# Commands

###### Identifier:

org.eclipse.ui.commands

###### Since:

2.1

###### Description:

The `org.eclipse.ui.commands` extension point is used to declare commands and command categories, using the `command` and `category` elements. A command is an abstract representation of some semantic behaviour, but not it's actual implementation. This allows different developers to contribute specific behaviour for their individual parts. For example, there might be a "paste" command with one implementation in an editor and a different implementation in an explorer widget. These implementations are called handlers. Commands can also be viewed as declarative function pointers, or signal handlers.

###### Configuration Markup:

<!ELEMENT extension (category* , command* , commandParameterType* , context* , scope*)>

<!ATTLIST extension

id CDATA #IMPLIED

name CDATA #IMPLIED

point CDATA #REQUIRED>

- id - An optional identifier of the extension instance.
- name - An optional name of the extension instance.
- point - A fully qualified identifier of the target extension point.

<!ELEMENT command (defaultHandler? , state* , commandParameter*)>

<!ATTLIST command

category CDATA #IMPLIED

description CDATA #IMPLIED

id CDATA #REQUIRED

name CDATA #REQUIRED

categoryId IDREF #IMPLIED

defaultHandler CDATA #IMPLIED

returnTypeId IDREF #IMPLIED

helpContextId CDATA #IMPLIED>

This element is used to define commands. A command represents an request from the user that can be handled by an action, and should be semantically unique among other commands. Do not define a command if there is already one defined with the same meaning. If more than one of these elements exist with the same `id` attribute, only the last declared element (in order of reading the plugin registry) is considered valid. See the extension points org.eclipse.ui.actionSets and org.eclipse.ui.editorActions to understand how actions are connected to commands.

- Deprecated category - Please use `categoryId` instead.
- description - A translatable short description of this command for display in the UI.
- id - The unique identifier of this command.
- name - The translatable name of this command for display in the UI. Commands are typically named in the form of an imperative verb.
- categoryId -

  The unique id of the category for this command. If this command does not specify a category it will be placed in an global "Uncategorized" category.

  Since: 3.0

- defaultHandler -

  The default handler for this command (see the org.eclipse.ui.handlers extension point). If no other handler is active, this handler will be active. This handler will conflict with other handler definitions that specify no `activeWhen` conditions. If you are creating an `IExecutableExtension`, you can use the `defaultHandler` element instead.

  Since: 3.1

- returnTypeId -

  The id of a `commandParameterType` indicating the type of value returned by this command. Specifying a `returnTypeId` allows clients executing the command to associate the value returned with a Java type and to convert the value to a String form that may be stored and/or passed to another command that accepts parameters of the same type.

  Since: 3.2

- helpContextId -

  The identifier of the help context that relates to this command in general. Handlers can override this context identifier to provide help that is more specific to their particular behaviours.

  Since: 3.2

<!ELEMENT category EMPTY>

<!ATTLIST category

description CDATA #IMPLIED

id CDATA #REQUIRED

name CDATA #REQUIRED>

In the UI, commands are often organized by category to make them more manageable. This element is used to define these categories. Commands can add themselves to at most one category. If more than one of these elements exist with the same `id` attribute, only the last declared element (in order of reading the plugin registry) is considered valid.

- description - A translatable short description of this category for display in the UI.
- id - The unique identifier of this category.
- name - The translatable name of this category for display in the UI.

<!ELEMENT commandParameter (values?)>

<!ATTLIST commandParameter

id CDATA #REQUIRED

name CDATA #REQUIRED

values CDATA #IMPLIED

typeId IDREF #IMPLIED

optional (true | false) "true">

Defines a parameter that a command should understand. A parameter is a way to provide more information to a handler at execution time. For example, a "show view" command might take a view as a parameter. Handlers should be able to understand these parameters, so they should be treated like API.

Since: 3.1

- id - The unique identifier for this parameter.
- name - The name for the parameter. This is the name as it will be displayed to an end-user. As such, it should be translatable. The name should be short -- preferrably one word.
- values - The class providing a list of parameter values for the user to select. This class should implement `org.eclipse.core.commands.IParameterValues`. If this class is not specified, you must specify the more verbose `values` element. Please see `org.eclipse.core.runtime.IExecutableExtension`.
- typeId - The id of a commandParameterType for this commandParameter. Specifying a typeId allows handlers of a command to convert string parameter values to objects in a consistent way and it allows potential callers of a command to look for commands that take objects of various types for their parameters.
- optional - Whether this parameter is optional. If a parameter is optional, the handler should be able to handle the absence of the parameter. By default, all parameters are optional.

<!ELEMENT commandParameterType EMPTY>

<!ATTLIST commandParameterType

id CDATA #REQUIRED

type CDATA #IMPLIED

converter CDATA #IMPLIED>

Defines the object type of a commandParameter and may specify an `org.eclipse.core.commands.AbstractParameterValueConverter` subclass to convert between string parameter values and objects.

Since: 3.2

- id - The unique identifier for this commandParameterType.
- type - The fully qualified name of a Java class or interface to use as the type of this command parameter. This attribute is optional, however if omitted, `java.lang.Object` will be used as the parameter type.
- converter - The class for converting between objects and string representations of objects for command parameter values. This class should extend `org.eclipse.core.commands.AbstractParameterValueConverter`. The converter should produce and consume objects of the type indicated in the `type` attribute. If this class is not specified, this facility to convert between string and object values for this parameter type will not be available (the `getValueConverter()` on class `ParameterType` will return `null`).

<!ELEMENT values (parameter*)>

<!ATTLIST values

class CDATA #REQUIRED>

The more verbose version of the `values` attribute on the `commandParameter`.

Since: 3.1

