0
votes

I'm trying to add a Menu Item to the Run Menu in Eclipse via a plugin.

However, I only want this Item to appear when I'm in the "Report Design" perspective (this is for BIRT). Secondly, (if possible) I'd like the menu item to be only enabled if the extension of the open file is .rptdesign.

I'm not having any luck using either of the visibility or visibleWhen elements in the plugin.xml

Any hints appreciated, Ro

1
Are you using the isPerspectiveOpen property? - tkotisis
No, I've not been using isPerspectiveOpen, but I'm unable to find a good example of that property usage. - Ro.

1 Answers

1
votes

Eventually got it, here's what I had to do.....

Create the Command

<extension
     point="org.eclipse.ui.commands">
  <command
        name="Deploy"
        icon="icons/deploy.gif"
        style="push"
        id="com.test.deployCommand">
  </command>

Create the Handler for the command

<extension
     point="org.eclipse.ui.handlers">
  <handler
        commandId="com.test.deployCommand"
        class="com.test.DeployHandler">
  </handler>

Add an existing property tester available in BIRT (to test the file type) - Would not work if i changed the namespace parameter

<extension
    point="org.eclipse.core.expressions.propertyTesters">
 <propertyTester
       class="org.eclipse.birt.report.debug.internal.ui.script.ScriptDebuggerPropertyTester"
       id="com.test.propertyTester1"
       namespace="scriptdebug"
       properties="isRptdesign"
       type="org.eclipse.core.runtime.IAdaptable">
 </propertyTester>

Added two definitions

<extension point="org.eclipse.core.expressions.definitions">
  <definition id="com.test.inRptDesignPerspective">
    <with variable="activeWorkbenchWindow.activePerspective">
      <equals value="org.eclipse.birt.report.designer.ui.ReportPerspective"/>
    </with>
  </definition>
  <definition id="com.test.inRptDesignFile">
    <with variable="selection">
    <count value="1" />
    <iterate>
       <and>
         <test property="scriptdebug.isRptdesign" />
       </and>
     </iterate>
    </with>
  </definition>
</extension>

On my menu extension, added a setting to the command, marking when its visible

<extension
     point="org.eclipse.ui.menus">
     <menuContribution locationURI="menu:org.eclipse.ui.main.menu" id="com.test.contribution2">
     <menu
          id="org.eclipse.ui.run"
          label="Run"
          path="additions">
        <groupMarker
             name="preview">
       </groupMarker>
        <command
              commandId="com.test.deployCommand"
              icon="icons/deploy.gif"
              id="com.test.deployCommand"
              menubarPath="org.eclipse.ui.run/preview"
              style="push"
              class="com.test.DeployHandler">
              <visibleWhen>
              <and>
                <reference definitionId="com.test.inRptDesignPerspective"/>
                <reference definitionId="com.test.inRptDesignFile"/>
              </and>
           </visibleWhen>
         </command>
       </menu>
     </menuContribution>