public class CommandAction
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
CommandAction()
This constructs an instance.
|
Modifier and Type | Method and Description |
---|---|
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.
|
protected IWorkbenchPart workbenchPart
@Deprecated protected IEditorPart editorPart
workbenchPart
.protected IAction action
protected EditingDomain editingDomain
protected java.util.Collection<java.lang.Object> collection
protected Command command
protected Command createActionCommand(EditingDomain editingDomain, java.util.Collection<?> collection)
protected ImageDescriptor getDefaultImageDescriptor()
public void init(IAction action)
public void dispose()
public void setActiveEditor(IAction action, IEditorPart editorPart)
setActiveWorkbenchPart(IWorkbenchPart)
to record it and its editing domain, if it can provide one.public void init(IViewPart view)
setActiveWorkbenchPart(IWorkbenchPart)
to record it and its editing domain, if it can provide one.public void setActiveWorkbenchPart(IWorkbenchPart workbenchPart)
public void runWithEvent(IAction action, Event event)
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.public void run(IAction action)
public void selectionChanged(IAction action, ISelection selection)
protected ImageDescriptor objectToImageDescriptor(java.lang.Object object)