- class - The class providing a list of parameter values for the user to select. This class should implement `org.eclipse.core.commands.IParameterValues`. If this class is not specified, you must specify the more verbose `values` element. Please see `org.eclipse.core.runtime.IExecutableExtension`.

<!ELEMENT parameter EMPTY>

<!ATTLIST parameter

name CDATA #REQUIRED

value CDATA #REQUIRED>

A possible value for a parameter.

Since: 3.1

- name - The name of the parameter to pass to the `IExecutableExtension`.
- value - The value of the parameter to pass to the `IExecutableExtension`.

<!ELEMENT defaultHandler (parameter)>

<!ATTLIST defaultHandler

class CDATA #REQUIRED>

The default handler for this command. If no other handler is active, this handler will be active. This handler will conflict with other handler definitions that specify no `activeWhen` conditions. If you are not creating an `IExecutableExtension`, you can use the `defaultHandler` attribute instead.

Since: 3.1

- class - The class which implements `org.eclipse.core.commands.IHandler`.

<!ELEMENT state (class?)>

<!ATTLIST state

class CDATA #IMPLIED

id CDATA #REQUIRED>

State information shared between all handlers, and potentially persisted between sessions.The state is simply a class that is loaded to look after the state. See the API Information for more details. This is not used for UI attributes like a menu contribution check box state or label.

Since: 3.2

- class - The class that can be loaded to store the state of this command. State is shared amongst handlers, and can be persisted between sessions. This class must subclass `org.eclipse.core.commands.State`. Please see API Information.
- id -

  A unique identifier for this state. This is used for persisting the state between sessions (if the state is an instance of `org.eclipse.jface.commands.PersistentState`). Certain common identifiers (see `org.eclipse.jface.menus.IMenuStateIds`) are understood when the command is being rendered in the menus or tool bars. The identifier only needs to be unique within the command defining the state.

<!ELEMENT class (parameter*)>

<!ATTLIST class

class CDATA #REQUIRED>

The class that can be loaded to store the state of this command. This element is used if you wish to pass multiple parameters to an `org.eclipse.core.runtime.IExecutableExtension`.

Since: 3.2

- class - The class that can be loaded to store the state of this command. State is shared amongst handlers, and can be persisted between sessions. This class must implement `org.eclipse.core.commands.State`. Please see API Information.

The context element is deprecated

<!ELEMENT context EMPTY>

<!ATTLIST context

description CDATA #IMPLIED

id CDATA #REQUIRED

name CDATA #REQUIRED

parent CDATA #IMPLIED

parentId CDATA #IMPLIED>

This element is used to define contexts. If more than one of these elements exist with the same `id` attribute, only the last declared element (in order of reading the plugin registry) is considered valid. Please use the org.eclipse.ui.contexts extension point instead.

- Deprecated description - A translatable short description of this context for display in the UI.
- Deprecated id - The unique identifier of this context.
- Deprecated name - The translatable name of this context for display in the UI. If this context has a parent, it is not necessary to add "(extends parent)" to the name. This will be automatically added by the UI where necessary.
- Deprecated parent - The unique id of the parent context. If this context has a parent, it will borrow all key bindings from its parent, in addition to the key bindings defined in its own context. @deprecated Please use "parentId" instead.
- Deprecated parentId - The unique id of the parent context. If this context has a parent, it will borrow all key bindings from its parent, in addition to the key bindings defined in its own context.

The scope element is deprecated

<!ELEMENT scope EMPTY>

<!ATTLIST scope

description CDATA #IMPLIED

id CDATA #REQUIRED

name CDATA #REQUIRED

parent CDATA #IMPLIED>

This element is used to define scopes. If more than one of these elements exist with the same `id` attribute, only the last declared element (in order of reading the plugin registry) is considered valid. @deprecated Please use the "org.eclipse.ui.contexts" extension point instead.

- Deprecated description - A translatable short description of this scope for display in the UI. @deprecated Please use the "org.eclipse.ui.contexts" extension point instead.
- Deprecated id - The unique identifier of this scope. @deprecated Please use the "org.eclipse.ui.contexts" extension point instead.
- Deprecated name - The translatable name of this scope for display in the UI. If this scope has a parent, it is not necessary to add "(extends parent)" to the name. This will be automatically added by the UI where necessary. @deprecated Please use the "org.eclipse.ui.contexts" extension point instead.
- Deprecated parent - The unique id of the parent scope. If this scope has a parent, it will borrow all key bindings from its parent, in addition to the key bindings defined in its own scope. @deprecated Please use the "org.eclipse.ui.contexts" extension point instead.

###### Examples:

The `plugin.xml` file in the `org.eclipse.ui` plugin makes extensive use of the `org.eclipse.ui.commands` extension point.

###### API Information:

Handlers can be registered with commands using the `org.eclipse.ui.handlers.IHandlerService`. This can be retrieved from various workbench components (e.g., workbench, workbench window, part site, etc.) by calling `getService(IHandlerService.class)`.

In general, it is preferrably to declare all commands statically (in `plugin.xml`). This is so that users can attach key bindings to the commands. However, it is possible to declare commands at run-time. To do this, retrieve the `org.eclipse.ui.commands.ICommandService` from a workbench component, call `getCommand(yourCommandID)` and then call `Command.define(...)`. Commands defined programmatically must be cleaned up by the plugin if it is unloaded.

There are a few default implementations of handler states that may be useful to users of this extension point:

- org.eclipse.jface.commands.TextState
- org.eclipse.jface.commands.RadioState
- org.eclipse.jface.commands.ToggleState
- org.eclipse.ui.handlers.RegistryRadioState
- org.eclipse.ui.handlers.RegistryToggleState

Copyright (c) 2000, 2007 IBM Corporation and others.
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html