Runtime

org.eclipse.gmf.runtime.common.ui.action
Class AbstractActionHandler

java.lang.Object
  extended byorg.eclipse.core.commands.common.EventManager
      extended byorg.eclipse.jface.action.AbstractAction
          extended byorg.eclipse.jface.action.Action
              extended byorg.eclipse.gmf.runtime.common.ui.action.AbstractActionHandler
All Implemented Interfaces:
IAction, IActionWithProgress, IDisposableAction, IOperationHistoryListener, IPropertyListener, ISelectionChangedListener
Direct Known Subclasses:
AbstractModelActionHandler, DiagramAction, GlobalAction, ShowPropertiesViewAction

public abstract class AbstractActionHandler
extends Action
implements IDisposableAction, IActionWithProgress, ISelectionChangedListener, IOperationHistoryListener, IPropertyListener

The abstract parent of all concrete action handlers that execute commands. Logging and exception handling are done in a uniform way in the run() method. Concrete subclasses must provide a definition of the doRun() method to gather any required input and execute a command. As an implementer of the IRepeatableAction interface, this class implements the isRepeatable() method to return true if it is enabled, and implements the repeat() method to run itself. Subclasses that aren't repeatable or require special repeat behavior must override the default implementations of these interface methods. This action handler supports life cycle methods by implementing the IDisposableAction interface. Therefore, clients need to call the init() method to initialize the action, and the dispose() method when the action is no longer needed.


Nested Class Summary
 
Nested classes inherited from class org.eclipse.gmf.runtime.common.ui.action.IActionWithProgress
IActionWithProgress.WorkIndicatorType
 
Field Summary
 
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
protected AbstractActionHandler(IWorkbenchPage workbenchPage)
          Constructs a new action handler that gets its workbench part by listening to the given workbench page
protected AbstractActionHandler(IWorkbenchPart workbenchPart)
          Constructs a new action handler for the specified workbench part.
 
Method Summary
protected  boolean contributedToPart(IWorkbenchPart part)
          Answers whether or not I am contributed to part.
 void dispose()
          Default implementation of dispose.
protected abstract  void doRun(IProgressMonitor progressMonitor)
          Performs the actual work when this action handler is run.
protected  ActionManager getActionManager()
          Retrieves the action manager for this action handler from its workbench part.
 java.lang.String getLabel()
          Retrieves the label for this action handler.
protected  IOperationHistory getOperationHistory()
          Returns the operation history for this action handler from its action manager.
protected  IPartListener getPartListener()
          Returns the part listener
protected  ISelection getSelection()
          Retrieves the current selection.
protected  IStructuredSelection getStructuredSelection()
          Retrieves the current structured selection.
protected  IUndoContext getUndoContext()
          Gets the undo context from my workbench part.
protected  IWorkbenchPage getWorkbenchPage()
          Returns the workbench page
protected  IWorkbenchPart getWorkbenchPart()
          Retrieves the value of the workbenchPart instance variable.
 IActionWithProgress.WorkIndicatorType getWorkIndicatorType()
          Gets type of work indicator (progress monitor, hourglass, or none).
protected  void handle(java.lang.Exception exception)
          Handles the specified exception.
 void historyNotification(OperationHistoryEvent event)
          Refreshes me if the history event has my workbench part's context, and the event is one of: OperationHistoryEvent.UNDONE OperationHistoryEvent.REDONE OperationHistoryEvent.OPERATION_ADDED OperationHistoryEvent.OPERATION_CHANGED OperationHistoryEvent.OPERATION_NOT_OK OperationHistoryEvent.OPERATION_REMOVED The other operation history events are ignored because they are intermediate events that will be followed by one of those listed above.
 void init()
          The basic implementation sets the workbenchpart if not already set and refreshes the action if the current part is not null.
 boolean isDisposed()
          Answers whether or not this action has been disposed and has not been re-initialized.
protected  boolean isOperationHistoryListener()
          Retrieves a Boolean indicating whether this action handler is interested in operation history changed events.
protected  boolean isPropertyListener()
          Answers whether of not this action handler is interested in property change events.
 boolean isRunnable()
          Retrieves a Boolean indicating whether this action handler can be run.
protected  boolean isSelectionListener()
          Retrieves a Boolean indicating whether this action handler is interested in selection events.
 boolean isSetup()
          Returns the setup state of this action.
