Getting Rid of Unwanted Preference Pages in Eclipse

I recently wanted to get rid of a preference page I did not want to expose in Mission Control (an Eclipse RCP based application), and ended up with the following code in my ApplicationWorkbenchWindowAdvisor:

private void removeUnwantedPreferencesPages() {
    PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager();
    IPreferenceNode root = getRoot(pm);
    removePrefsPage(root, ""); //$NON-NLS-1$

private IPreferenceNode getRoot(PreferenceManager pm) {
    try {
        Method m = PreferenceManager.class.getDeclaredMethod("getRoot", (Class[]) null); //$NON-NLS-1$
        return (IPreferenceNode) m.invoke(pm);
    } catch (Exception e) {
       LoggingToolkit.getLogger().log(Level.WARNING, "Could not get the root node for the preferences, and will not be able to prune unwanted prefs pages.", e); //$NON-NLS-1$
    return null;

private void removePrefsPage(IPreferenceNode root, String id) {
    for (IPreferenceNode node : root.getSubNodes()) {
        if (node.getId().equals(id)) {
           LoggingToolkit.getLogger().log(Level.INFO, String.format("Removed preference page %s (ID:%s)", node.getLabelText(), node.getId()));   //$NON-NLS-1$
        } else {
           removePrefsPage(node, id);

If you need to know the ID of the preference page you wish to remove, simply walk the tree and print all the nodes instead of removing selected ones.

Hope this helps someone. Blinkar

Leave a Reply

Your email address will not be published.