Eclipse Platform
Release 3.1

org.eclipse.ui.actions
Class SelectionListenerAction

java.lang.Object
  extended byorg.eclipse.jface.action.Action
      extended byorg.eclipse.ui.actions.BaseSelectionListenerAction
          extended byorg.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 (see 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:

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:


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
protected SelectionListenerAction(String text)
          Creates a new action with the given text.
 
Method Summary
protected  void clearCache()
          The SelectionListenerAction implementation of this BaseSelectionListenerAction method clears the cached resources and non-resources.
protected  List getSelectedNonResources()
          Returns the elements in the current selection that are not IResources.
protected  List getSelectedResources()
          Returns the elements in the current selection that are IResources.
protected  boolean resourceIsType(IResource resource, int resourceMask)
          Returns whether the type of the given resource is among those in the given resource type mask.
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.
 
Methods inherited from class org.eclipse.ui.actions.BaseSelectionListenerAction
getStructuredSelection, runWithEvent, selectionChanged, selectionChanged, updateSelection
 
Methods inherited from class org.eclipse.jface.action.Action
addPropertyChangeListener, convertAccelerator, convertAccelerator, findKeyCode, findKeyString, findModifier, findModifierString, firePropertyChange, firePropertyChange, getAccelerator, getActionDefinitionId, getDescription, getDisabledImageDescriptor, getHelpListener, getHoverImageDescriptor, getId, getImageDescriptor, getMenuCreator, getStyle, getText, getToolTipText, isChecked, isEnabled, isHandled, notifyResult, removeAcceleratorText, removeMnemonics, removePropertyChangeListener, run, setAccelerator, setActionDefinitionId, setChecked, setDescription, setDisabledImageDescriptor, setEnabled, setHelpListener, setHoverImageDescriptor, setId, setImageDescriptor, setMenuCreator, setText, setToolTipText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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, or null if there is no text
Method Detail

clearCache

protected void clearCache()
The SelectionListenerAction implementation of this BaseSelectionListenerAction method clears the cached resources and non-resources.

Overrides:
clearCache in class BaseSelectionListenerAction

getSelectedNonResources

protected List getSelectedNonResources()
Returns the elements in the current selection that are not IResources.

Returns:
list of elements (element type: Object)

getSelectedResources

protected List getSelectedResources()
Returns the elements in the current selection that are IResources.

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 resource
resourceMask - a bitwise OR of resource types: IResource.{FILE, FOLDER, PROJECT, ROOT}
Returns:
true if the resource type matches, and false otherwise
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:
true if all resources in the current selection are of the specified types or if the current selection is empty, and false if some elements are resources of a different type or not resources
See Also:
IResource

Eclipse Platform
Release 3.1

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2005. All rights reserved.