Search code examples
eclipsepluginspreference

How to restore multiple default values on a Preference page in Eclipse


I am writing a plugin, which will do the job of restoring all default values of a Preference page in Eclipse. My idea is to get the Preference page, and then invoke: performDefaults() to reset all the values. However, I can't manage to get the Preference page of that plugin: I used the following code to get the IPreferenceNode, then I want to use method getPage() to return the corresponding Preference page of the plugin, but it returns null. It seems that IPreferenceNode doesn't store the associated Preference page. So How can I get the Preference page of a plugin? Or is there any other method to reset multiple values in a Preference page?

PreferenceManager prefmngr = PlatformUI.getWorkbench( ).getPreferenceManager();
List<IPreferenceNode> nodelist = pm.getElements(PreferenceManager.PRE_ORDER);

Solution

  • Calling performDefaults() is not going to work as it expects to be run in an open preference dialog and calls user interface functions which will fail outside of an open dialog (it is also protected so you can't call it without reflection anyway).

    Looking at a variety of preference pages there does not look to be any general way to reset a page's default.