Yeti
Yeti

Reputation: 1160

Own PreferencePage: Set and get values - storeValues() is never called

I'm creating my own PreferencePage for Eclipse for a RCP application. For the FileFieldEditor I want the value to be stored and get it later on in another class. For this I do:

private void initializeDefaults() {
    IPreferenceStore store = getPreferenceStore();
    subversionPathEditor.setStringValue(store.getString(FIELD_SUBVERSION_PATH));
}

The Activator class implements AbstractUIPlugin and in the init() method of the PreferencePage the preference store is set:

public void init(IWorkbench workbench) {
    setPreferenceStore(Activator.getDefault().getPreferenceStore());
}

Values are stored using the storeValues() method accoring to the Eclipse Documentation:

private void storeValues() {
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    store.setValue("SUBVERSION_PATH", subversionPathEditor.getStringValue());
}

And here is the problem: Eclipse is telling me the method is never used (locally). So the value can't be in the PreferenceStore.

What I am doing wrong?

(Tell me, if you need more code.)

Upvotes: 0

Views: 129

Answers (1)

greg-449
greg-449

Reputation: 111142

If you read the documentation page carefully it says the storeValues method has to be called when OK and Apply are pressed.

You do this by overriding performOk:

@Override
public boolean performOk()
{
  storeValues();

  super.performOk();
}

You can also override performApply but the default action is to call performOk so it is not necessary in this case.

Upvotes: 1

Related Questions