4

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.

2 Answers2

2

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
  • 41
  • 3
  • *[@user844542 wrote this comment]* I tried using this, but was not able to get the `PerspectiveBar`. Which is the right class for introducing this code? Or is it not possible anymore? – phihag Jul 14 '11 at 12:30
1

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
  • 3,014
  • 1
  • 24
  • 25