Runtime

## org.eclipse.gmf.runtime.common.ui.action
Class AbstractActionDelegate

    java.lang.Object
      org.eclipse.gmf.runtime.common.ui.action.AbstractActionDelegate

All Implemented Interfaces:
  IActionWithProgress, IPartListener

Direct Known Subclasses:
  AbstractModelActionDelegate, PropertyWindowActionDelegate

public abstract class AbstractActionDelegate
extends java.lang.Object
implements IPartListener, IActionWithProgress

The abstract parent of all concrete action delegates 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 its plug-in action is enabled, and implements the `repeat()` method to run the delegate's action. Subclasses that aren't repeatable or require special repeat behavior must override the default implementations of these interface methods.

This class provides definitions for the methods that are found in four of the five action delegate interfaces in Eclipse. Hence, in most cases, adding a new action delegate is simply a matter of subclassing this class and declaring that the new class implements the desired action delegate interface.

See Also:
  `IActionDelegate`, `IEditorActionDelegate`, `IObjectActionDelegate`, `IViewActionDelegate`, `IWorkbenchWindowActionDelegate`, `IActionDelegate2`

Nested Class Summary

Nested classes inherited from class org.eclipse.gmf.runtime.common.ui.action.IActionWithProgress
`IActionWithProgress.WorkIndicatorType`

Constructor Summary
`protected` `AbstractActionDelegate()` Constructs a new action delegate.

Method Summary
`void` `dispose()` Disposes this action delegate.
`protected abstract void` `doRun(IProgressMonitor progressMonitor)` Performs the actual work when this action delegate is run.
`protected IAction` `getAction()` Retrieves the value of the `action` instance variable.
`protected ActionManager` `getActionManager()` Retrieves the action manager for this action delegate from its workbench part.
`java.lang.String` `getLabel()` Retrieves the label for this action delegate.
`protected IOperationHistory` `getOperationHistory()` Gets the operation history for this action delegate from its action manager.
`protected ISelection` `getSelection()` Retrieves the current selection.
`protected IStructuredSelection` `getStructuredSelection()` Retrieves the current structured selection.
`protected IWorkbenchPart` `getWorkbenchPart()` Retrieves the value of the `workbenchPart` instance variable.
`protected IWorkbenchWindow` `getWorkbenchWindow()` Retrieves the value of the `workbenchWindow` 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` `init(IAction anAction)` Allows the action delegate to initialize itself after being created by the proxy action.
`void` `init(IViewPart view)` Initializes this action delegate with the view it will work in.
`void` `init(IWorkbenchWindow window)` Initializes this action delegate with the workbench window it will work in.
`boolean` `isRunnable()` Retrieves a Boolean indicating whether this action delegate can be run.
`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` `partActivated(IWorkbenchPart part)` Notifies this action delegate that the given part has been activated.
`void` `partBroughtToTop(IWorkbenchPart part)` Notifies this action delegate that the given part has been brought to the top.
`void` `partClosed(IWorkbenchPart part)` Notifies this action delegate that the given part has been closed.
`void` `partDeactivated(IWorkbenchPart part)` Notifies this action delegate that the given part has been deactivated.
`void` `partOpened(IWorkbenchPart part)` Notifies this action delegate that the given part has been opened.
`void` `refresh()` Refreshes various aspects of this action, such as its label and whether or not it is enabled.
`void` `run(IAction act)` Performs this action.
`void` `run(IProgressMonitor progressMonitor)` Runs this action delegate.
`void` `runWithEvent(IAction anAction, Event event)` Performs this action, passing the SWT event which triggered it.
`void` `selectionChanged(IAction act, ISelection selection)` Notifies this action delegate that the selection in the workbench has changed.
`protected void` `setAction(IAction action)` Sets the `action` instance variable to the specified value.
`void` `setActiveEditor(IAction action, IEditorPart targetEditor)` Sets the active editor for this action delegate.
`void` `setActivePart(IAction action, IWorkbenchPart targetPart)` Sets the active part for this delegate.
`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 `workbenchPart` instance variable to the specified value.
`protected void` `setWorkbenchWindow(IWorkbenchWindow workbenchWindow)` Sets the `workbenchWindow` instance variable to the specified value.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### AbstractActionDelegate

    protected AbstractActionDelegate()

  Constructs a new action delegate.

Method Detail

### getAction

    protected final IAction getAction()

  Retrieves the value of the `action` instance variable.

  Returns:
    The value of the `action` instance variable.

### setAction

    protected final void setAction(IAction action)

  Sets the `action` instance variable to the specified value.

  Parameters:
    `action` - The new value for the `action` instance variable.

### getWorkbenchPart

    protected final IWorkbenchPart getWorkbenchPart()

  Retrieves the value of the `workbenchPart` instance variable.

  Returns:
    The value of the `workbenchPart` instance variable.

### setWorkbenchPart

    protected final void setWorkbenchPart(IWorkbenchPart workbenchPart)

  Sets the `workbenchPart` instance variable to the specified value.

  Parameters:
    `workbenchPart` - The new value for the `workbenchPart` instance variable.

