E4 Preference Initializer 不会被调用

E4 Preference Initializer won´t get called

我正在尝试将我的 e3-rcp-app 迁移到 e4-rcp-app。

因此我需要定义我的默认首选项。 (不是 Pref.Pages)

通过这样做和尝试,我就是无法调用我的 Initializer。这是我的初始值设定项-class:

public class MyPreferenceInitializer extends AbstractPreferenceInitializer {

public MyPreferenceInitializer (){}

@Override
public void initializeDefaultPreferences() {

Preferences defaults = DefaultScope.INSTANCE.getNode(InspectIT.ID);
          // Set defaults using things like:
          defaults.put("DUMMY", "DUMMYCONTENT");
          try {
            defaults.flush();
        } catch (BackingStoreException e) {
            e.printStackTrace();
        }

          //And this other approach to make sure that one of them works
          IPreferenceStore store = InspectIT.getDefault().getPreferenceStore();
          store.setDefault("DUMMY", "DUMMYCONTENT");         
          try {
            ((Preferences) store).flush();
        } catch (BackingStoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        //Dummy impl        
       default Preferences....,
    }

}

我也得到了一个 Activator class,其结构如下:(只是发布相关方法(?))

 public class Activator implements BundleActivator {

        private static BundleContext context;

        static BundleContext getContext() {
            return context;
        }


        private static Activator plugin;

        private volatile ScopedPreferenceStore  preferenceStore;

        public void start(BundleContext context) throws Exception {
            plugin = this;
            Activator.context = context;
            locateRuntimeDir();     
            logListener = new LogListener();
            Platform.addLogListener(logListener);

//access to my initializor
        String text = getPreferenceStore().getDefaultString("DUMMY");
        String text2 = getPreferenceStore().getString("DUMMY");

        }

        public void stop(BundleContext context) throws Exception {

        Activator.context = null;
        plugin = null; 
    }

    public static <E> E getService(Class<E> clazz) {
        ServiceReference<E> reference = context.getServiceReference(clazz);
        if (null != reference) {  

            return context.getService(reference);
        }
        throw new RuntimeException("Requested service of the class " + clazz.getName() + " is not registered in the bundle.");
    }

    public ScopedPreferenceStore getPreferenceStore() {

        if (null == preferenceStore) {
            synchronized (this) {
                if (null == preferenceStore) { 


                    preferenceStore = new  ScopedPreferenceStore(ConfigurationScope.INSTANCE, ID); 
                } 
            } 
        } 
        return preferenceStore;
    }
}

我正在使用的 ScopedPreferenceStore 位于:https://github.com/opcoach/e4Preferences/tree/master/com.opcoach.e4.preferences

另外,我这样声明 plugin.xml 扩展(我确实需要这个,对吧?)

...
 <extension
         point="org.eclipse.core.runtime.preferences">
      <initializer            class="MyApplication.rcp.preferences.MyPreferenceInitializer ">
      </initializer>
   </extension>
...

我在 win7 x64 上使用 Eclipse 4.5.1 我在谷歌上搜索了很多,发现了很多与此相关的主题,但我就是找不到我的错误 =/。 有人对为什么我的默认首选项初始化程序不会被调用有任何建议吗?

提前致谢

您仍然必须使用 org.eclipse.core.runtime.preferences 扩展点来定义首选项初始化程序。

<extension
     point="org.eclipse.core.runtime.preferences">
  <initializer
        class="package.MyPreferenceInitializer">
  </initializer>
</extension>

在初始化程序中使用:

@Override
public void initializeDefaultPreferences()
{
  Preferences defaults = DefaultScope.INSTANCE.getNode(Activator.ID);

  // Set defaults using things like:
  defaults.putInt("pref id", 0);
}

我终于找到了解决这个问题的方法。 不小心又翻过了这个问题,错误在Activator。我错误地将 ID 设置为错误的名称。我将其重置为我的项目名称,现在可以正常工作了!

public ScopedPreferenceStore getPreferenceStore() {

    if (null == preferenceStore) {      
        synchronized (this) {
            if (null == preferenceStore) 
            preferenceStore = new ScopedPreferenceStore(ConfigurationScope.INSTANCE, ID); 
        }                   
    } 
    return preferenceStore;
}

ID = Project-Name