Training „git“
07.10.2010 - 08.10.2010, Essen
Training „Eclipse RCP“
28.03.2011 - 01.04.2011, Dortmund
19.07.2009

Showing menu contributions depending on active perspective

Using the variable activeWorkbenchWindow.activePerspective in org.eclipse.ui.menus you can contribute commands to the menu- or toolbar depending on the active perspective. Unfortunately, this works only for single commands and not for a complete menu or toolbar element. For example:

<extension point="org.eclipse.ui.menus">
   <menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar">
      <toolbar id="de.rcpbuch.addressbook.filetoolbar">
         <command commandId="de.rcpbuch.addressbook.somecommandid" style="push">
            <visibleWhen checkEnabled="false">
               <with variable="activeWorkbenchWindow.activePerspective">
                  <equals value="de.rcpbuch.addressbook.someperspectiveid"/>
               </with>
            </visibleWhen>
         </command>
      </toolbar>
   </menuContribution>
</extension>
Kristian Rink, 11. Dezember, 15:07 Uhr

Thanks, just what I've been searching for. :) Now if I only could figure out why this ain't working on a per-toolbar rather than on a per-command level...

Girish, 20. Mai, 12:06 Uhr

This is right in a case when I want some commands visible for some perspectives and invisible for others. But when I close all the perspectives the command are left over on the toolbar if they were visible in the last open perspective. This kind of memory leak. Do we have a solution for this?

Ralf Ebert, 20. Mai, 13:00 Uhr

Sounds like a bug. Never had the problem myself as there's always an active perspective in my applications. Please ask at the eclipse.platform.rcp newsgroup or file a bug report.

I'm looking forward to your comments:

Schulungen

Eclipse RCP

Ralf Ebert | Blog | Eclipse RCP | Showing menu contributions depending on active perspective