### getWorkbenchWindow

    protected final IWorkbenchWindow getWorkbenchWindow()

  Retrieves the value of the `workbenchWindow` instance variable.

  Returns:
    The value of the `workbenchWindow` instance variable.

### setWorkbenchWindow

    protected final void setWorkbenchWindow(IWorkbenchWindow workbenchWindow)

  Sets the `workbenchWindow` instance variable to the specified value.

  Parameters:
    `workbenchWindow` - The new value for the `workbenchWindow` instance variable.

### getActionManager

    protected ActionManager getActionManager()

  Retrieves the action manager for this action delegate from its workbench part.

  Returns:
    The action manager for this action delegate.

### getOperationHistory

    protected IOperationHistory getOperationHistory()

  Gets the operation history for this action delegate from its action manager.

  Returns:
    the operation history

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

### run

    public void run(IAction act)

  Performs this action. This method is called when the delegating action has been triggered.

  Parameters:
    `act` - The action proxy that handles the presentation portion of the action.

### selectionChanged

    public void selectionChanged(IAction act,
                                 ISelection selection)

  Notifies this action delegate that the selection in the workbench has changed.

  Parameters:
    `act` - The action proxy that handles presentation portion of the action.
    `selection` - The current selection, or `null` if there is no selection.

### setActiveEditor

    public void setActiveEditor(IAction action,
                                IEditorPart targetEditor)

  Sets the active editor for this action delegate.

  Parameters:
    `action` - The action proxy that handles presentation portion of the action.
    `targetEditor` - The new editor target.

### setActivePart

    public void setActivePart(IAction action,
                              IWorkbenchPart targetPart)

  Sets the active part for this delegate. The active part is commonly used to get a working context for the action, such as the shell for any dialog which is needed.

  Parameters:
    `action` - The action proxy that handles presentation portion of the action.
    `targetPart` - The new part target.

### partActivated

    public void partActivated(IWorkbenchPart part)

  Notifies this action delegate that the given part has been activated.

  Specified by:
    `partActivated` in interface `IPartListener`
  Parameters:
    `part` - The part that was activated.

### partBroughtToTop

    public void partBroughtToTop(IWorkbenchPart part)

  Notifies this action delegate that the given part has been brought to the top.

  Specified by:
    `partBroughtToTop` in interface `IPartListener`
  Parameters:
    `part` - The part that was surfaced.

### partClosed

    public void partClosed(IWorkbenchPart part)

  Notifies this action delegate that the given part has been closed.

  Specified by:
    `partClosed` in interface `IPartListener`
  Parameters:
    `part` - The part that was closed.

### partDeactivated

    public void partDeactivated(IWorkbenchPart part)

  Notifies this action delegate that the given part has been deactivated.

  Specified by:
    `partDeactivated` in interface `IPartListener`
  Parameters:
    `part` - The part that was deactivated.

### partOpened

    public void partOpened(IWorkbenchPart part)

  Notifies this action delegate that the given part has been opened.

  Specified by:
    `partOpened` in interface `IPartListener`
  Parameters:
    `part` - The part that was opened.

### init

    public void init(IViewPart view)

  Initializes this action delegate with the view it will work in.

  Parameters:
    `view` - The view that provides the context for this delegate.

### dispose

    public void dispose()

  Disposes this action delegate.

### init

    public void init(IWorkbenchWindow window)

  Initializes this action delegate with the workbench window it will work in.

  Parameters:
    `window` - The window that provides the context for this delegate.

### getLabel

    public java.lang.String getLabel()

  Retrieves the label for this action delegate.

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

### isRunnable

    public boolean isRunnable()

  Retrieves a Boolean indicating whether this action delegate can be run.

  Specified by:
    `isRunnable` in interface `IActionWithProgress`
  Returns:
    `true` if the action for this delegate is enabled; `false` otherwise.

### refresh

    public void refresh()

  Description copied from interface: `IActionWithProgress`
  Refreshes various aspects of this action, such as its label and whether or not it is enabled.

  Specified by:
    `refresh` in interface `IActionWithProgress`

### run

    public void run(IProgressMonitor progressMonitor)

  Runs this action delegate.

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

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

### 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 delegate is run. Subclasses must override this method to do some work.

  Parameters:
    `progressMonitor` - A progress monitor for tracking the progress of the action's execution.

### 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
  See Also:
    `IActionWithProgress.getWorkIndicatorType()`

### 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.
  See Also:
    `IActionWithProgress.setup()`

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

### init

    public void init(IAction anAction)

  Allows the action delegate to initialize itself after being created by the proxy action. This lifecycle method is called after the action delegate has been created and before any other method of the action delegate is called.

  Parameters:
    `anAction` - the proxy action that handles the presentation portion of the action.

### runWithEvent

    public void runWithEvent(IAction anAction,
                             Event event)

  Performs this action, passing the SWT event which triggered it. This method is called by the proxy action when the action has been triggered. Implement this method to do the actual work.

  Note: This method is called instead of `run(IAction)`.

  Parameters:
    `anAction` - the action proxy that handles the presentation portion of the action
    `event` - the SWT event which triggered this action being run

Runtime

Guidelines for using Eclipse APIs.

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