protected  boolean needsSetup()
          Answers whether or not this action should be setup before it is run.
protected  void openErrorDialog(IStatus status)
          Opens an error dialog for the specified status object.
 void propertyChanged(java.lang.Object source, int propId)
          Property change event handler; does nothing by default.
 void run()
           
 void run(IProgressMonitor progressMonitor)
          Runs this action handler.
 void runWithEvent(Event event)
          Runs this action handler, passing the triggering SWT event.
 void selectionChanged(SelectionChangedEvent event)
          Notifies this action handler that the selection has changed.
protected  void setDisposed(boolean b)
          Sets my disposed state.
 void setPartSelector(IPartSelector partSelector)
          Sets my part selector.
protected  void setSetup(boolean setup)
          Sets the setup state of this action.
 boolean setup()
          Sets up the action.
protected  void setWorkbenchPart(IWorkbenchPart workbenchPart)
          Sets the current workbencgPart
 
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, 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, getAccelerator, getActionDefinitionId, getDescription, getDisabledImageDescriptor, getHelpListener, getHoverImageDescriptor, getId, getImageDescriptor, getMenuCreator, getStyle, getText, getToolTipText, isChecked, isEnabled, isHandled, removePropertyChangeListener, setAccelerator, setActionDefinitionId, setChecked, setDescription, setDisabledImageDescriptor, setEnabled, setHelpListener, setHoverImageDescriptor, setId, setImageDescriptor, setMenuCreator, setText, setToolTipText
 
Methods inherited from interface org.eclipse.gmf.runtime.common.ui.action.IActionWithProgress
refresh
 

Constructor Detail

AbstractActionHandler

protected AbstractActionHandler(IWorkbenchPart workbenchPart)
Constructs a new action handler for the specified workbench part.

Parameters:
workbenchPart - The workbench part to which this action handler applies.

AbstractActionHandler

protected AbstractActionHandler(IWorkbenchPage workbenchPage)
Constructs a new action handler that gets its workbench part by listening to the given workbench page

Parameters:
workbenchPage - The workbench page associated with this action handler
Method Detail

init

public void init()
The basic implementation sets the workbenchpart if not already set and refreshes the action if the current part is not null.

Any subclass that overrided this method should ensure that the disposed state of this action is maintained by calling setDisposed(false) or calling super.init().

Specified by:
init in interface IDisposableAction

dispose

public void dispose()
Default implementation of dispose. Any subclass that overrided this method should ensure that the disposed state of this action is maintained by calling setDisposed(true) or calling super.dispose().

Specified by:
dispose in interface IDisposableAction

setWorkbenchPart

protected void setWorkbenchPart(IWorkbenchPart workbenchPart)
Sets the current workbencgPart

Parameters:
workbenchPart - The current workbenchPart

contributedToPart

protected boolean contributedToPart(IWorkbenchPart part)
Answers whether or not I am contributed to part.

Parameters:
part - the workbench part to be tested
Returns:
true if I am contributed to this part, false otherwise.

setPartSelector

public final void setPartSelector(IPartSelector partSelector)
Sets my part selector. If my current workbench part doesn't match the part selector, I stop listening to selection, property and operation history changes on that part.

Parameters:
partSelector - my new part selector

getWorkbenchPart

protected final IWorkbenchPart getWorkbenchPart()
Retrieves the value of the workbenchPart instance variable.

Returns:
The value of the workbenchPart instance variable.

getActionManager

protected ActionManager getActionManager()
Retrieves the action manager for this action handler from its workbench part.

Returns:
The action manager for this action handler.

getOperationHistory

protected IOperationHistory getOperationHistory()
Returns the operation history for this action handler from its action manager.

Returns:
the operation history

run

public void run()
Specified by:
run in interface IAction

run

public void run(IProgressMonitor progressMonitor)
Runs this action handler.

Specified by:
run in interface IActionWithProgress
Parameters:
progressMonitor - IProgressMonitor monitoring the execution of this action

runWithEvent

public void runWithEvent(Event event)
Runs this action handler, passing the triggering SWT event.

Specified by:
runWithEvent in interface IAction
Parameters:
event - The SWT event which triggered this action being run.

selectionChanged

public final void selectionChanged(SelectionChangedEvent event)
Notifies this action handler that the selection has changed.

