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

java.lang.Object
  extended by org.eclipse.core.commands.common.EventManager
      extended by org.eclipse.jface.action.AbstractAction
          extended by org.eclipse.jface.action.Action
              extended by org.eclipse.emf.edit.ui.action.StaticSelectionCommandAction
All Implemented Interfaces:
IAction
Direct Known Subclasses:
CreateChildAction, CreateChildAction, CreateSiblingAction

public abstract class StaticSelectionCommandAction
extends Action

This class is used as a basis for implementing an 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.


Field Summary
protected  Command command
          This records the command.
protected  EditingDomain editingDomain
          This records the editing domain of the current editor or viewer.
 
Fields inherited from interface org.eclipse.jface.action.IAction
AS_CHECK_BOX, AS_DROP_DOWN_MENU, AS_PUSH_BUTTON, AS_RADIO_BUTTON, AS_UNSPECIFIED, CHECKED, DESCRIPTION, ENABLED, HANDLED, IMAGE, RESULT, TEXT, TOOL_TIP_TEXT
 
Constructor Summary
StaticSelectionCommandAction()
          This constructs an instance without a specified workbenchPart.
StaticSelectionCommandAction(EditingDomain editingDomain)
          This constructs an instance for a command to be executed via the given editing domain.
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.
 
Method Summary
 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.
 
Methods inherited from class org.eclipse.jface.action.Action
convertAccelerator, convertAccelerator, findKeyCode, findKeyString, findModifier, findModifierString, getAccelerator, getActionDefinitionId, getDescription, getDisabledImageDescriptor, getHelpListener, getHoverImageDescriptor, getId, getImageDescriptor, getMenuCreator, getStyle, getText, getToolTipText, isChecked, isEnabled, isHandled, notifyResult, removeAcceleratorText, removeMnemonics, runWithEvent, setAccelerator, setActionDefinitionId, setChecked, setDescription, setDisabledImageDescriptor, setEnabled, setHelpListener, setHoverImageDescriptor, setId, setImageDescriptor, setMenuCreator, setText, setToolTipText
 
Methods inherited from class org.eclipse.jface.action.AbstractAction
addPropertyChangeListener, firePropertyChange, firePropertyChange, removePropertyChangeListener
 
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jface.action.IAction
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

editingDomain

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


command

protected Command command
This records the command.

Constructor Detail

StaticSelectionCommandAction

public StaticSelectionCommandAction(IWorkbenchPart workbenchPart)
This constructs an instance for a command to be executed via workbenchPart's editing domain.

Since:
2.1.0

StaticSelectionCommandAction

public StaticSelectionCommandAction(IEditorPart editorPart)
This constructor is simply retained for binary compatibility. It just calls the new form.


StaticSelectionCommandAction

public StaticSelectionCommandAction(EditingDomain editingDomain)
This constructs an instance for a command to be executed via the given editing domain.

Since:
2.4.0

StaticSelectionCommandAction

public StaticSelectionCommandAction()
This constructs an instance without a specified workbenchPart.

Method Detail

createActionCommand

protected abstract Command createActionCommand(EditingDomain editingDomain,
                                               java.util.Collection<?> collection)
This should be implemented to create a command that performs the action.


configureAction

public 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.


getDefaultImageDescriptor

protected ImageDescriptor getDefaultImageDescriptor()
This can be overridden to provide the image descriptor used when the command does not provide one. This implementation simply returns null.


disable

protected void disable()
This gets invoked when the selection is inappropriate or the command cannot be created. It puts the action in the correct state for such error conditions. This implementation disables the action and sets its icon to the default.


run

public void run()
This executes the command.

Specified by:
run in interface IAction
Overrides:
run in class Action

objectToImageDescriptor

protected ImageDescriptor objectToImageDescriptor(java.lang.Object object)
If necessary, this converts any image representation into an image descriptor.


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