{"id":397,"date":"2012-07-24T15:59:34","date_gmt":"2012-07-24T10:29:34","guid":{"rendered":"http:\/\/ramkulkarni.com\/blog\/?p=397"},"modified":"2012-07-24T15:59:34","modified_gmt":"2012-07-24T10:29:34","slug":"hiding-menu-and-tool-bars-in-eclipse-rcp-application","status":"publish","type":"post","link":"http:\/\/ramkulkarni.com\/blog\/hiding-menu-and-tool-bars-in-eclipse-rcp-application\/","title":{"rendered":"Hiding menu and tool bars in Eclipse RCP Application"},"content":{"rendered":"<p>I wanted to hide\/show menu bar in my <a title=\"WebAppRunner \u2013 Run your web applications standalone\" href=\"http:\/\/ramkulkarni.com\/blog\/webapprunner-run-your-web-applications-standalone\/\">WebAppRunner<\/a> Eclipse application, depending on settings. I figured getting menu bar manager and calling setVisible method would do the job, but it was not sufficient.<\/p>\n<p>Eclipse checks visibility of each menu manager in the menu bar and even if one of them is visible, it would not hide the menu bar after calling setVisible(false).<\/p>\n<p><!--more--><\/p>\n<pre style=\"color: #000020; background: #f6f8ff;\"><span style=\"color: #200080; font-weight: bold;\">private<\/span> void setMenubarVisible (boolean visible)\n<span style=\"color: #406080;\">{<\/span>\n    IWorkbenchWindow workbenchWindow <span style=\"color: #308080;\">=<\/span>  PlatformUI<span style=\"color: #308080;\">.<\/span>getWorkbench<span style=\"color: #308080;\">(<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #308080;\">.<\/span>getActiveWorkbenchWindow<span style=\"color: #308080;\">(<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span>\n    IContributionItem<span style=\"color: #308080;\">[<\/span><span style=\"color: #308080;\">]<\/span> items <span style=\"color: #308080;\">=<\/span> <span style=\"color: #308080;\">(<\/span><span style=\"color: #308080;\">(<\/span>WorkbenchWindow<span style=\"color: #308080;\">)<\/span>workbenchWindow<span style=\"color: #308080;\">)<\/span><span style=\"color: #308080;\">.<\/span>getMenuBarManager<span style=\"color: #308080;\">(<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #308080;\">.<\/span>getItems<span style=\"color: #308080;\">(<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span>\n    <span style=\"color: #200080; font-weight: bold;\">for<\/span> <span style=\"color: #308080;\">(<\/span>IContributionItem item <span style=\"color: #308080;\">:<\/span> items<span style=\"color: #308080;\">)<\/span>\n    <span style=\"color: #406080;\">{<\/span>\n        item<span style=\"color: #308080;\">.<\/span>setVisible<span style=\"color: #308080;\">(<\/span>visible<span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span>\n    <span style=\"color: #406080;\">}<\/span>\n    <span style=\"color: #308080;\">(<\/span><span style=\"color: #308080;\">(<\/span>WorkbenchWindow<span style=\"color: #308080;\">)<\/span>workbenchWindow<span style=\"color: #308080;\">)<\/span><span style=\"color: #308080;\">.<\/span>getMenuBarManager<span style=\"color: #308080;\">(<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #308080;\">.<\/span>setVisible<span style=\"color: #308080;\">(<\/span>visible<span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span>\n<span style=\"color: #406080;\">}<\/span><\/pre>\n<p>I really do not like typecasting to WorkbenchWindow in the above code. However I did not find any way to get menu manager from IWorkbenchWindow.<\/p>\n<p>Also a quick tip about hiding toolbar in Eclipse 4.2 (Juno). Even if you do not contribute any toolbar buttons, you will notice that Juno creates the toolbar for &#8216;Quick Access&#8217; box. I have hidden that in my application&#8217;s WorkbenchWindowAdvisor class as follows &#8211;<\/p>\n<pre style=\"color: #000020; background: #f6f8ff;\"><span style=\"color: #200080; font-weight: bold;\">public<\/span> void postWindowOpen() <span style=\"color: #406080;\">{<\/span>\n    <span style=\"color: #200080; font-weight: bold;\">try<\/span> <span style=\"color: #406080;\">{<\/span>\n        IHandlerService service <span style=\"color: #308080;\">=<\/span> <span style=\"color: #308080;\">(<\/span>IHandlerService<span style=\"color: #308080;\">)<\/span> PlatformUI\n                <span style=\"color: #308080;\">.<\/span>getWorkbench<span style=\"color: #308080;\">(<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #308080;\">.<\/span>getActiveWorkbenchWindow<span style=\"color: #308080;\">(<\/span><span style=\"color: #308080;\">)<\/span>\n                <span style=\"color: #308080;\">.<\/span>getService<span style=\"color: #308080;\">(<\/span>IHandlerService<span style=\"color: #308080;\">.<\/span>class<span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span>\n        <span style=\"color: #200080; font-weight: bold;\">if<\/span> <span style=\"color: #308080;\">(<\/span>service <span style=\"color: #308080;\">!<\/span><span style=\"color: #308080;\">=<\/span> <span style=\"color: #200080; font-weight: bold;\">null<\/span><span style=\"color: #308080;\">)<\/span>\n            service<span style=\"color: #308080;\">.<\/span>executeCommand<span style=\"color: #308080;\">(<\/span><span style=\"color: #1060b6;\">\"org.eclipse.ui.ToggleCoolbarAction\"<\/span><span style=\"color: #308080;\">,<\/span>\n                    <span style=\"color: #200080; font-weight: bold;\">null<\/span><span style=\"color: #308080;\">)<\/span><span style=\"color: #406080;\">;<\/span>\n    <span style=\"color: #406080;\">}<\/span> <span style=\"color: #200080; font-weight: bold;\">catch<\/span> <span style=\"color: #308080;\">(<\/span><span style=\"color: #6679aa; font-weight: bold;\">Exception<\/span> e<span style=\"color: #308080;\">)<\/span> <span style=\"color: #406080;\">{<\/span>\n        <span style=\"color: #595979;\">\/\/handle error<\/span>\n    <span style=\"color: #406080;\">}<\/span>\n<span style=\"color: #406080;\">}<\/span><\/pre>\n<p>-Ram Kulkarni<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to hide\/show menu bar in my WebAppRunner Eclipse application, depending on settings. I figured getting menu bar manager and calling setVisible method would do the job, but it was not sufficient. Eclipse checks visibility of each menu manager in the menu bar and even if one of them is visible, it would not &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/ramkulkarni.com\/blog\/hiding-menu-and-tool-bars-in-eclipse-rcp-application\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Hiding menu and tool bars in Eclipse RCP Application&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[38,1],"tags":[42,43],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2g9O8-6p","jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts\/397"}],"collection":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/comments?post=397"}],"version-history":[{"count":0,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts\/397\/revisions"}],"wp:attachment":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/media?parent=397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/categories?post=397"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/tags?post=397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}