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

java.lang.Object
  extended byorg.eclipse.emf.edit.ui.action.CommandAction
All Implemented Interfaces:
IActionDelegate, IEditorActionDelegate
Direct Known Subclasses:
AddRootBottomAction, AddRootTopAction, CreateMappingAction, CreateOneSidedMappingAction, NameMatchMappingAction, RemoveMappingAction, TypeMatchMappingAction

public class CommandAction
extends Object
implements IEditorActionDelegate

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 overriden to do nothing.


Field Summary
protected  IAction action
          This returns the action to which we are delegating our action properties.
protected  Collection 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
          When the action is used as an editor part (for the menubar and toolbar), this records the current editor.
 
Constructor Summary
CommandAction()
          This constructs an instance.
 
Method Summary
protected  Command createActionCommand(EditingDomain editingDomain, Collection collection)
          This method must be implemented to create the command for this action, given the editing domain and the collection of selected objects.
protected  ImageDescriptor getDefaultImageDescriptor()
          This returns the image descriptor if the command does not provide an override.
protected  ImageDescriptor objectToImageDescriptor(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 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)
          The framework calls this so that we can register against this editor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

editorPart

protected IEditorPart editorPart
When the action is used as an editor part (for the menubar and toolbar), this records the current editor.


action

protected IAction action
This returns the action to which we are delegating our action properties.


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 Collection 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,
                                      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.


setActiveEditor

public void setActiveEditor(IAction action,
                            IEditorPart editorPart)
The framework calls this so that we can register against this editor. We use this as an opportunity to record the action and the editor part for later use.

Specified by:
setActiveEditor in interface IEditorActionDelegate

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(Object object)

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