Creating Basic Menu Contributions
This procedure shows how to create menu contributions.
The sample plugin.xml
files are provided in plugin.xml for an Editor with Main Menu and Launcher Bar Contributions and plugin.xml for Vertical and Horizontal Views with Main Menu and Side Bar Contributions.
Preparing to Add a Menu Contribution
-
Complete one of the following:
-
The steps in Creating a Sample Editor
-
The steps in Creating Sample View
-
The steps in Creating a Command and a Handler
-
An editor, view, and generic command also need the handler extension org.eclipse.ui.handlers .
-
Open Eclipse, select your workspace, and then open the Red App target platform.
-
For the sample horizontal view and side bar menu contribution, add the com.sabre.redapp.example.editor.basic sample plug-in.
-
Open your project. In Package Explorer view, open MANIFEST.MF.
-
Open the Dependencies tab, and then add the org.eclipse.ui dependency.
-
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
build.properties
file.
-
Adding Extensions and Elements
-
Open the Extensions tab, and then click Add to display the New Extension dialog.
-
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.
-
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
-
Right-click org.eclipse.ui.menus, and then choose New > menuContribution.
In Extension Element Details, you will add properties to the menus extension.
-
Add menuContribution properties in the locationURI element. Type the syntax that corresponds to the menu to which you are contributing.
-
For main menu contributions, see identifiers and syntax for main menus. If you are making a contribution from a view, your menu entry should be on the Tools menu.
-
The ocationURI syntax for application side bar contributions is
toolbar:com.sabre.edge.toolbar.sidebar
.
-
Eclipse adds the value in locationURI as a prefix to the menuContribution
in the All Extensions panel.
Adding command and commandParameter Elements
-
Right-click menu contribution, and then choose New > command.
-
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
.
-
Open the Extensions tab. Add properties to the command element in the following fields:
icon |
Add the image file for the menu contribution. This image appears on the GUI. |
label |
Type the text for your menu contribution. This label is displayed on the sub-menu to end-users. |
style |
The required value is push. |
Note
|
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.
-
Right-click command that you added to org.eclipse.ui.menus, and choose New > parameter.
-
Add properties to the parameter element in the following fields.
name |
For an editor, the value editorId is required if you are using the Sabre Red 360 internal class. |
value |
This is the identifier of the editor to open. For an editor, type the value in the id property for org.eclipse.ui.editors. |
-
When you are done, save MANIFEST.MF.
Using visibleWhen to Limit the Visibility of the Menu Contribution on the Side Bar
-
Right-click command, and then choose visibleWhen.
-
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.
-
If the editor will run Sabre emulator, use the definition that Sabre Red 360 requires. (See Rules for Sabre Emulator in an Editor.)
-
If the editor will run another application, provide your own definition. (See Rules for Other Applications in an Editor.)
Rules for Sabre Emulator in an Editor
-
Right-click visibleWhen, and then choose New > reference.
-
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
-
Right-click visibleWhen, and then choose New > with.
-
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.
-
Add the logical evaluation of the value. Right-click the with element, and then choose equals.
-
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.
-
Save MANIFEST.MF. Either click the Save icon or type Ctrl+S.