如何在会话之间存储Eclipse插件状态?

3 java eclipse eclipse-plugin

我正在研究Eclipse插件.该插件每次在本地保存工作时都会提醒用户将其工作保存在中央存储库中.

但是,一旦用户成功将他的工作保存在中央存储库中10次,他将不再被提醒保存他的工作.

这在单个会话中很有效.也就是说,当用户开始在工作区中工作并启用插件时.

但是,如果用户在将工作保存到中央存储库9次后退出工作区,他将继续被提醒10次,即从头开始,下次他打开工作区时.

我想知道,如果可以增加计数器并将其存储在内存中,以便插件按预期工作.

jhu*_*ado 7

您可以使用插件设置来存储和检索插件的值.Eclipse FAQ中
的示例:

 private void savePluginSettings() {
  // saves plugin preferences at the workspace level
  Preferences prefs =
    //Platform.getPreferencesService().getRootNode().node(Plugin.PLUGIN_PREFEERENCES_SCOPE).node(MY_PLUGIN_ID);
    new InstanceScope().getNode(MY_PLUGIN_ID); // does all the above behind the scenes

  prefs.put(KEY1, this.someStr);
  prefs.put(KEY2, this.someBool);

  try {
    // prefs are automatically flushed during a plugin's "super.stop()".
    prefs.flush();
  } catch(BackingStoreException e) {
    //TODO write a real exception handler.
    e.printStackTrace();
  }
}

private void loadPluginSettings() {
  Preferences prefs = new InstanceScope().getNode(MY_PLUGIN_ID);
  // you might want to call prefs.sync() if you're worried about others changing your settings
  this.someStr = prefs.get(KEY1);
  this.someBool= prefs.getBoolean(KEY2);
}
Run Code Online (Sandbox Code Playgroud)