0

I have created a preference page in eclipse the preference page has two fields

  1. server url
  2. store location

If the user open this preferences dialog, change the value of url and apply it the product is restarted and after restart when I check the value in the url field it is changed as expected. When I change the values of both url and directory only one of them is updated depends on which one is changed later. Here is my init method which initialize the preferences

public class DataStorePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

public static final String SERVER_URL = "prefs_server_url";
public static final String WORKSPACE_DIR = "prefs_workspace_dir";
public static final String KEEP_LOCKS = "prefs_keep_locks";
//public static final String RELEASE = "prefs_release";
public DataStorePreferencePage() {
    super(GRID);
}


@Override
public void init(IWorkbench workbench) {
    setPreferenceStore(Activator.getDefault().getPreferenceStore());
    getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            String property = event.getProperty();
            System.setProperty("datastoreserver_url", property);
            if (property.equals(DataStorePreferencePage.WORKSPACE_DIR) ||
                    property.equals(DataStorePreferencePage.SERVER_URL)) {

                if(MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Information", "New settings will be applied after a restart.\nRestart now?"))
                    PlatformUI.getWorkbench().restart();

            }
        }
    });                     
}

@Override
protected void createFieldEditors() {
    StringFieldEditor urlEditor = new StringFieldEditor(SERVER_URL, "DataStore Server URL", getFieldEditorParent());
    StringFieldEditor workspaceDirEditor = new DirectoryFieldEditor(WORKSPACE_DIR, "Workspace directory:", getFieldEditorParent());
    BooleanFieldEditor keepLocksEditor = new BooleanFieldEditor(KEEP_LOCKS, "Keep locks (default setting):", getFieldEditorParent());
    //BooleanFieldEditor releaseEditor = new BooleanFieldEditor(RELEASE, "Release (default setting):", getFieldEditorParent());

    addField(workspaceDirEditor);
    addField(urlEditor);
    addField(keepLocksEditor);
    //addField(releaseEditor);
}

@Override
public boolean performOk() {

    return super.performOk();

}


}

Question:

Where is the new value stored? From where eclipse get this changed value in any .ini file?

How can I change both the properties at the same time?

Thanks

Wearybands
  • 2,438
  • 8
  • 34
  • 53

1 Answers1

1

Wait until performOk or performApply is called before checking for restart.

The preference values are stored in the preference store. You can get them with:

IPreferenceStore store = getPreferenceStore();

String dir = store.getString(WORKSPACE_DIR);

String url = store.getString(SERVER_URL);
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Is this preference store any ini file or its just created in memory or what ? – Wearybands Dec 10 '14 at 15:53
  • How can I ensure that performOk is called before I check for restart? Do I need to call performOk before checking for restart ? – Wearybands Dec 10 '14 at 15:54
  • Eclipse will call performOk if the user clicks 'OK' (and `performApply' if they click 'Apply'). If they click Cancel the new values are discarded and you should not do a restart. – greg-449 Dec 10 '14 at 16:02
  • when I change both the values i-e url and dir, performOk() is called two times once for each field. After each performOk() call propertyChange Listener is called. How can I ensure that performOk() is called for all the values that are changed? – Wearybands Dec 11 '14 at 09:30
  • Eclipse should only call performOk once when the OK button is clicked, I have never seen it behave any other way. – greg-449 Dec 11 '14 at 09:41
  • The performApply also call performOk() internally. How can I restart my product on clicking upon Ok button instead of clicking on Apply – Wearybands Dec 11 '14 at 10:24
  • You can override performApply if you want, but you should really take the same action for Apply as OK – greg-449 Dec 11 '14 at 10:35
  • Thanks for your tips , after overriding performApply I solved my problem Thanks – Wearybands Dec 11 '14 at 11:08
  • Eclipse stores its all preferences in files. Check the following folder in your workspace folder. .metadata/.plugins/org.eclipse.core.runtime/.settings/ – M Faisal Hameed Jan 28 '15 at 06:01