【发布时间】:2016-01-07 23:34:35
【问题描述】:
我正在尝试将我的 e3-rcp-app 迁移到 e4-rcp-app。
因此我需要定义我的默认首选项。 (不是 Pref.Pages)
通过这样做和尝试,我无法调用我的初始化程序。这是我的初始化程序类:
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 类:(只需发布相关方法(?))
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 我用谷歌搜索了很多,发现了很多关于这个的线程,但我找不到我的错误 =/。 有人建议为什么我的默认首选项初始化程序不会被调用?
提前致谢
【问题讨论】:
-
您不需要在
start方法中使用@PostConstruct。不注入激活剂。 -
谢谢,我解决了这个问题,但我的首选项初始化程序仍然不会被调用。
标签: eclipse preferences rcp e4 initializer