Skip Navigation

Creating Basic Menu Contributions

This procedure shows how to create menu contributions.

Preparing to Add a Menu Contribution

  1. Complete one of the following:

An editor, view, and generic command also need the handler extension org.eclipse.ui.handlers .

  1. Open Eclipse, select your workspace, and then open the Red App target platform.

  2. For the sample horizontal view and side bar menu contribution, add the com.sabre.redapp.example.editor.basic sample plug-in.

  3. Open your project. In Package Explorer view, open MANIFEST.MF.

  4. Open the Dependencies tab, and then add the org.eclipse.ui dependency.

  5. It is optional, but recommended, to add an icon for a menu contribution. In order to add the icon property to your menu contribution, you must create a folder structure on your local drive.

    •         Add a new folder to your project for images and other graphic files. In the sample, the folder is named images.

    •         On your local drive, add the icon file to the images folder.

    •         Open the Build tab. Add the images directory to the file.

Adding Extensions and Elements

  1. Open the Extensions tab, and then click Add to display the New Extension dialog.

  1. Remove the selection from Show Only Extension Points from the Required Plug-ins. In the Extension Point Filter field, type org.eclipse.ui.menus.

You can type either the complete name or * followed by the partial name to display a list of names that contain the characters you enter. Select the name when it appears in the list.

  1. Click Finish. If Eclipse displays the New Plug-in Dependency dialog, click Yes.

        Eclipse displays org.eclipse.ui.menus on the Extensions tab.

Adding menuContribution to org.eclipse.ui.menus

  1. Right-click org.eclipse.ui.menus, and then choose New > menuContribution.

In Extension Element Details, you will add properties to the menus extension.

  1. Add menuContribution properties in the locationURI element. Type the syntax that corresponds to the menu to which you are contributing.

Eclipse adds the value in locationURI as a prefix to the menuContribution in the All Extensions panel.

Adding command and commandParameter Elements

  1. Right-click menu contribution, and then choose New > command.

  1. Type a value for the commandId property. The value in the commandId property must match the value in the id property of command for org.eclipse.ui.commands in your plug-in.

        The value for the sample editor is com.sabre.redapp.example.editor.basic.OpenSampleEditorCommand.

        The value for the sample vertical view is com.sabre.edge.command.example.view.basic.

        The value for the sample horizontal view is com.sabre.edge.command.example.view.horizontal.

  1. Open the Extensions tab. Add properties to the command element in the following fields:


Add the image file for the menu contribution. This image appears on the GUI.
Next to the icon field, click Browse and select the path and file from the resource that has the image file within the plug-in.
In the sample plug-in, the path is images/sample_icon.png.


Type the text for your menu contribution. This label is displayed on the sub-menu to end-users.


The required value is push.

Sabre Red 360 ignores the toolTip property.

If you are adding a contribution for a generic command, do not add a command parameter. Omit the next two steps.

  1. Right-click command that you added to org.eclipse.ui.menus, and choose New > parameter.

  2. Add properties to the parameter element in the following fields.


For an editor, the value editorId is required if you are using the Sabre Red 360 internal class.
For a view, type the same value that is in the id property of the commandParameter for org.eclipse.ui.commands.
In the sample vertical and horizontal views, this value is viewId.
You can type the value manually or click Browse and select it.


This is the identifier of the editor to open. For an editor, type the value in the id property for org.eclipse.ui.editors.
In the sample editor, this value is com.sabre.redapp.example.editor.basic.SampleEditor.
This is the identifier of the view to open. For a view, type the same value that is in the id property of the view class that was declared for org.eclipse.ui.views.
In the sample vertical view, this value is com.sabre.redapp.example.view.basic.view.
In the sample horizontal view, this value is com.sabre.redapp.example.view.basic.horizontal.

  1. When you are done, save MANIFEST.MF.

Using visibleWhen to Limit the Visibility of the Menu Contribution on the Side Bar

  1. Right-click command, and then choose visibleWhen.

  1. In the checkEnabled property for visibleWhen, select true.

        A value of true checks whether the handler for the command is enabled. If the handler is not enabled, a value of true sets visibleWhen to false, which suppresses the display of the menu entry on the side bar.

        A value of false does not check the handler, and displays the menu entry whether the handler is enabled or not. (For information about how to add complex conditions to menus using visibleWhen and handler policies, see Controlling the Visibility and Activation of Menus.)

It is recommended that you add rules to establish the visibility of the menu entry for your view when the corresponding editor is active. The rules are added to the visibleWhen property.

Rules for Sabre Emulator in an Editor

  1. Right-click visibleWhen, and then choose New > reference.

  2. In the definitionId property, type com.sabre.edge.command.definitions.editorMenu. This entry identifies the Sabre Red 360 definition. (More information is available in Sabre Red 360 declared variables and definitions.)

Rules for Other Applications in an Editor

  1. Right-click visibleWhen, and then choose New > with.

  1. In the variable property, type the name of the variable that you want to use for evaluation, for example, edgeActiveEditorId. This is a Sabre Red 360 variable.

  2. Add the logical evaluation of the value. Right-click the with element, and then choose equals.

  3. In the value property, type the value of the variable property of the with element in a previous step, or a specific value from a set. In this case, the value is the id property of editor in org.eclipse.ui.editors. In the sample editor, the value is com.sabre.redapp.example.editor.basic.SampleEditor.

        If the evaluation is true for visibleWhen with variable equals value, the menu entry is visible; otherwise, the menu entry is not visible.

  1. Save MANIFEST.MF. Either click the Save icon or type Ctrl+S.