public abstract class StaticSelectionCommandAction
extends Action
org.eclipse.jface.action.IAction
on the menubar, the toolbar, or a pop-up menu by delegating all required
behaviour to a Command
, only when it is guaranteed that the
selection will not change during the life of the action. In other words,
the action itself would be created based on the selection, and destroyed
when the selection changed. All possible aspects of the action are
delegated to the command, namely the enablement state and, if it
implements CommandActionDelegate
, the text, the toolbar icon, and
the tool tip text; however, this need only be done once, at the time the
action is created.
Subclasses must provide an implementation for createActionCommand(org.eclipse.emf.edit.domain.EditingDomain, java.util.Collection<?>)
that creates the command to perform this action.
They may also override getDefaultImageDescriptor()
to provide a
default icon and disable()
to set the action's state when a command
cannot be created.
Modifier and Type | Field and Description |
---|---|
protected Command |
command
This records the command.
|
protected EditingDomain |
editingDomain
This records the editing domain of the current editor or viewer.
|
Constructor and Description |
---|
StaticSelectionCommandAction()
This constructs an instance without a specified workbenchPart.
|
StaticSelectionCommandAction(IEditorPart editorPart)
This constructor is simply retained for binary compatibility.
|
StaticSelectionCommandAction(IWorkbenchPart workbenchPart)
This constructs an instance for a command to be executed via
workbenchPart's editing domain.
|
Modifier and Type | Method and Description |
---|---|
void |
configureAction(ISelection selection)
This extracts the objects from selection, invokes createActionCommand
to create the command, and then configures the action based on the
result.
|
protected abstract Command |
createActionCommand(EditingDomain editingDomain,
java.util.Collection<?> collection)
This should be implemented to create a command that performs the action.
|
protected void |
disable()
This gets invoked when the selection is inappropriate or the command
cannot be created.
|
protected ImageDescriptor |
getDefaultImageDescriptor()
This can be overridden to provide the image descriptor used when the
command does not provide one.
|
protected ImageDescriptor |
objectToImageDescriptor(java.lang.Object object)
If necessary, this converts any image representation into an image
descriptor.
|
void |
run()
This executes the command.
|
protected EditingDomain editingDomain
protected Command command
public StaticSelectionCommandAction(IWorkbenchPart workbenchPart)
public StaticSelectionCommandAction(IEditorPart editorPart)
new form
.public StaticSelectionCommandAction()
protected abstract Command createActionCommand(EditingDomain editingDomain, java.util.Collection<?> collection)
public void configureAction(ISelection selection)
protected ImageDescriptor getDefaultImageDescriptor()
protected void disable()
public void run()
protected ImageDescriptor objectToImageDescriptor(java.lang.Object object)