Menus

org.eclipse.ui.menus

3.2

This extension point allows the plug-in developer to define menus, separators, logical groups and menu items -- appearing anywhere within the application, from status lines to context menus. It also allows sets of such contributions to be defined (i.e., action sets); these action sets can be turned on or off by the end user. In brief, the menus extension point contains all of the presentation elements (except the icons) for contributing to any menu, tool bar or status line in Eclipse.

Every element within this extension point is given a unique identifier. This is so that these elements can be referred to elsewhere without having to restate the element. For example, the identifier might be required for ordering or for defining an action set. Also, this allows third-party plug-in developers to place these elements in new locations within the interface, as appropriate.

<!ELEMENT extension (item* , menu* , group* , widget* , actionSet*)>

<!ATTLIST extension

point CDATA #REQUIRED

id    CDATA #IMPLIED

name  CDATA #IMPLIED>


<!ELEMENT item (parameter* , location* , visibleWhen?)>

<!ATTLIST item

id        CDATA #REQUIRED

commandId CDATA #REQUIRED

menuId    CDATA #IMPLIED>

An item could be a menu item or a tool item, depending on where it is placed. It could also be something in the status line. The text and image associated with the item will be drawn from the command.



<!ELEMENT menu (location* , visibleWhen?)>

<!ATTLIST menu

id    CDATA #REQUIRED

label CDATA #IMPLIED>

A menu can appear either attached to a tool item, or somewhere within a view menu, context menu or the top-level menu bar. For free, the plug-in developer can assume that there is a menu and tool bar for every view, and that the top-level menu bar exists. Context menus must be registered programmatically before they can be used (see API Information).

A menu can only contain groups.



<!ELEMENT group (location*)>

<!ATTLIST group

id                CDATA #REQUIRED

separatorsVisible (true | false) "true">

A logical group. It can either be visible (e.g., separators are drawn before and after, as appropriate) or invisible. By default, logicial groups are visible.

A group can contain menus, items and other groups.



<!ELEMENT widget (location* , class? , visibleWhen?)>

<!ATTLIST widget

id    CDATA #REQUIRED

class CDATA #IMPLIED>

A menu elements that is given direct access to the widgets. For example, this can be used to render a combo box. Unfortunately, this means that if a widget element becomes visible in the user interface, this will lead to plug-in loading. Use this element with caution, as it can cause performance problems. This also will cause problems for things like macro support, scripting and pretty much any other command-based mechanism.



<!ELEMENT location (order? , (bar | part | popup))>

<!ATTLIST location

mnemonic   CDATA #IMPLIED

imageStyle CDATA #IMPLIED>

A location in which a menu, group, item or widget can appear. This element is used to control location-specific information.



<!ELEMENT bar EMPTY>

<!ATTLIST bar

type (menu|trim)

path CDATA #IMPLIED>

A leaf element within a location. This can be the menu bar, the tool bar or the status line. If unqualified, this indicates the top-level menu bar, tool bar or status line. If this is qualified with a part element, then this indicates that part's menu, tool bar or status line.



<!ELEMENT class (parameter*)>

<!ATTLIST class

class CDATA #REQUIRED>

A class element supporting the executable extension parsing syntax for both widget and dynamic elements.



<!ELEMENT visibleWhen (not | or | and | instanceof | test | systemTest | equals | count | with | resolve | adapt | iterate)>

<!ATTLIST visibleWhen

checkEnabled (true | false) "false">

Controls the visibility of the given element.



<!ELEMENT actionSet (reference+)>

<!ATTLIST actionSet

id          CDATA #REQUIRED

label       CDATA #REQUIRED

description CDATA #IMPLIED

visible     CDATA "false">

A named group of elements. The workbench allows the user to view action sets, and disable or enable them as desired. It is also possible for certain action sets to be associated with particular parts or perspectives.

An action set has a name and a unique identifier. It is also possible to specify whether the action set should be visible by default. Within the action set is simply a list of references to menus, groups, items and widgets that have been declared elsewhere.



<!ELEMENT part (popup | part)>

<!ATTLIST part

id    CDATA #IMPLIED

class CDATA #IMPLIED>

