public abstract class BaseSelectionListenerAction extends Action implements ISelectionChangedListener
getStructuredSelection
) 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 eventAS_CHECK_BOX, AS_DROP_DOWN_MENU, AS_PUSH_BUTTON, AS_RADIO_BUTTON, AS_UNSPECIFIED, CHECKED, DESCRIPTION, ENABLED, HANDLED, IMAGE, RESULT, TEXT, TOOL_TIP_TEXT
Modifier | Constructor and Description |
---|---|
protected |
BaseSelectionListenerAction(String text)
Creates a new action with the given text.
|
Modifier and Type | Method and 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 this
IAction method ignores
the event argument, and simply calls run() . |
void |
selectionChanged(IStructuredSelection selection)
Notifies this action that the given structured selection has changed.
|
void |
selectionChanged(SelectionChangedEvent event)
The
BaseSelectionListenerAction implementation of this
ISelectionChangedListener method calls
selectionChanged(IStructuredSelection) assuming the selection is
a structured one. |
protected boolean |
updateSelection(IStructuredSelection selection)
Updates this action in response to the given selection.
|
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
addPropertyChangeListener, firePropertyChange, firePropertyChange, removePropertyChangeListener
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addPropertyChangeListener, removePropertyChangeListener
protected BaseSelectionListenerAction(String text)
text
- the string used as the text for the action,
or null
if there is no textprotected void clearCache()
The BaseSelectionListenerAction
implementation of this method
does nothing. Subclasses may override.
public IStructuredSelection getStructuredSelection()
public final void selectionChanged(IStructuredSelection selection)
The BaseSelectionListenerAction
implementation of this method
records the given selection for future reference and calls
updateSelection
, updating the enable state of this action
based on the outcome. Subclasses should override updateSelection
to react to selection changes.
selection
- the new selectionpublic final void selectionChanged(SelectionChangedEvent event)
BaseSelectionListenerAction
implementation of this
ISelectionChangedListener
method calls
selectionChanged(IStructuredSelection)
assuming the selection is
a structured one. Subclasses should override the updateSelection
method to react to selection changes.selectionChanged
in interface ISelectionChangedListener
event
- event object describing the changeprotected boolean updateSelection(IStructuredSelection selection)
The BaseSelectionListenerAction
implementation of this method
returns true
. Subclasses may extend to react to selection
changes; however, if the super method returns false
, the
overriding method must also return false
.
selection
- the new selectiontrue
if the action should be enabled for this selection,
and false
otherwisepublic void runWithEvent(Event event)
Action
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.runWithEvent
in interface IAction
runWithEvent
in class Action
event
- the SWT event which triggered this action being run
Copyright (c) 2000, 2013 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.