Description: This extension point is used to add actions to the menu and toolbar for views registered by other plug-ins. Each view has a local pulldown menu normally activated by clicking on the top right area. Other plug-ins can contribute submenus and actions to this menu. Plug-ins may also contribute actions to a view toolbar. View owners are first given a chance to populate these areas. Optional additions by other plug-ins are appended.
Configuration Markup:
<!ELEMENT viewContribution (menu | action)*>
<!ATTLIST viewContribution
id
CDATA #REQUIRED
targetID CDATA #REQUIRED
>
<!ELEMENT menu (separator)+>id - a unique identifier that can be used to reference this contribution. targetID - the unique identifier of the view (as specified in the registry) into which the contribution is made.
<!ELEMENT action (selection)* (enablement)?>name - name of the separator that can later be referenced as the last token in the action path. Therefore, separators serve as named groups into which actions can be added.
In version 2.0 of Eclipse, an enablement element may be used to define the enablement for the action. For more information on the use of enablement element, refer to actionExpressions.html.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.
Action and menu labels may contain special characters that encode mnemonics which are specified using the ampersand ('&') character in front of a mnemonic character in the translatable text. Since ampersand is not allowed in XML strings, use & character entity.
If two or more actions are contributed to a menu or toolbar 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.
Examples:
The following is an example of a view actions extension point (note the subelements and the way attributes are used):
<extension point="org.eclipse.ui.viewActions">
<viewContribution
id="com.xyz.xyzViewC1"
targetID="org.eclipse.ui.views.ResourceNavigator">
<menu id="com.xyz.xyzMenu"
label="XYZ Menu"
path="additions">
<separator name="group1"/>
</menu>
<action id="com.xyz.runXYZ"
label="&Run XYZ Tool"
menubarPath="com.xyz.xyzMenu/group1"
toolbarPath="Normal/XYZ"
icon="icons/runXYZ.gif"
tooltip="Run XYZ Tool"
helpContextId="com.xyz.run_action_context"
class="com.xyz.actions.RunXYZ"
enablesFor="1"/>
<selection class="org.eclipse.core.resources.IFile" name="*.java">
</action>
</viewContribution>
</extension>
In the example above, the specified action will only enable for a single selection (enablesFor attribute). In addition, each object in this selection must implement the specified interface (IFile) and must be a Java file. Multiple selection elements can be specified, meaning 'one of'.
API Information: The value of the class attribute must be a fully qualified name of a Java class that implements org.eclipse.ui.IViewActionDelegate. This interface is loaded as late as possible to avoid loading the entire plug-in before it is really needed. It extends org.eclipse.ui.IActionDelegate and adds an additional method that allows the delegate to initialize with the view instance it is contributing into.
Supplied Implementation: Each view normally comes with a number of standard items on the pulldown menu and local toolbar. Additions from other plug-ins will be appended to the standard complement. It is helpful to publish the action identifiers for a view within a public interface. For example, the actions and major groups for the workbench window are defined in org.eclipse.ui.IWorkbenchActionConstants.