Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementation AbstractPreferenceInitializer won't get called in my Eclipse RCP

I want to use the Eclipse mechanism to set default preferences in my RCP application. Therefore I extended the class AbstractPreferenceInitializer to set my default preferences:

public class PreferenceInitializer extends AbstractPreferenceInitializer {
  @Override
  public void initializeDefaultPreferences() {
    IPreferenceStore preferenceStore = PlatformUI.getPreferenceStore();
    preferenceStore.setDefault("xyz",  xyz);
    preferenceStore.setDefault("abc", false);
  }
}

Then I defined the extension point:

<extension point="org.eclipse.core.runtime.preferences">
  <initializer class="com.abc.PreferenceInitializer">
  </initializer>
</extension>

But unfortunately, the initializer won't get called during startup (whereas Eclipse's WorkbenchPreferenceInitializer will be called).

Can someone give me a hint, what to do, to get this run?

like image 690
Philipp Avatar asked Jul 02 '26 00:07

Philipp


1 Answers

Your preference initializer code won't get called until those default values are needed (rather than on application startup, which I'm guessing was your expectation).

If you have yourself a preference page that contains some FieldEditors using your preference names, your preference initializer will get called when you go to the Preferences dialog and select that preference page.

Something along the lines of:

public class MyPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

    public void createFieldEditors() {
        Composite parent = getFieldEditorParent();
        addField(new StringFieldEditor(Constants.PREFERENCES.FILE_COMPARE_TOOL_LOCATION, "File compare tool location", parent));
        addField(new StringFieldEditor("xyz", "XYZ Value", parent));
        addField(new BooleanFieldEditor("abc", "Enable the ABC widget", parent));
    }

}

And of course, an extension point for the page:

<extension point="org.eclipse.ui.preferencePages">
  <page
        class="whatever.package.MyPreferencePage"
        id="whatever.package.MyPreferencePage"
        name="MyPrefs">
  </page>
</extension>
like image 69
stracka Avatar answered Jul 06 '26 23:07

stracka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!