Eclipse: OSGI Preferences vs. PreferenceStore

扶醉桌前 提交于 2019-11-30 12:47:51
Paul Webster

It seems that at the preference page level, it wants to work with a preference store. Most plugins get their preference store from the default provided by org.eclipse.ui.plugin.AbstractUIPlugin.getPreferenceStore(). That translates loosely to a ScopedPreferenceStore with an InstanceScope with a node that matches their bundle.id.

The equivalent to get the matching IEclipsePreferences object would be InstanceScope.INSTANCE.getNode("bundle.id"). That would allow you to add further nodes underneath, but they wouldn't be accessible from your IPreferenceStore. However, your preference page could set its preference store to the main one for your plugin, and still use IEclipsePreferences or a secondary IPreferenceStore to access extra preferences (you just have to code it yourself, similar to org.eclipse.ui.internal.dialogs.EditorsPreferencePage).

I tackled this problem by overriding the getPreference store as follows:

@Override
public IPreferenceStore getPreferenceStore() {
    if (preferenceStore == null) {
        preferenceStore = new ScopedPreferenceStore( InstanceScope.INSTANCE, ID );
    }
    return preferenceStore;
}

works for me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!