Class BaseSelectionListenerAction
- java.lang.Object
-
- org.eclipse.core.commands.common.EventManager
-
- org.eclipse.jface.action.AbstractAction
-
- org.eclipse.jface.action.Action
-
- org.eclipse.ui.actions.BaseSelectionListenerAction
-
- All Implemented Interfaces:
IAction
,ISelectionChangedListener
- Direct Known Subclasses:
ExportResourcesAction
,ImportResourcesAction
,ModelParticipantAction
,SelectionListenerAction
,SynchronizeModelAction
public abstract class BaseSelectionListenerAction extends Action implements ISelectionChangedListener
The abstract superclass for actions that listen to selection change events. This implementation tracks the current selection (seegetStructuredSelection
) and provides a convenient place to monitor selection changes that could affect the availability of the action.Subclasses must implement the following
IAction
method:run
- to do the action's work
Subclasses may extend the
updateSelection
method to update the action determine its availability based on the current selection.The object instantiating the subclass is responsible for registering the instance with a selection provider. Alternatively, the object can notify the subclass instance directly of a selection change using the methods:
selectionChanged(IStructuredSelection)
- passing the selectionselectionChanged(ISelectionChangedEvent)
- passing the selection change event
- Since:
- 3.0
-
-
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
Constructors Modifier Constructor Description protected
BaseSelectionListenerAction(String text)
Creates a new action with the given text.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
clearCache()
Clears any cached state associated with the selection.IStructuredSelection
getStructuredSelection()
Returns the current structured selection in the workbench, or an empty selection if nothing is selected or if selection does not include objects (for example, raw text).void
runWithEvent(Event event)
The default implementation of thisIAction
method ignores the event argument, and simply callsrun()
.void
selectionChanged(IStructuredSelection selection)
Notifies this action that the given structured selection has changed.void
selectionChanged(SelectionChangedEvent event)
TheBaseSelectionListenerAction
implementation of thisISelectionChangedListener
method callsselectionChanged(IStructuredSelection)
assuming the selection is a structured one.protected boolean
updateSelection(IStructuredSelection selection)
Updates this action in response to the given selection.-
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, run, 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
-
-
-
-
Constructor Detail
-
BaseSelectionListenerAction
protected BaseSelectionListenerAction(String text)
Creates a new action with the given text.- Parameters:
text
- the string used as the text for the action, ornull
if there is no text
-
-
Method Detail
-
clearCache
protected void clearCache()
Clears any cached state associated with the selection. Called when the selection changes.The
BaseSelectionListenerAction
implementation of this method does nothing. Subclasses may override.
-
getStructuredSelection
public IStructuredSelection getStructuredSelection()
Returns the current structured selection in the workbench, or an empty selection if nothing is selected or if selection does not include objects (for example, raw text).- Returns:
- the current structured selection in the workbench
-
selectionChanged
public final void selectionChanged(IStructuredSelection selection)
Notifies this action that the given structured selection has changed.The
BaseSelectionListenerAction
implementation of this method records the given selection for future reference and callsupdateSelection
, updating the enable state of this action based on the outcome. Subclasses should overrideupdateSelection
to react to selection changes.- Parameters:
selection
- the new selection
-
selectionChanged
public final void selectionChanged(SelectionChangedEvent event)
TheBaseSelectionListenerAction
implementation of thisISelectionChangedListener
method callsselectionChanged(IStructuredSelection)
assuming the selection is a structured one. Subclasses should override theupdateSelection
method to react to selection changes.- Specified by:
selectionChanged
in interfaceISelectionChangedListener
- Parameters:
event
- event object describing the change
-
updateSelection
protected boolean updateSelection(IStructuredSelection selection)
Updates this action in response to the given selection.The
BaseSelectionListenerAction
implementation of this method returnstrue
. Subclasses may extend to react to selection changes; however, if the super method returnsfalse
, the overriding method must also returnfalse
.- Parameters:
selection
- the new selection- Returns:
true
if the action should be enabled for this selection, andfalse
otherwise
-
runWithEvent
public void runWithEvent(Event event)
Description copied from class:Action
The default implementation of thisIAction
method ignores the event argument, and simply callsrun()
. Subclasses should override this method if they need information from the triggering event, or overriderun()
if not.- Specified by:
runWithEvent
in interfaceIAction
- Overrides:
runWithEvent
in classAction
- Parameters:
event
- the SWT event which triggered this action being run- See Also:
How radio buttons are handled
,How check boxes are handled
-
-