Package org.eclipse.ui.actions
Class SelectionListenerAction
- java.lang.Object
-
- org.eclipse.core.commands.common.EventManager
-
- org.eclipse.jface.action.AbstractAction
-
- org.eclipse.jface.action.Action
-
- org.eclipse.ui.actions.BaseSelectionListenerAction
-
- org.eclipse.ui.actions.SelectionListenerAction
-
- All Implemented Interfaces:
IAction,ISelectionChangedListener
- Direct Known Subclasses:
AddBookmarkAction,AddTaskAction,CopyProjectAction,CopyResourceAction,CreateFileAction,CreateFolderAction,DeleteResourceAction,OpenSystemEditorAction,WorkspaceAction
public abstract class SelectionListenerAction extends BaseSelectionListenerAction
The abstract superclass for resource-based 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
IActionmethod:run- to do the action's work
Subclasses may extend the
updateSelectionmethod 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
-
-
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 protectedSelectionListenerAction(String text)Creates a new action with the given text.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclearCache()TheSelectionListenerActionimplementation of thisBaseSelectionListenerActionmethod clears the cached resources and non-resources.protected List<?>getSelectedNonResources()Returns the elements in the current selection that are notIResources.protected List<? extends IResource>getSelectedResources()Returns the elements in the current selection that areIResources.protected booleanresourceIsType(IResource resource, int resourceMask)Returns whether the type of the given resource is among those in the given resource type mask.protected booleanselectionIsOfType(int resourceMask)Returns whether the current selection consists entirely of resources whose types are among those in the given resource type mask.-
Methods inherited from class org.eclipse.ui.actions.BaseSelectionListenerAction
getStructuredSelection, runWithEvent, selectionChanged, selectionChanged, updateSelection
-
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
-
SelectionListenerAction
protected SelectionListenerAction(String text)
Creates a new action with the given text.- Parameters:
text- the string used as the text for the action, ornullif there is no text
-
-
Method Detail
-
clearCache
protected void clearCache()
TheSelectionListenerActionimplementation of thisBaseSelectionListenerActionmethod clears the cached resources and non-resources.- Overrides:
clearCachein classBaseSelectionListenerAction
-
getSelectedNonResources
protected List<?> getSelectedNonResources()
Returns the elements in the current selection that are notIResources.- Returns:
- list of elements (element type:
Object)
-
getSelectedResources
protected List<? extends IResource> getSelectedResources()
Returns the elements in the current selection that areIResources.- Returns:
- list of resource elements (element type:
IResource)
-
resourceIsType
protected boolean resourceIsType(IResource resource, int resourceMask)
Returns whether the type of the given resource is among those in the given resource type mask.- Parameters:
resource- the resourceresourceMask- a bitwise OR of resource types:IResource.{FILE,FOLDER,PROJECT,ROOT}- Returns:
trueif the resource type matches, andfalseotherwise- See Also:
IResource
-
selectionIsOfType
protected boolean selectionIsOfType(int resourceMask)
Returns whether the current selection consists entirely of resources whose types are among those in the given resource type mask.- Parameters:
resourceMask- a bitwise OR of resource types:IResource.{FILE,FOLDER,PROJECT,ROOT}- Returns:
trueif all resources in the current selection are of the specified types or if the current selection is empty, andfalseif some elements are resources of a different type or not resources- See Also:
IResource
-
-