Search code examples
javaeclipse-plugineclipse-rcp

BooleanFieldEditor doesn't load value from PreferenceStore


For an own PreferencePage in an Eclipse-RCP-Plugin I use an BooleanFieldEditor. Its value is saved in the PreferenceStore (confirmed that it is saved). But the Editor always is set to "false" after opening the PreferencePage again.

public class PreferencePage extends FieldEditorPreferencePage implements
IWorkbenchPreferencePage {

[...]
protected void createFieldEditors() {
subversionSupportBooleanFieldEditor = new BooleanFieldEditor
    (PreferenceConstants.FIELD_SUBVERSION_SUPPORT, "Enable Subversion support", BooleanFieldEditor.DEFAULT, getFieldEditorParent());
subversionSupportBooleanFieldEditor.setPreferenceStore(Activator.getDefault().getPreferenceStore());
subversionSupportBooleanFieldEditor.load();
[...]}

What is missing?


Solution

  • You need to override the doGetPreferenceStore method of PreferencePage and return the preference store that should be used by the field editors.

      @Override
      protected IPreferenceStore doGetPreferenceStore() {
        return Activator.getDefault().getPreferenceStore();
      }
    

    The initialize method of FieldEditorPreferencePage assigns the value returned here to each field editor. If you do not override doGetPreferenceStore the preference store of the container is taken.