An element within a location. This qualifies the location to refer to a particular workbench part. This can be either a view or an editor. The qualification can use either the class name of the part (including inheritance), or it can refer to the identifier for the view or editor.

Only one of id and class can be specified.



<!ELEMENT reference EMPTY>

<!ATTLIST reference

id   CDATA #REQUIRED

type (menu|group|item|widget) >

A reference to an already existing element. This is used for action sets.



<!ELEMENT parameter EMPTY>

<!ATTLIST parameter

name  CDATA #REQUIRED

value CDATA #REQUIRED>

A parameter to either an executable extension or a command -- depending on where it appears in the extension.



<!ELEMENT order EMPTY>

<!ATTLIST order

position   (start|end|before|after)

relativeTo CDATA #IMPLIED>

Controls the position of a menu, group, item or widget within a particular location.



<!ELEMENT popup EMPTY>

<!ATTLIST popup

id   CDATA #IMPLIED

path CDATA #IMPLIED>

Part of a location. It indicates that the menu, group, item or widget should appear in the popup menu.



A basic menu definition looks like this.

<menu id=

"com.mycompany.myplugin.projection"

label=

"%Folding.label"

>

<location mnemonic=

"%Folding.label.mnemonic"

>

<part id=

"AntEditor"

>

<popup id=

"#RulerContext"

path=

"rest"

/>

</part>

</location>

</menu>

In this example, the plug-in developer is contributing to all parts who subclass or implement the given type. This allows, for example, for some contributions to be added to all text editors.

<menu id=

"com.mycompany.myplugin.textEditorMenu"

label=

"Text Commands"

>

<location mnemonic=

"X"

>

<part class=

"AbstractTextEditor"

>

<popup id=

"#RulerContext"

path=

"rest"

/>

</part>

</location>

</menu>

It is possible to associate help with a menu.

<menu id=

"com.mycompany.myplugin.RunWithConfigurationAction"

label=

"Run With Configuration"

helpContextId=

"run_with_configuration_context"

>

<location>

<menubar />

</location>

</menu>

Within a menu, it is possible to define logical groups. These logical groups can either be visible (e.g., separators are drawn before and after, as appropriate) or invisible. By default, logicial groups are visible.

<group id=

"com.mycompany.myplugin.stepGroup"

>

<location>

<menubar path=

"org.eclipse.ui.run"

/>

</location>

</group>

<group id=

"com.mycompany.myplugin.stepIntoGroup"

separatorsVisible=

"false"

>

<location>

<menubar path=

"org.eclipse.ui.run"

/>

</location>

</group>

It is possible to place menus, group, items and widgets in multiple locations.

<item id=

"com.mycompany.myplugin.ToggleStepFilters"

commandId=

"com.mycompany.myplugin.ToggleStepFilters"

>

<location mnemonic=

"%mnemonic"

>

<menubar path=

"org.eclipse.ui.run/emptyStepGroup"

/>

</location>

<location>

<part id=

"org.eclipse.debug.ui.DebugView"

>

<toolbar path=

"renderGroup"

/>

</part>

</location>

<location mnemonic=

"%mnemonic"

>

<part id=

"org.eclipse.debug.ui.DebugView"

>

<popup path=

"renderGroup"

/>

</part>

</location>

</item>

If the popup element is specified with no id and no parent part element, then it applies to any context menu registered with the workbench. This is similar to the behaviour of the old object contributions. Similarly, a top-level popup element with an id will affect any context menu registered with the given name.

<item id=

"com.mycompany.myplugin.ObjectContribution"

commandId=

"com.mycompany.myplugin.ObjectContribution"

>

<location>

<popup path=

"additions"

/>

</location>

</item>

Sometimes, you might want to control the visibility of an item. While normally it is preferrable to maintain stability in the layout of menus and tool bars, it is sometimes desirable to hide items that aren't immediately relevent. This is particularly true on context menus, where space is limited. In this case, you would define a visibleWhen element. This element is almost identical to the activeWhen and enabledWhen elements defined in the handlers extension point.

<item id=

"com.mycompany.myplugin.ConvertToWatchExpression"

commandId=

"com.mycompany.myplugin.ConvertToWatchExpression"

