{"id":171,"date":"2012-02-01T10:36:16","date_gmt":"2012-02-01T09:36:16","guid":{"rendered":"http:\/\/hirt.se\/blog\/?p=171"},"modified":"2012-03-22T14:30:02","modified_gmt":"2012-03-22T13:30:02","slug":"getting-rid-of-unwanted-preference-pages-in-eclipse","status":"publish","type":"post","link":"https:\/\/hirt.se\/blog\/?p=171","title":{"rendered":"Getting Rid of Unwanted Preference Pages in Eclipse"},"content":{"rendered":"<p>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:<\/p>\n<blockquote>\n<p><font face=\"Courier New\">private void removeUnwantedPreferencesPages() {<br \/>&#160;&#160;&#160; PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager();<br \/>&#160;&#160;&#160; IPreferenceNode root = getRoot(pm);<br \/>&#160;&#160;&#160; removePrefsPage(root, &quot;org.eclipse.equinox.security.ui.category&quot;); \/\/$NON-NLS-1$<br \/>}<\/font><\/p>\n<p><font face=\"Courier New\"><br \/>private IPreferenceNode getRoot(PreferenceManager pm) {<br \/>&#160;&#160;&#160; try {<br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Method m = PreferenceManager.class.getDeclaredMethod(&quot;getRoot&quot;, (Class[]) null); \/\/$NON-NLS-1$<br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m.setAccessible(true);<br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (IPreferenceNode) m.invoke(pm);<br \/>&#160;&#160;&#160; } catch (Exception e) {<br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;LoggingToolkit.getLogger().log(Level.WARNING, &quot;Could not get the root node for the preferences, and will not be able to prune unwanted prefs pages.&quot;, e); \/\/$NON-NLS-1$<br \/>&#160;&#160;&#160; }<br \/>&#160;&#160;&#160; return null;<br \/>}<\/font><\/p>\n<p><font face=\"Courier New\">private void removePrefsPage(IPreferenceNode root, String id) {<br \/>&#160;&#160;&#160; for (IPreferenceNode node : root.getSubNodes()) {<br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; logPrefsNode(node);<br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (node.getId().equals(id)) {<br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;root.remove(node);<br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;LoggingToolkit.getLogger().log(Level.INFO, String.format(&quot;Removed preference page %s (ID:%s)&quot;, node.getLabelText(), node.getId()));&#160;&#160; \/\/$NON-NLS-1$<br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else {<br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;removePrefsPage(node, id);<br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br \/>&#160;&#160;&#160; }<br \/>}<\/font><\/p>\n<\/blockquote>\n<p>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. <\/p>\n<p>Hope this helps someone. <img decoding=\"async\" style=\"border-bottom-style: none;border-left-style: none;border-top-style: none;border-right-style: none\" class=\"wlEmoticon wlEmoticon-winkingsmile\" alt=\"Blinkar\" src=\"https:\/\/hirt.se\/blog\/wp-content\/uploads\/2012\/02\/wlEmoticon-winkingsmile.png\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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() {&#160;&#160;&#160; PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager();&#160;&#160;&#160; IPreferenceNode root = getRoot(pm);&#160;&#160;&#160; removePrefsPage(root, &quot;org.eclipse.equinox.security.ui.category&quot;); \/\/$NON-NLS-1$} private IPreferenceNode getRoot(PreferenceManager pm) {&#160;&#160;&#160; try [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-java-mission-control-fair-dj"],"_links":{"self":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=171"}],"version-history":[{"count":5,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":192,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions\/192"}],"wp:attachment":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}