Runtime

## org.eclipse.gmf.runtime.diagram.ui.actions
Class DiagramAction

    java.lang.Object
      org.eclipse.core.commands.common.EventManager
          org.eclipse.jface.action.AbstractAction
              org.eclipse.jface.action.Action
                  org.eclipse.gmf.runtime.common.ui.action.AbstractActionHandler
                      org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction

All Implemented Interfaces:
  Disposable, IAction, IActionWithProgress, IDisposableAction, IOperationHistoryListener, IPropertyListener, ISelectionChangedListener

Direct Known Subclasses:
  AbstractDeleteFromAction, AlignAction, AttachShapeAction, CopyAction, CopyToImageAction, org.eclipse.gmf.runtime.diagram.ui.internal.actions.PropertyChangeAction

public abstract class DiagramAction
extends AbstractActionHandler
implements Disposable

An abstract implementation of a diagram action that follows the request-command architecture. Notice: 1) This action retargets to the active workbench part 2) This action can either be contributed programatically or through the `ControbutionItemService`.

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
`` `DiagramAction(IWorkbenchPage workbenchPage)` Constructs a new diagram action
`protected` `DiagramAction(IWorkbenchPart workbenchpart)` Constructs a new diagram action.

Method Summary
`protected boolean` `calculateEnabled()` Calculates the enblement state of the action
`protected void` `clearTargetRequest()` Sets the target request to `null`.
`protected java.util.List` `createOperationSet()` Filters the selected objects and returns only editparts that understands the request
`protected abstract Request` `createTargetRequest()` Creates a new target request
`void` `dispose()` Default implementation of dispose.
`protected void` `doRun(IProgressMonitor progressMonitor)` Performs the actual work when this action handler is run.
`protected void` `execute(Command command, IProgressMonitor progressMonitor)` Executes the given `Command`.
`protected java.util.List` `filterEditPartsMatching(java.util.List list, EditPartViewer.Conditional condition)` Filters the given list of EditParts so that the list only contains the EditParts that matches the given condition.
`protected Command` `getCommand()` Gets the associated Command with this action based on the target request
`protected Command` `getCommand(Request request)` Gets a command to execute on the operation set based on a given request
`protected java.lang.String` `getCommandLabel()` Gets an optional label for the action's executed command
`protected DiagramCommandStack` `getDiagramCommandStack()` gives access to the diagram command stack
`protected IDiagramEditDomain` `getDiagramEditDomain()` A utility method to get the `IDiagramEditDomain` from the current part if it adapts to it
`protected DiagramEditPart` `getDiagramEditPart()` A utility method to return the active `DiagramEditPart` if the current part implements `IDiagramWorkbenchPart`
`protected IDiagramGraphicalViewer` `getDiagramGraphicalViewer()` A utility method to return the active `DiagramEditPart` if the current part implements `IDiagramWorkbenchPart`
`protected IDiagramWorkbenchPart` `getDiagramWorkbenchPart()` A utility method to return the active part if it implements the `IDiagramWorkbenchPart` interface
`protected java.util.List` `getOperationSet()` Return the list of editparts considered the operation set after caching them
`protected PreferencesHint` `getPreferencesHint()` Gets the preferences hint that is to be used to find the appropriate preference store from which to retrieve diagram preference values.
`protected java.util.List` `getSelectedObjects()` A utility method to return a list of objects in the current structured selection
`protected java.util.List` `getTargetEditParts(EditPart editpart)` Given an editpart, returns a list of target editparts to the current request If no targets could be found, an empty list is returned
`protected Request` `getTargetRequest()` Gets a request to be addressed to the operation set
`protected abstract boolean` `isSelectionListener()` Does this action need to listen to selection change events?
`void` `refresh()` Refreshes various aspects of this action, such as its label and whether or not it is enabled.
`protected void` `setTargetRequest(Request targetRequest)`
`protected void` `updateTargetRequest()` updates the target request.

Methods inherited from class org.eclipse.gmf.runtime.common.ui.action.AbstractActionHandler