>

<location mnemonic=

"%mnemonic"

>

<part id=

"org.eclipse.debug.ui.DebugView"

>

<popup path=

"additions"

/>

</part>

</location>

<visibleWhen>

<with variable=

"selection"

>

<iterate operator=

"and"

>

<not>

<instanceof value=

"IWatchExpression"

/>

</not>

<instanceof value=

"IExpression"

/>

</iterate>

</with>

</visibleWhen>

</item>

The most common case is simply to make something visible when its handler is enabled. This is handled with some syntactic sugar. There is a checkEnabled attribute on the visibleWhen element.

<item id=

"com.mycompany.myplugin.compareWithPatch"

commandId=

"com.mycompany.myplugin.compareWithPatch"

>

<location mnemonic=

"%mnemonic"

>

<part id=

"MyPart"

>

<popup path=

"additions"

/>

</part>

</location>

<visibleWhen checkEnabled=

"true"

/>

</item>

Any item associated with a command can include parameter values. If the parameter of the given identifier is not defined, this is an error. If the item does not have a command, then this is also an error.

<item id=

"com.mycompany.myplugin.RunHistory"

commandId=

"com.mycompany.myplugin.RunHistory"

>

<location>

<menubar path=

"org.eclipse.ui.run"

/>

</location>

<parameter name=

"index"

value=

"1"

/>

</item>

It also possible to specify relative ordering. This is done using the order attribute on the location element. The order attribute accepts the following values: start (put the element at the beginning of the container); end (put the element at the end of its container); after (put the element after the sibling element whose id matches ref); and, before (put the element before the sibling element whose id matches ref). Relative ordering can be applied to any type of menu element.

<item id=

"com.mycompany.myplugin.MyFirstItem"

commandId=

"com.mycompany.myplugin.MyFirstCommand"

>

<location>

<order position=

"start"

/>

<menubar path=

"org.eclipse.ui.run"

/>

</location>

</item>

<item id=

"com.mycompany.myplugin.MySecondItem"

commandId=

"com.mycompany.myplugin.MySecondCommand"

>

<location>

<order position=

"after"

relativeTo=

"com.mycompany.myplugin.MyFirstItem"

/>

<menubar path=

"org.eclipse.ui.run"

/>

</location>

</item>

If you require direct access to the widgets (e.g., for rendering a combo box), then you can use a widget element. Unfortunately, this means that if a widget element becomes visible in the user interface, this will lead to plug-in loading.

<widget id=

"com.mycompany.myplugin.MyComboBoxSimple"

class=

"com.mycompany.myplugin.MyComboBox"

>

<location>

<toolbar path=

"myGroup"

>

</location>

</widget>

<widget id=

"com.mycompany.myplugin.MyComboBoxParameterized1"

class=

"com.mycompany.myplugin.MyComboBox:a,b,c"

>

<location>

<toolbar path=

"myGroup"

/>

</location>

</widget>

<widget id=

"com.mycompany.myplugin.MyComboBoxParameterized2"

>

<class class=

"com.mycompany.myplugin.MyComboBox"

>

<parameter name=

"list"

value=

"a,b,c"

/>

<parameter name=

"selected"

value=

"c"

/>

<parameter name=

"editable"

value=

"false"

/>

</class>

<location>

<toolbar pathd=

"myGroup"

/>

</location>

</widget>

It is possible to define action sets, or groups of elements with a name. The workbench allows the user to view acton sets, and disable or enable them as desired. It is also possible for certain action sets to be associated with particular parts or perspectives.

<actionSet label=

"%ProfileActionSet.label"

visible=

"false"

id=

"org.eclipse.debug.ui.profileActionSet"

>

<reference id=

"ProfileDropDownAction"

type=

"menu"

/>

<reference id=

"ProfileWithConfigurationAction"

type=

"menu"

/>

<reference id=

"ProfileHistoryMenuAction"

type=

"menu"

/>

<reference id=

"OpenProfileConfigurations"

type=

"item"

/>

<reference id=

"ProfileLast"

type=

"item"

/>

</actionSet>

To register a context menu, use the IWorkbenchPartSite.registerContextMenu methods.