Commands

A command is the declaration of a user action by id.  Commands are used to declare semantic actions so that action implementations defined in action sets and editors can associate themselves with a particular semantic command.  The separation of the command from the action implementation allows multiple plug-ins to define actions that implement the same semantic command.  The command is what gets associated with a particular key binding.

The workbench defines many common commands in its plugin.xml file, and plug-ins are encouraged to associate their own actions with these commands where it makes sense.  In this way, semantically similar actions implemented in different plug-ins may share the same key binding.

Defining a command

Commands are defined using the org.eclipse.ui.commands extension point.  The following comes from the workbench markup:

<extension
	point="org.eclipse.ui.commands">
	...
	<command
		name="%command.save.name"
		description="%command.save.description"
		categoryId="org.eclipse.ui.category.file"
		id="org.eclipse.ui.file.save">
	</command>
	...

The command definition specifies a name, description, and id for the action.   It also specifies the id of a category for the command, which is used to group commands in the preferences dialog.  The categories are also defined in the org.eclipse.ui.commands extension point:

      ...
      <category
            name="%category.file.name"
            description="%category.file.description"
            id="org.eclipse.ui.category.file">
      </category>
      ...

Note that there is no implementation specified for a command.  A command only becomes concrete when a plug-in associates its action with the command id.