This extension point allows the plug-in developer to add (contribute) a variety of custom additions to the eclipse framework:
It provides a common implementation for and acts as a replacement of the following (legacy) eclipse extension points:
The general strategy for this mechanism is to separate the 'location' where the contributions should be inserted from the visibility and enablement state of the element. Each contribution first defines its insertion location through a Menu 'URI', a string (loosely) formatted according to the jave.net.URI format:
"[Scheme]:[ID]?[ArgList]"
This will define the location at which the contributions will appear in the eclipse UI. Once the insertion point has been defined the rest of the contributions describe the UI elements that will be added at that location. Each element supports a 'visibleWhen' expression that determines at run time whether a particular item should appear in the menu based on the system's current state (selection, active view/editor, context...). See org.eclipse.ui.ISources
for a list of currently
supported variables.
<!ELEMENT extension (group* , widget* , menuContribution*)>
<!ATTLIST extension
point CDATA #REQUIRED
id CDATA #IMPLIED
name CDATA #IMPLIED>
<!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, logical groups are visible.
A group can contain menus, items and other groups.
This element is deprecated. Groups are now expressed as id'd 'separator' elements. The menu insertion URI can be used to define an insertion point either 'before' or 'after' any id'd element and placing it after the separator is the same as contributing it to the group.
See the documentation for the 'locationURI' attribute of 'menuAddition' for more details on how to define insertion points and how they relate to the menu structure.
org.eclipse.ui
might be called org.eclipse.ui.group1
.<!ELEMENT widget (location* , class? , visibleWhen? , layout?)>
<!ATTLIST widget
id CDATA #REQUIRED
class CDATA #REQUIRED>
NOTE: This element is deprecated. Clients should contribute a Toolbar to one of the trim areas and place a control contribution inside it. See the Trim Contribution example for details.
org.eclipse.ui
might be called org.eclipse.ui.widget1
.
If defined then it can be used as a reference in the Query part of the location defining whether the additions are to go before or after this element (or at the end of the logical group containing this element using the 'endof' value).
IWorkbenchWidget
you should use the default implementation; AbstractWorkbenchTrimWidget
as the base from which to derive your widget implementation. This implementation handles the 'init' method and caches the result for use through its getWorkbenchWindow
method.<!ELEMENT layout EMPTY>
<!ATTLIST layout
fillMajor (true | false)
fillMinor (true | false) >
This element can be used to specify various layout options for elements added into trim
locations.
false
.false
.<!ELEMENT location (order? , (bar | part | popup))>
<!ATTLIST location
mnemonic CDATA #IMPLIED
imageStyle CDATA #IMPLIED>
menu
, group
, item
or widget
can appear. This element is used to control location-specific information.
This element is deprecated. Users of this extension point should now define the location at which their contributions should appear using the 'locationURI' specification.
<!ELEMENT bar EMPTY>
<!ATTLIST bar
type (menu|trim)
path CDATA #IMPLIED>
A leaf element within a location. This can be the menu bar or the trim area. If unqualified, this indicates the top-level menu bar or trim. If this is qualified with a part
element, then this indicates that part's menu or trim.
NOTE: This is not only deprecated but has no value in the current implementation (the only acceptable value is 'trim' which is the default. You may safely remove this from any declarations.
What type of bar to contribute to. This can be menu
or trim
. If contributing to the menu, then the item will be parented to some widget structure. In general, this means using widget elements does not make much sense, and an icon for an item's command is not strictly necessary. The default value is menu
.
If contributing to the trim
, then the bar will generally not require a command or an icon, it should be filled with a widget that displays the trim information.
Within the trim, the workbench defines five general groups which correspond to various positions around the window:
vertical1
.<!ATTLIST class
class CDATA #REQUIRED>
A class element supporting the executable extension parsing syntax for both widget
and dynamic
elements.
IExecutableExtension
.<!ELEMENT visibleWhen (not | or | and | instanceof | test | systemTest | equals | count | with | resolve | adapt | iterate | reference)?>
<!ATTLIST visibleWhen
checkEnabled (true | false) "false">
A core Expression that controls the visibility of the given element.
true
, then there should be no sub-elements. This just checks the enabled state of the command, and makes the corresponding element visible if the command is enabled.<!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.
NOTE: This element is deprecated. It had been used for a previous technique for adding trim elements. Instead, clients should contribute a Toolbar to one of the trim areas and place a control contribution inside it. See the Trim Contribution example for details.
<!ELEMENT parameter EMPTY>
<!ATTLIST parameter
name IDREF #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 widget within a particular group.
This 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.
In the event of conflicts, Eclipse will chose an arbitrary order. The only guarantee is that, in the event of a conflict, the order will remain the same as long as the following holds:
position
is before
or after
.<!ELEMENT popup EMPTY>
<!ATTLIST popup
id CDATA #IMPLIED
path CDATA #IMPLIED>
NOTE: This element is deprecated. It had been used for a previous technique for adding trim elements. Instead, clients should contribute a Toolbar to one of the trim areas and place a control contribution inside it. See the Trim Contribution example for details.
<!ELEMENT menuContribution (menu* , command* , separator* , dynamic* , toolbar* , control*)>
<!ATTLIST menuContribution
locationURI CDATA #REQUIRED
class CDATA #IMPLIED
allPopups (true | false) "false">
Defines an ordered set of additions to the command UI structure. The defined elements will be added into the command UI structure at the location specified by the locationURI
element.
This should be the starting point for all contributions into menus, toolbars or trim, wherever they occur in the UI.
URI
specification that defines the insertion point at which the contained additions will be added.
The format for the URI is comprised of three basic parts:
The placement modifier is executed when this contribution is processed. Following contributions may change the final shape of the menu when they are processed.
<!ELEMENT menu (visibleWhen? , (menu? | command? | separator? | dynamic?)*)?>
<!ATTLIST menu
label CDATA #REQUIRED
id CDATA #IMPLIED
mnemonic CDATA #IMPLIED
icon CDATA #IMPLIED
tooltip CDATA #IMPLIED
commandId IDREF #IMPLIED>
Defines a new menu contribution at the given insertion point.
<!ELEMENT command (visibleWhen? , parameter*)>
<!ATTLIST command
label CDATA #IMPLIED
commandId IDREF #REQUIRED
id CDATA #IMPLIED
mnemonic CDATA #IMPLIED
icon CDATA #IMPLIED
disabledIcon CDATA #IMPLIED
hoverIcon CDATA #IMPLIED
tooltip CDATA #IMPLIED
helpContextId CDATA #IMPLIED
style (push|radio|toggle|pulldown) "push"
mode (FORCE_TEXT) >
Defines a new Command Contribution at the defined insertion point.
ISharedImages
constant.push | - as a regular menu item or tool item. | |
radio | - as a radio style menu item or tool item. Actions with the radio style within the same menu or toolbar group behave as a radio set. The initial value is specified by the state attribute. | |
toggle | - as a checked style menu item or as a toggle tool item. The initial value is specified by the state attribute. | |
pulldown | - (ToolBar only) Creates a ToolItem with the SWT.DROP_DOWN affordance. The URI of the menu is "menu:" + this item's ID. |
FORCE_TEXT
will show text even if there is an icon. See CommandContributionItem.<!ELEMENT separator EMPTY>
<!ATTLIST separator
name CDATA #REQUIRED
visible (true | false) >
Inserts a separator at the current insertion point.
Separator contributions that have an id define the start of a logical group so the result of using the 'endof' value for placement is to search forward in the current menu to locate the next separator and to place the inserted elements before that element. If no trailing separator is found then the items are placed at the end of the menu.
false
by default.<!ELEMENT toolbar (visibleWhen? , (command? | separator? | dynamic? | control?)*)?>
<!ATTLIST toolbar
id CDATA #REQUIRED
label CDATA #IMPLIED>
Contributes a new ToolBar at the current insertion point. This element is only currently valid for CoolBarManagers, which can contain toolbars. For example, the trim location URIs specified in org.eclipse.ui.menus.MenuUtil
.
<!ELEMENT control (visibleWhen?)>
<!ATTLIST control
id CDATA #IMPLIED
class CDATA #REQUIRED>
NOTE: Due to platform restrictions control contributions are only supported for toolbars; Attempts to contribute controls into a menu or popup will be treated as a NO-OP.
<!ELEMENT dynamic (class? , visibleWhen?)>
<!ATTLIST dynamic
id CDATA #REQUIRED
class CDATA #REQUIRED>
The element provides a mechanism that will call back into the defined class to provide an IContributionItem to be shown when the menu or toolbar is built. The defined class must be a derivative of the org.eclipse.jface.action.ContributionItem base class. It can also use org.eclipse.ui.action.CompoundContributionItem and provide an implementation for the abstract getContributionItems
method to provide a dynamic menu item.
org.eclipse.ui
might be called org.eclipse.ui.widget1
.
If defined then it can be used as a reference in the Query part of the location defining whether the additions are to go before or after this element (or at the end of the logical group containing this element using the 'endof' value).
A basic extension looks like this.
<extension id="add.item" point="org.eclipse.ui.menus"> <menuContribution locationURI="menu:someorg.somemenu.id?after=additions"> <command commandId="someorg.someid.someCommand" icon="icons/anything.png" id="someorg.someid.BasicCmdItem" label="Simple Item" mnemonic="S"> </command> </menuContribution> </extension>
This is the simplest example; adding a command contribution after an existing menu's additions group.
It is preferred that menu contributions be added in the plugin.xml
. Plugins can
programmatically add their own menu contributions using org.eclipse.ui.menus.IMenuService
and org.eclipse.ui.menus.AbstractContributionFactory
, but should be sure to remove them if the plugin is unloaded. The IMenuService
can be retrieved through any of the IServiceLocators
, the workbench, the workbench window, or the part site.
See org.eclipse.ui.commands to define a command and org.eclipse.ui.handlers to define an implementation for the command.
To register a context menu, use the IWorkbenchPartSite.registerContextMenu
methods.
Copyright (c) 2005,2007 IBM Corporation and others.
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0 which accompanies
this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html/
SPDX-License-Identifier: EPL-2.0