`contributedToPart, getActionManager, getLabel, getOperationHistory, getPartListener, getSelection, getStructuredSelection, getUndoContext, getWorkbenchPage, getWorkbenchPart, getWorkIndicatorType, handle, historyNotification, init, isDisposed, isOperationHistoryListener, isPropertyListener, isRunnable, isSetup, needsSetup, openErrorDialog, propertyChanged, run, run, runWithEvent, selectionChanged, setDisposed, setPartSelector, setSetup, setup, setWorkbenchPart`

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`

Constructor Detail

### DiagramAction

    public DiagramAction(IWorkbenchPage workbenchPage)

  Constructs a new diagram action

Parameters:
  `workbenchPage` - The workbench page associated with this action

### DiagramAction

    protected DiagramAction(IWorkbenchPart workbenchpart)

  Constructs a new diagram action. This constructor is provided just in case a derived class needs to support both the construction of a diagram action with a workbenchpart. Typically this is only when the diagram declares its own action in additional to the one registered with the action serivce.

Parameters:
  `workbenchpart` - The workbench part associated with this action

Method Detail

### dispose

    public void dispose()

  Description copied from class: `AbstractActionHandler`
  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 `Disposable`
  Overrides:
    `dispose` in class `AbstractActionHandler`

### doRun

    protected void doRun(IProgressMonitor progressMonitor)

  Description copied from class: `AbstractActionHandler`
  Performs the actual work when this action handler is run. Subclasses must override this method to do some work.

  Specified by:
    `doRun` in class `AbstractActionHandler`
  Parameters:
    `progressMonitor` - the progress monitor for tracking the progress of this action when it is run.

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

### calculateEnabled

    protected boolean calculateEnabled()

  Calculates the enblement state of the action

  Returns:
    `true` if action should be enabled, `false` otherwise

### execute

    protected final void execute(Command command,
                                 IProgressMonitor progressMonitor)

  Executes the given `Command`.

  Parameters:
    `command` - the command to execute
    `progressMonitor` - the progress monitor to use during execution

### getDiagramCommandStack

    protected DiagramCommandStack getDiagramCommandStack()

  gives access to the diagram command stack

  Returns:
    the diagram command stack

### getCommand

    protected Command getCommand()

  Gets the associated Command with this action based on the target request

  Returns:
    a command

### getCommand

    protected Command getCommand(Request request)

  Gets a command to execute on the operation set based on a given request

  Parameters:
    `request` - request to use to get the command
  Returns:
    a command

### getCommandLabel

    protected java.lang.String getCommandLabel()

  Gets an optional label for the action's executed command

  Returns:
    An optional label for the action's executed command

### getTargetRequest

    protected Request getTargetRequest()

  Gets a request to be addressed to the operation set

  Returns:
    a target request

### createTargetRequest

    protected abstract Request createTargetRequest()

  Creates a new target request

  Returns:
    the new target request

### updateTargetRequest

    protected void updateTargetRequest()

  updates the target request. Clients should call this method whenever the request is expected to be changed

### clearTargetRequest

    protected void clearTargetRequest()

  Sets the target request to `null`. This will force the creation of a new target request on the next `DiagramAction.getTargetRequest()` call.

### getSelectedObjects

    protected java.util.List getSelectedObjects()

  A utility method to return a list of objects in the current structured selection

  Returns:
    A list of objects in the current structure selection

### getOperationSet

    protected final java.util.List getOperationSet()

  Return the list of editparts considered the operation set after caching them

  Returns:
    A list of editparts conidered the operation set

### createOperationSet

    protected java.util.List createOperationSet()

  Filters the selected objects and returns only editparts that understands the request

  Returns:
    a list of editparts selected.

### getTargetEditParts

    protected java.util.List getTargetEditParts(EditPart editpart)

  Given an editpart, returns a list of target editparts to the current request If no targets could be found, an empty list is returned

  Parameters:
    `editpart` - The given editpart
  Returns:
    a list of target editparts, or Empty list if none

### getDiagramEditDomain

    protected IDiagramEditDomain getDiagramEditDomain()

  A utility method to get the `IDiagramEditDomain` from the current part if it adapts to it

  Returns:
    The diagram edit domain adapter if it exists; `null` otherwise

### getDiagramWorkbenchPart

    protected IDiagramWorkbenchPart getDiagramWorkbenchPart()

  A utility method to return the active part if it implements the `IDiagramWorkbenchPart` interface

  Returns:
    The current part if it implements `IDiagramWorkbenchPart`; `null` otherwise

### getDiagramEditPart

    protected DiagramEditPart getDiagramEditPart()

  A utility method to return the active `DiagramEditPart` if the current part implements `IDiagramWorkbenchPart`

  Returns:
    The current diagram if the parts implements `IDiagramWorkbenchPart`; `null` otherwise

### getDiagramGraphicalViewer

    protected IDiagramGraphicalViewer getDiagramGraphicalViewer()

  A utility method to return the active `DiagramEditPart` if the current part implements `IDiagramWorkbenchPart`

  Returns:
    The current diagram if the parts implements `IDiagramWorkbenchPart`; `null` otherwise

### filterEditPartsMatching

    protected java.util.List filterEditPartsMatching(java.util.List list,
                                                     EditPartViewer.Conditional condition)

  Filters the given list of EditParts so that the list only contains the EditParts that matches the given condition.

  Parameters:
    `list` - the list of edit parts to filter
    `condition` - the condition
  Returns:
    a modified list containing those editparts that matched the condition

### isSelectionListener

    protected abstract boolean isSelectionListener()

  Does this action need to listen to selection change events? If the enablement state of the context menu or the operation set depends on what is selected in a diagram, then this needs to return true. If this action targets the diagram only, then it should return false.

  Actions that are only contributed to the popup menu (and not toolbar or main menus) will not receive selection events at all. The refresh() method will be called when the context menu is about to show.

  Overrides:
    `isSelectionListener` in class `AbstractActionHandler`
  Returns:
    `true` if this action handler is interested; `false` otherwise.

### setTargetRequest

    protected void setTargetRequest(Request targetRequest)

  Parameters:
    `targetRequest` - The targetRequest to set.

### getPreferencesHint

    protected PreferencesHint getPreferencesHint()

  Gets the preferences hint that is to be used to find the appropriate preference store from which to retrieve diagram preference values. The preference hint is mapped to a preference store in the preference registry <@link DiagramPreferencesRegistry>.

  Returns:
    the preferences hint

Runtime

Guidelines for using Eclipse APIs.

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