views:

416

answers:

2

I would like to suppress the context menu that shows when right clicking on the perspective tool bar in an rcp application. To clarify, I do want the perspective bar and shortcuts to show, but I do not want the context menu to pop up. All perspective tool bar api seems to be internal.

Thanks.

+1  A: 

The context menu of the PerspectiveSwitcher is created deeply in the internal classes of the workbench framework, as you mentioned. You cannot prevent it from beeing created, neither can you get a reference to the PerspectiveSwitcher to suppress the menu somehow, without heavy use of internal classes and a lot of reimplementing existing functionality.

So, to put it simple, IMHO it seems the context menu is not meant to be suppressed.

The easiest and cleanest way to solve your problem would be to suppress the whole perspective bar, and implement your own. There is public API for querying the existing perspectives (IWorkbench.getPerspectiveRegistry) and switching perspectives (IWorkbenchPage.setPerspective), all you need to code is the UI.

ftl
+1  A: 

You can try this

    PerspectiveBarManager perspectiveBarManager = ((WorkbenchWindow) PlatformUI.getWorkbench()
            .getActiveWorkbenchWindow()).getPerspectiveBar();
    ToolBar toolBar = perspectiveBarManager.getControl();
    Listener[] listeners = toolBar.getListeners(SWT.MenuDetect);
    if (listeners != null)
    {
        for (Listener listener : listeners)
        {
            toolBar.removeListener(SWT.MenuDetect, listener);
        }
    }
kakogo