Class PluginAction

All Implemented Interfaces:
EventListener, IAction, ISelectionChangedListener, INullSelectionListener, IPluginContribution, ISelectionListener
Direct Known Subclasses:
ObjectPluginAction, PartPluginAction, WWinPluginAction

public abstract class PluginAction extends Action implements ISelectionListener, ISelectionChangedListener, INullSelectionListener, IPluginContribution
A PluginAction is a proxy for an action extension. At startup we read the registry and create a PluginAction for each action extension. This plugin action looks like the real action ( label, icon, etc ) and acts as a proxy for the action until invoked. At that point the proxy will instantiate the real action and delegate the run method to the real action. This makes it possible to load the action extension lazily. Occasionally the class will ask if it is OK to load the delegate (on selection changes). If the plugin containing the action extension has been loaded then the action extension itself will be instantiated.
  • Constructor Details

    • PluginAction

      public PluginAction(IConfigurationElement actionElement, String id, int style)
      PluginAction constructor.
      Parameters:
      actionElement - the element
      id - the identifier
      style - the style bits
  • Method Details

    • createDelegate

      protected final void createDelegate()
      Creates the delegate and refreshes its enablement.
    • validateDelegate

      protected IActionDelegate validateDelegate(Object obj) throws WorkbenchException
      Validates the object is a delegate of the expected type. Subclasses can override to check for specific delegate types.

      Note: Calls to the object are not allowed during this method.

      Parameters:
      obj - a possible action delegate implementation
      Returns:
      the IActionDelegate implementation for the object
      Throws:
      WorkbenchException - if not of the expected delegate type
    • initDelegate

      protected void initDelegate()
      Initialize the action delegate by calling its lifecycle method. Subclasses may override but must call this implementation first.
    • getDelegate

      protected IActionDelegate getDelegate()
      Returns the action delegate if created. Can be null if the delegate is not created yet or if previous delegate creation failed.
    • isOkToCreateDelegate

      protected boolean isOkToCreateDelegate()
      Returns true if the declaring plugin has been loaded and there is no need to delay creating the delegate any more.
    • refreshEnablement

      protected void refreshEnablement()
      Refresh the action enablement.
    • run

      public void run()
      Description copied from class: Action
      The default implementation of this IAction method does nothing. Subclasses should override this method if they do not need information from the triggering event, or override runWithEvent(Event) if they do.
      Specified by:
      run in interface IAction
      Overrides:
      run in class Action
      See Also:
    • runWithEvent

      public void runWithEvent(Event event)
      Description copied from class: Action
      The default implementation of this IAction method ignores the event argument, and simply calls run(). Subclasses should override this method if they need information from the triggering event, or override run() if not.
      Specified by:
      runWithEvent in interface IAction
      Overrides:
      runWithEvent in class Action
      Parameters:
      event - the SWT event which triggered this action being run
      See Also:
    • selectionChanged

      public void selectionChanged(ISelection newSelection)
      Handles selection change. If rule-based enabled is defined, it will be first to call it. If the delegate is loaded, it will also be given a chance.
      Parameters:
      newSelection - the new selection
    • selectionChanged

      public void selectionChanged(SelectionChangedEvent event)
      The SelectionChangedEventAction implementation of this ISelectionChangedListener method calls selectionChanged(IStructuredSelection) when the selection is a structured one.
      Specified by:
      selectionChanged in interface ISelectionChangedListener
      Parameters:
      event - event object describing the change
    • selectionChanged

      public void selectionChanged(IWorkbenchPart part, ISelection sel)
      The SelectionChangedEventAction implementation of this ISelectionListener method calls selectionChanged(IStructuredSelection) when the selection is a structured one. Subclasses may extend this method to react to the change.
      Specified by:
      selectionChanged in interface ISelectionListener
      Parameters:
      part - the workbench part containing the selection
      sel - the current selection. This may be null if INullSelectionListener is implemented.
      See Also:
    • getSelection

      public ISelection getSelection()
      For testing purposes only.
      Returns:
      the selection
      Since:
      3.1
    • getOverrideActionId

      public String getOverrideActionId()
      Returns the action identifier this action overrides. Default implementation returns null.
      Returns:
      the action identifier to override or null
    • getConfigElement

      protected IConfigurationElement getConfigElement()
      Returns:
      the IConfigurationElement used to create this PluginAction.
      Since:
      3.0
    • getLocalId

      public String getLocalId()
      Specified by:
      getLocalId in interface IPluginContribution
      Returns:
      the local id of the contribution. Must not be null. This should correspond to the extension-specific identifier for a given contribution.
    • getPluginId

      public String getPluginId()
      Specified by:
      getPluginId in interface IPluginContribution
      Returns:
      the id of the originating plugin. Can be null if this contribution did not originate from a plugin.
    • disposeDelegate

      public void disposeDelegate()
      Disposes the delegate, if created.
      Since:
      3.1
    • dispose

      public void dispose()
      Disposes this plugin action.
      Since:
      3.1
    • getMenuCreator

      public IMenuCreator getMenuCreator()
      Description copied from interface: IAction
      Returns the menu creator for this action.
      Specified by:
      getMenuCreator in interface IAction
      Overrides:
      getMenuCreator in class Action
      Returns:
      the menu creator, or null if none