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>
Ralf Ebert

Ralf Ebert is an independent software developer, technical writer and trainer. He makes apps for Mac OS X and iOS and builds software solutions for companies using Eclipse RCP and Ruby on Rails. He offers training courses for software developers and writes books and articles about software development.