Я пытаюсь перенести свое приложение e3-rcp на приложение e4-rcp.
Поэтому мне нужно определить мои настройки по умолчанию. (Не Pref.Pages)
И, делая и пытаясь это сделать, я просто не могу вызвать свой Initializer. Вот мой класс инициализатора:
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>
...
Я использую Eclipse 4.5.1 на win7 x64. Я много гуглил и нашел много тем по этому поводу, но я просто не могу найти свою ошибку =/. У кого-нибудь есть предложение, почему мой инициализатор настроек по умолчанию не вызывается?
заранее спасибо
@PostConstruct
в методеstart
. Активаторы не вводят. - person greg-449   schedule 25.11.2015