分享

Hiding menu and tool bars in Eclipse RCP Application

 LibraryPKU 2015-01-08

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 hide the menu bar after calling setVisible(false).

private void setMenubarVisible (boolean visible)
{
    IWorkbenchWindow workbenchWindow =  PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IContributionItem[] items = ((WorkbenchWindow)workbenchWindow).getMenuBarManager().getItems();
    for (IContributionItem item : items)
    {
        item.setVisible(visible);
    }
    ((WorkbenchWindow)workbenchWindow).getMenuBarManager().setVisible(visible);
}

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.

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 ‘Quick Access’ box. I have hidden that in my application’s WorkbenchWindowAdvisor class as follows –

public void postWindowOpen() {
    try {
        IHandlerService service = (IHandlerService) PlatformUI
                .getWorkbench().getActiveWorkbenchWindow()
                .getService(IHandlerService.class);
        if (service != null)
            service.executeCommand("org.eclipse.ui.ToggleCoolbarAction",
                    null);
    } catch (Exception e) {
        //handle error
    }
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多