# View Menus,Toolbars and Actions

This extension point is deprecated

###### Identifier:

org.eclipse.ui.viewActions

###### Description:

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

This extension point is used to add actions to the pulldown 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 triangle button. 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.

You can now use org.eclipse.ui.menus to place commands in menus and toolbars as well.

###### Configuration Markup:

<!ELEMENT extension (viewContribution+)>

<!ATTLIST extension

point CDATA #REQUIRED

id CDATA #IMPLIED

name CDATA #IMPLIED>

- point - a fully qualified identifier of the target extension point
- id - an optional identifier of the extension instance
- name - an optional name of the extension instance

The viewContribution element is deprecated

<!ELEMENT viewContribution (menu* , action*)>

<!ATTLIST viewContribution

id CDATA #REQUIRED

targetID IDREF #REQUIRED>

This element is used to define a group of view actions and/or menus.

- id - a unique identifier used to reference this contribution.
- targetID - a unique identifier of a registered view that is the target of this contribution.

The action element is deprecated

<!ELEMENT action ((selection* | enablement?) , class?)>

<!ATTLIST action

id CDATA #REQUIRED

label CDATA #REQUIRED

definitionId IDREF #IMPLIED

menubarPath CDATA #IMPLIED

toolbarPath CDATA #IMPLIED

icon CDATA #IMPLIED

disabledIcon CDATA #IMPLIED

hoverIcon CDATA #IMPLIED

tooltip CDATA #IMPLIED

helpContextId CDATA #IMPLIED

style (push|radio|toggle|pulldown) "push"

state (true | false)

class CDATA #REQUIRED

enablesFor CDATA #IMPLIED

mode (FORCE_TEXT) >

This element defines an action that the user can invoke in the UI.

- id - a unique identifier used as a reference for this action.
- label - a translatable name used either as the menu item text or toolbar button label. The name can include mnenomic information.
- definitionId - Specifies the command that this action will handle. By specifying and action, the key binding service can assign a key sequence to this action. See the extension point org.eclipse.ui.commands for more information.
- menubarPath - a slash-delimited path ('/') used to specify the location of this action in the pulldown menu. Each token in the path, except the last one, must represent a valid identifier of an existing menu in the hierarchy. The last token represents the named group into which this action will be added. If the path is omitted, this action will not appear in the pulldown menu.
- toolbarPath - a named group within the local toolbar of the target view. If the group does not exist, it will be created. If omitted, the action will not appear in the local toolbar.
- icon - a relative path of an icon used to visually represent the action in its context. If omitted and the action appears in the toolbar, the Workbench will use a placeholder icon. The path is relative to the location of the plugin.xml file of the contributing plug-in. The icon will appear in the toolbar but not in the pulldown menu.
- disabledIcon - a relative path of an icon used to visually represent the action in its context when the action is disabled. If omitted, the normal icon will simply appear greyed out. The path is relative to the location of the plugin.xml file of the contributing plug-in. The disabled icon will appear in the toolbar but not in the pulldown menu.
- hoverIcon - a relative path of an icon used to visually represent the action in its context when the mouse pointer is over the action. If omitted, the normal icon will be used. The path is relative to the location of the plugin.xml file of the contributing plug-in.
- tooltip - a translatable text representing the action's tool tip. Only used if the action appears in the toolbar.
- helpContextId - a unique identifier indicating the help context for this action. On some platforms, if the action appears as a menu item, then pressing the appropriate help key while the menu item is highlighted will display help. Not all platforms support this behaviour.
- style - an optional attribute to define the user interface style type for the action. If defined, the attribute value will be one of the following:

  | 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 pulldown tool item. The initial value is specified by the `state` attribute.

- state - an optional attribute indicating the initial state (either `true` or `false`), used when the `style` attribute has the value `radio` or `toggle`.
- class - name of the fully qualified class that implements `org.eclipse.ui.IViewActionDelegate`.
- enablesFor - a value indicating the selection count which must be met to enable the action. If this attribute is specified and the condition is met, the action is enabled. If the condition is not met, the action is disabled. If no attribute is specified, the action is enabled for any number of items selected. The following attribute formats are supported:

  | ! | - 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

- mode - For actions appearing in a toolbar, `FORCE_TEXT` will show text even if there is an icon. See ActionContribuitonItem.

The parameter element is deprecated

<!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.

- name - the parameter name
- value - the parameter value

The class element is deprecated

<!ELEMENT class (parameter*)>

<!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.

- class - A class that implements `org.eclipse.ui.IViewActionDelegate`. It may also implement `org.eclipse.core.runtime.IExecutableExtension`.

###### Examples:

The following is an example of a view action extension:

       <extension point="org.eclipse.ui.viewActions">
          <viewContribution
             id="com.xyz.xyzViewC1"
             targetID="org.eclipse.ui.views.navigator.ResourceNavigator">
             <menu
                id="com.xyz.xyzMenu"
                label="XYZ Menu"
                path="additions">
                <separator name="group1"/>
             </menu>
             <action
                id="com.xyz.runXYZ"
                label="&amp;Run XYZ Tool"
                menubarPath="com.xyz.xyzMenu/group1"
                toolbarPath="Normal/additions"
                style="toggle"
                state="true"
                icon="icons/runXYZ.png"
                tooltip="Run XYZ Tool"
                helpContextId="com.xyz.run_action_context"
                class="com.xyz.actions.RunXYZ">
                <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, the object in the selection must be a Java file resource.

The following is an other example of a view action extension:

       <extension point="org.eclipse.ui.viewActions">
          <viewContribution
             id="com.xyz.xyzViewC1"
             targetID="org.eclipse.ui.views.navigator.ResourceNavigator">
             <menu
                id="com.xyz.xyzMenu"
                label="XYZ Menu"
                path="additions">
                <separator name="group1"/>
             </menu>
             <action
                id="com.xyz.runXYZ2"
                label="&amp;Run XYZ2 Tool"
                menubarPath="com.xyz.xyzMenu/group1"
                style="push"
                icon="icons/runXYZ2.png"
                tooltip="Run XYZ2 Tool"
                helpContextId="com.xyz.run_action_context2"
                class="com.xyz.actions.RunXYZ2">
                <enablement>
                   <and>
                      <objectClass name="org.eclipse.core.resources.IFile"/>
                      <not>
                         <objectState name="extension" value="java"/>
                      </not>
                   </and>
                </enablement>
             </action>
          </viewContribution>
       </extension>

In the example above, the specified action will appear as a menu item. The action is enabled if the selection contains no Java file resources.

###### 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 class is loaded as late as possible to avoid loading the entire plug-in before it is really needed.

The interface `org.eclipse.ui.IViewActionDelegate` extends `org.eclipse.ui.IActionDelegate` and adds an additional method that allows the delegate to initialize with the view instance it is contributing into.

This extension point can be used to contribute actions into menus previously created by the target view. Omitting the menu path attribute will result in adding the new menu or action at the end of the pulldown menu.

The enablement criteria for an action extension is initially defined by `enablesFor`, and also either `selection` or `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 using the following rules:

1. Mnemonics 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 `&amp;` 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.

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>

###### 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.

Copyright (c) 2002, 2011 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