WARNING: This extension point is DEPRECATED.
Do not use this extension point, it will be removed in future versions of this product.
Instead, use the extension point org.eclipse.ui.commands
You can now use org.eclipse.ui.menus to place commands editor or view contexts menus as well.
When the selection is heterogeneous, the contribution will be applied if registered against a common type of the selection, if possible. If a direct match is not possible, matching against superclasses and superinterfaces will be attempted.
Selection can be further constrained through the use of a name filter. If used, all the objects in the selection must match the filter in order to apply the contribution.
Individual actions in an object contribution can use the attribute enablesFor
to specify if it should only apply for a single, multiple, or any other selection type.
If these filtering mechanisms are inadequate an action contribution may use the filter mechanism. In this case the attributes of the target object are described in a series of name-value pairs. The attributes which apply to the selection are type-specific and beyond the domain of the workbench itself, so the workbench will delegate filtering at this level to the actual selection.
The objectContribution
element uses the core expression enablement
, as defined in org.eclipse.core.expressions.definitions.
<!ELEMENT extension (objectContribution* , viewerContribution*)>
<!ATTLIST extension
point CDATA #REQUIRED
id CDATA #IMPLIED
name CDATA #IMPLIED>
<!ELEMENT objectContribution (filter* , visibility? , enablement? , menu* , action*)>
<!ATTLIST objectContribution
id CDATA #REQUIRED
objectClass CDATA #REQUIRED
nameFilter CDATA #IMPLIED
adaptable (true | false) "false">
This element is used to define a group of actions and/or menus for any viewer context menus for which the objects of the specified type are selected. enablement
in this element refers to core expression enablement, as defined in org.eclipse.core.expressions.definitions, and affects the enablement of the objectContribution not the contained actions.
<!ELEMENT viewerContribution (visibility? , menu* , action*)>
<!ATTLIST viewerContribution
id CDATA #REQUIRED
targetID CDATA #REQUIRED>
This element is used to define a group of actions and/or menus for a specific view or editor part context menu.
getSite().registerContextMenu(*)
. If not specified when registered, it defaults to the view or editor ID.<!ELEMENT action (selection* , enablement? , class?)>
<!ATTLIST action
id CDATA #REQUIRED
label CDATA #REQUIRED
definitionId IDREF #IMPLIED
menubarPath CDATA #IMPLIED
icon CDATA #IMPLIED
helpContextId CDATA #IMPLIED
style (push|radio|toggle|pulldown)
state (true | false)
class CDATA #REQUIRED
enablesFor CDATA #IMPLIED
overrideActionId IDREF #IMPLIED
tooltip CDATA #IMPLIED>
This element defines an action that the user can invoke in the UI.
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 | - as a cascading style menu item. |
! | - 0 items selected | |
? | - 0 or 1 items selected | |
+ | - 1 or more items selected | |
multiple, 2+ | - 2 or more items selected | |
n | - a precise number of items selected.a precise number of items selected. For example: enablesFor=" 4" enables the action only when 4 items are selected | |
* | - any number of items selected |
The enablement criteria for an action extension are initially defined by enablesFor, selection and enablement. However, once the action delegate has been instantiated it may control the action enable state directly within its selectionChanged method.
<!ELEMENT filter EMPTY>
<!ATTLIST filter
name CDATA #REQUIRED
value CDATA #REQUIRED>
This element is used to evaluate the attribute state of each object in the current selection. A match only if each object in the selection has the specified attribute state. Each object in the selection must implement, or adapt to, org.eclipse.ui.IActionFilter.
<!ELEMENT parameter EMPTY>
<!ATTLIST parameter
name CDATA #REQUIRED
value CDATA #REQUIRED>
A parameter element to be used within an IExecutableExtension element. This will be passed as initialization data to the instantiated class.
<!ATTLIST class
class CDATA #IMPLIED>
The element version of the class
attribute. This is used when the class implements org.eclipse.core.runtime.IExecutableExtension
and there is parameterized data that you wish used in its initialization.
org.eclipse.core.runtime.IExecutableExtension
.
<extension point="org.eclipse.ui.popupMenus"> <objectContribution id="com.xyz.C1" objectClass="org.eclipse.core.resources.IFile" nameFilter="*.java"> <menu id="com.xyz.xyzMenu" path="additions" label="&XYZ Java Tools"> <separator name="group1"/> </menu> <action id="com.xyz.runXYZ" label="&Run XYZ Tool" style="push" menubarPath="com.xyz.xyzMenu/group1" icon="icons/runXYZ.png" helpContextId="com.xyz.run_action_context" class="com.xyz.actions.XYZToolActionDelegate" enablesFor="1" /> </objectContribution> <viewerContribution id="com.xyz.C2" targetID="org.eclipse.ui.views.TaskList"> <action id="com.xyz.showXYZ" label="&Show XYZ" style="toggle" state="true" menubarPath="additions" icon="icons/showXYZ.png" helpContextId="com.xyz.show_action_context" class="com.xyz.actions.XYZShowActionDelegate" /> </viewerContribution> </extension>In the example above, the specified object contribution action will only enable for a single selection (enablesFor attribute). In addition, each object in the selection must implement the specified interface (IFile) and must be a Java file. This action will be added into a submenu previously created. This contribution will be effective in any view that has the required selection.
In contrast, the viewer contribution above will only appear in the Tasks view context menu, and will not be affected by the selection in the view.
The following is an example of the filter mechanism. In this case the action will only appear for IMarkers which are completed and have high priority.
<extension point="org.eclipse.ui.popupMenus"> <objectContribution id="com.xyz.C3" objectClass="org.eclipse.core.resources.IMarker"> <filter name="done" value="true"/> <filter name="priority" value="2"/> <action id="com.xyz.runXYZ" label="High Priority Completed Action Tool" icon="icons/runXYZ.png" class="com.xyz.actions.MarkerActionDelegate"> </action> </objectContribution> </extension>The following is an other example of using the visibility element:
<extension point="org.eclipse.ui.popupMenus"> <viewerContribution id="com.xyz.C4" targetID="org.eclipse.ui.views.TaskList"> <visibility> <and> <pluginState id="com.xyz" value="activated"/> <systemProperty name="ADVANCED_MODE" value="true"/> </and> </visibility> <action id="com.xyz.showXYZ" label="&Show XYZ" style="push" menubarPath="additions" icon="icons/showXYZ.png" helpContextId="com.xyz.show_action_context" class="com.xyz.actions.XYZShowActionDelegate"> </action> </viewerContribution> </extension>
In the example above, the specified action will appear as a menu item in the Task view context menu, but only if the "com.xyz" plug-in is active and the specified system property is set to true.
Note: For backwards compatibility, org.eclipse.ui.IActionDelegate may be implemented for object contributions.
Conext menu extension within a part is only possible when the target part publishes a menu for extension. This is strongly encouraged, as it improves the extensibility of the product. To accomplish this each part should publish any context menus which are defined by calling IWorkbenchPartSite.registerContextMenu. Once this has been done the workbench will automatically insert any action extensions which exist.
A menu id must be provided for each registered menu. For consistency across parts the following strategy should be adopted by all part implementors.
Any context menu which is registered with the workbench also should contain a standard insertion point with id IWorkbenchActionConstants.MB_ADDITIONS. Other plug-ins will use this value as a reference point for insertion. The insertion point may be defined by adding a GroupMarker to the menu at an appropriate location for insertion.
An object in the workbench which is the selection in a context menu may define an org.eclipse.ui.IActionFilter. This is a filtering strategy which can perform type specific filtering. The workbench will retrieve the filter for the selection by testing to see if it implements IActionFilter. If that fails, the workbench will ask for a filter through the IAdaptable mechanism.
Action and menu labels may contain special characters that encode mnemonics which are specified using the ampersand ('&') character in front of a selected character in the translated text. Since ampersand is not allowed in XML strings, use & character entity.
If two or more actions are contributed to a menu by a single extension the actions will appear in the reverse order of how they are listed in the plugin.xml file. This behavior is admittedly unintuitive. However, it was discovered after the Eclipse Platform API was frozen. Changing the behavior now would break every plug-in which relies upon the existing behavior.
The selection and enablement elements are mutually exclusive. The enablement element can replace the selection element using the sub-elements objectClass and objectState. For example, the following:
<selection class="org.eclipse.core.resources.IFile" name="*.java"> </selection>can be expressed using:
<enablement> <and> <objectClass name="org.eclipse.core.resources.IFile"/> <objectState name="extension" value="java"/> </and> </enablement>
Copyright (c) 2000, 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