Specified by:
selectionChanged in interface ISelectionChangedListener
Parameters:
event - Event object describing the change.

propertyChanged

public void propertyChanged(java.lang.Object source,
                            int propId)
Property change event handler; does nothing by default. Subclasses should override if they are interested in handling property change events.

Specified by:
propertyChanged in interface IPropertyListener

getLabel

public java.lang.String getLabel()
Retrieves the label for this action handler.

Specified by:
getLabel in interface IActionWithProgress
Returns:
The label for this action handler.

getSelection

protected ISelection getSelection()
Retrieves the current selection.

Returns:
The current selection.

getStructuredSelection

protected IStructuredSelection getStructuredSelection()
Retrieves the current structured selection.

Returns:
The current structured selection.

isRunnable

public boolean isRunnable()
Retrieves a Boolean indicating whether this action handler can be run.

Specified by:
isRunnable in interface IActionWithProgress
Returns:
true if this action handler is enabled; false otherwise.

isSelectionListener

protected boolean isSelectionListener()
Retrieves a Boolean indicating whether this action handler is interested in selection events.

Returns:
true if this action handler is interested; false otherwise.

isPropertyListener

protected boolean isPropertyListener()
Answers whether of not this action handler is interested in property change events.

This default implementation always returns false. Subclasses must override if they are interested in property change events.

Returns:
true if this action handler is interested; false otherwise.

isOperationHistoryListener

protected boolean isOperationHistoryListener()
Retrieves a Boolean indicating whether this action handler is interested in operation history changed events.

Returns:
true if this action handler is interested; false otherwise.

handle

protected void handle(java.lang.Exception exception)
Handles the specified exception.

Parameters:
exception - The exception to be handled.

openErrorDialog

protected void openErrorDialog(IStatus status)
Opens an error dialog for the specified status object.

Parameters:
status - The status object for which to open an error dialog.

doRun

protected abstract void doRun(IProgressMonitor progressMonitor)
Performs the actual work when this action handler is run. Subclasses must override this method to do some work.

Parameters:
progressMonitor - the progress monitor for tracking the progress of this action when it is run.

getWorkIndicatorType

public IActionWithProgress.WorkIndicatorType getWorkIndicatorType()
Description copied from interface: IActionWithProgress
Gets type of work indicator (progress monitor, hourglass, or none).

Specified by:
getWorkIndicatorType in interface IActionWithProgress
Returns:
type of work indicator

getPartListener

protected IPartListener getPartListener()
Returns the part listener

Returns:
The part listener

getWorkbenchPage

protected IWorkbenchPage getWorkbenchPage()
Returns the workbench page

Returns:
The workbench page

historyNotification

public void historyNotification(OperationHistoryEvent event)
Refreshes me if the history event has my workbench part's context, and the event is one of: The other operation history events are ignored because they are intermediate events that will be followed by one of those listed above. We only want to refresh the action handler once for each change to the operation history.

Specified by:
historyNotification in interface IOperationHistoryListener

getUndoContext

protected IUndoContext getUndoContext()
Gets the undo context from my workbench part.

Returns:
the undo context

isDisposed

public boolean isDisposed()
Description copied from interface: IDisposableAction
Answers whether or not this action has been disposed and has not been re-initialized.

Specified by:
isDisposed in interface IDisposableAction
Returns:
true if the action has been disposed, false otherwise.

setDisposed

protected void setDisposed(boolean b)
Sets my disposed state.

Parameters:
b - true if I am disposed, false otherwise.

setup

public boolean setup()
Description copied from interface: IActionWithProgress
Sets up the action. Should always be called before IActionWithProgress.run(IProgressMonitor) is called.

Specified by:
setup in interface IActionWithProgress
Returns:
true if the setup completed successfully, false otherwise.

isSetup

public boolean isSetup()
Returns the setup state of this action.

Returns:
true if the action has been setup, false otherwise.

setSetup

protected void setSetup(boolean setup)
Sets the setup state of this action.

Parameters:
setup - true if the action has been setup, false otherwise.

needsSetup

protected boolean needsSetup()
Answers whether or not this action should be setup before it is run. Subclasses should override if they provide vital behaviour in the setup method.

Returns:
true if the action has a setup, false otherwise.

Runtime

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp., Borland Software Corp., and others 2005,2006. All rights reserved.