## org.eclipse.emf.edit.ui.action
Class CommandAction

    java.lang.Object
      org.eclipse.emf.edit.ui.action.CommandAction

All Implemented Interfaces:
  IActionDelegate, IActionDelegate2, IEditorActionDelegate, IViewActionDelegate

Direct Known Subclasses:
  AddRootBottomAction, AddRootTopAction, CreateMappingAction, CreateOneSidedMappingAction, NameMatchMappingAction, RemoveMappingAction, TypeMatchMappingAction

    public class CommandAction

extends java.lang.Object
implements IEditorActionDelegate, IViewActionDelegate, IActionDelegate2

This class is used to implement a selection-based `IAction` on the menubar, the toolbar, or a popup menu by delegating all required behaviour to a `Command`. All aspects of the action are delegated, namely the enablement state, the menu text, the toolbar icon, and the help tip text. A derived class implements `createActionCommand` to return a command based on the `EditingDomain` and the collection of selected objects.

This class can also be used to implement actions not based on a selection, in that case the method `selectionChanged` should be overridden to do nothing.

Field Summary
`protected IAction` `action` This records the proxy action created by the platform.
`protected java.util.Collection<java.lang.Object>` `collection` This records the collection of selected objects so that a new command can be easily constructed after the execution of the command previously constructed from this selection.
`protected Command` `command` This records the command that is created each time the selection changes.
`protected EditingDomain` `editingDomain` This records the editing domain of the current editor.
`protected IEditorPart` `editorPart` Deprecated. As of EMF 2.1.0, replaced by `workbenchPart`.
`protected IWorkbenchPart` `workbenchPart` This records the editor or view with which the action is currently associated.

Constructor Summary
`CommandAction()` This constructs an instance.

Method Summary
`protected Command` `createActionCommand(EditingDomain editingDomain, java.util.Collection<?> collection)` This method must be implemented to create the command for this action, given the editing domain and the collection of selected objects.
`void` `dispose()` This is called when this action delegate is no longer needed.
`protected ImageDescriptor` `getDefaultImageDescriptor()` This returns the image descriptor if the command does not provide an override.
`void` `init(IAction action)` This is called immediately after this action delegate is created.
`void` `init(IViewPart view)` For view actions, the framework calls this when the view is shown, so that we can connect with it.
`protected ImageDescriptor` `objectToImageDescriptor(java.lang.Object object)`
`void` `run(IAction action)` The action must have been enabled for this to have been called, so we must have stored the selection already by this point.
`void` `runWithEvent(IAction action, Event event)` Because we implement `IActionDelegate2`, this is called instead of the old `run`.
`void` `selectionChanged(IAction action, ISelection selection)` This is invoked by the framework so that the action state can be updated.
`void` `setActiveEditor(IAction action, IEditorPart editorPart)` For editor actions, the framework calls this when the active editor changes, so that we can connect with it.
`void` `setActiveWorkbenchPart(IWorkbenchPart workbenchPart)` This records the specified workbench part, and if it is an editing domain provider, its editing domain.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### workbenchPart

    protected IWorkbenchPart workbenchPart

  This records the editor or view with which the action is currently associated.

  Since:
    2.1.0

### editorPart

    @Deprecated
    protected IEditorPart editorPart

  Deprecated. As of EMF 2.1.0, replaced by `workbenchPart`.
  If this action delegate is associated with an editor, it is also recorded here. This field was retained for backwards compatibility.

### action

    protected IAction action

  This records the proxy action created by the platform.

### editingDomain

    protected EditingDomain editingDomain

  This records the editing domain of the current editor. For global popups, we try to determine the editing domain from the selected objects themselves.

### collection

    protected java.util.Collection<java.lang.Object> collection

  This records the collection of selected objects so that a new command can be easily constructed after the execution of the command previously constructed from this selection.

### command

    protected Command command

  This records the command that is created each time the selection changes.

Constructor Detail

### CommandAction

    public CommandAction()

  This constructs an instance.

Method Detail

### createActionCommand

    protected Command createActionCommand(EditingDomain editingDomain,
                                          java.util.Collection<?> collection)

  This method must be implemented to create the command for this action, given the editing domain and the collection of selected objects.

### getDefaultImageDescriptor

    protected ImageDescriptor getDefaultImageDescriptor()

  This returns the image descriptor if the command does not provide an override.

### init

    public void init(IAction action)

  This is called immediately after this action delegate is created. We use this as an opportunity to record the proxy action for later use.

  Specified by:
    `init` in interface `IActionDelegate2`
  Since:
    2.1.0

### dispose

    public void dispose()

  This is called when this action delegate is no longer needed. This implementation does nothing.

  Specified by:
    `dispose` in interface `IActionDelegate2`
  Since:
    2.1.0

### setActiveEditor

    public void setActiveEditor(IAction action,
                                IEditorPart editorPart)

  For editor actions, the framework calls this when the active editor changes, so that we can connect with it. We call `setActiveWorkbenchPart(org.eclipse.ui.IWorkbenchPart)` to record it and its editing domain, if it can provide one.

  Specified by:
    `setActiveEditor` in interface `IEditorActionDelegate`

### init

    public void init(IViewPart view)

  For view actions, the framework calls this when the view is shown, so that we can connect with it. We call `setActiveWorkbenchPart(org.eclipse.ui.IWorkbenchPart)` to record it and its editing domain, if it can provide one.

  Specified by:
    `init` in interface `IViewActionDelegate`
  Since:
    2.1.0

### setActiveWorkbenchPart

    public void setActiveWorkbenchPart(IWorkbenchPart workbenchPart)

  This records the specified workbench part, and if it is an editing domain provider, its editing domain.

  Since:
    2.1.0

### runWithEvent

    public void runWithEvent(IAction action,
                             Event event)

  Because we implement `IActionDelegate2`, this is called instead of the old `run`. This simply calls that method, which must be invoked since a subclass may have overridden it.

  Specified by:
    `runWithEvent` in interface `IActionDelegate2`
  Since:
    2.1.0

### run

    public void run(IAction action)

  The action must have been enabled for this to have been called, so we must have stored the selection already by this point.

  Specified by:
    `run` in interface `IActionDelegate`

### selectionChanged

    public void selectionChanged(IAction action,
                                 ISelection selection)

  This is invoked by the framework so that the action state can be updated.

  Specified by:
    `selectionChanged` in interface `IActionDelegate`

### objectToImageDescriptor

    protected ImageDescriptor objectToImageDescriptor(java.lang.Object object)

Copyright 2001-2006 IBM Corporation and others. All Rights Reserved.