Package org.eclipse.gef.tools

# Class SelectionTool

java.lang.Object
org.eclipse.gef.util.FlagSupport
org.eclipse.gef.tools.AbstractTool
org.eclipse.gef.tools.TargetingTool
org.eclipse.gef.tools.SelectionTool

All Implemented Interfaces:
  `RequestConstants`, `Tool`

Direct Known Subclasses:
  `PanningSelectionTool`

public class SelectionTool extends TargetingTool
Tool to select and manipulate figures. A selection tool is in one of three states, e.g., background selection, figure selection, handle manipulation. The different states are handled by different child tools.

## Nested Class Summary

## Nested classes/interfaces inherited from class org.eclipse.gef.tools.AbstractTool

`AbstractTool.Input`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected static final int`
`MAX_FLAG`
Max flag
`protected static final int`
`MAX_STATE`
Max state
`protected static final int`
`STATE_TRAVERSE_HANDLE`
Traverse handle state

### Fields inherited from class org.eclipse.gef.tools.AbstractTool

`MOUSE_BUTTON_ANY, MOUSE_BUTTON1, MOUSE_BUTTON2, MOUSE_BUTTON3, PROPERTY_UNLOAD_WHEN_FINISHED, STATE_ACCESSIBLE_DRAG, STATE_ACCESSIBLE_DRAG_IN_PROGRESS, STATE_DRAG, STATE_DRAG_IN_PROGRESS, STATE_INITIAL, STATE_INVALID, STATE_TERMINAL`

### Fields inherited from interface org.eclipse.gef.RequestConstants

`REQ_ADD, REQ_ALIGN, REQ_ALIGN_CHILDREN, REQ_CLONE, REQ_CONNECTION_END, REQ_CONNECTION_START, REQ_CREATE, REQ_CREATE_BENDPOINT, REQ_DELETE, REQ_DELETE_DEPENDANT, REQ_DIRECT_EDIT, REQ_MOVE, REQ_MOVE_BENDPOINT, REQ_MOVE_CHILDREN, REQ_OPEN, REQ_ORPHAN, REQ_ORPHAN_CHILDREN, REQ_RECONNECT_SOURCE, REQ_RECONNECT_TARGET, REQ_RESIZE, REQ_RESIZE_CHILDREN, REQ_SELECTION, REQ_SELECTION_HOVER`

## Constructor Summary

Constructors
Constructor
Description
`SelectionTool()`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`createHoverRequest()`
Creates the hover request (a `LocationRequest`) and sets its type to `RequestConstants.REQ_SELECTION_HOVER`.
`protected Request`
`createTargetRequest()`
Creates a `SelectionRequest` for the target request.
`void`
`deactivate()`
Deactivates the tool.
`protected void`
`eraseHoverFeedback()`
Erases the hover feedback by calling `EditPart.eraseTargetFeedback(Request)`.
`protected String`
`getCommandName()`
Returns the identifier of the command that is being sought.
`protected String`
`getDebugName()`
Returns the debug name for this tool.
`protected String`
`getDebugNameForState(int state)`
Returns a String representation of the given state for debug purposes.
`protected DragTracker`
`getDragTracker()`
Returns the current drag tracker.
`protected Request`
`getTargetHoverRequest()`
Returns the target hover request.
`protected EditPartViewer.Conditional`
`getTargetingConditional()`
Returns a new Conditional that evaluates to `true` if the queried edit part's `EditPart.isSelectable()` method returns `true`.
`protected SelectionRequest`
`getTargetRequest()`
Lazily creates and returns the request used when communicating with the target editpart.
`protected boolean`
`handleButtonDown(int button)`
If there is a `Handle` under the mouse, this method sets the drag tracker returned from the handle.
`protected boolean`
`handleButtonUp(int button)`
Resets this tool when the last button is released.
`protected boolean`
`handleCommandStackChanged()`
Called when the command stack has changed, for instance, when a delete or undo command has been executed.
`protected boolean`
`handleFocusLost()`
Sets the drag tracker to `null` and goes into the initial state when focus is lost.
`protected boolean`
`handleHover()`
Called when the mouse hovers.
`protected boolean`
`handleHoverStop()`
Called when the mouse hover stops (i.e. the mouse moves or a button is clicked).
`protected boolean`
`handleKeyDown(KeyEvent e)`
Processes key down events.
`protected boolean`
`handleKeyUp(KeyEvent e)`
If in the initial state and the viewer has a `KeyHandler`, calls `KeyHandler.keyReleased(KeyEvent)` sending it the given key event.
`protected boolean`
`handleMove()`
If in the initial state, updates the request and the mouse target and asks to show target feedback.
`boolean`
`handleNativeDragFinished(DragSourceEvent event)`
If there's a drag tracker, calls handleNativeDragFinished() on the drag tracker and then sets the drag tracker to `null`.
`boolean`
`handleNativeDragStarted(DragSourceEvent event)`
If there's a drag tracker, calls nativeDragStarted() on the drag tracker.
`protected boolean`
`handleViewerExited()`
If there's a drag tracker, sets it to `null` and then sets this tool's state to the initial state.
`void`
`keyDown(KeyEvent evt, EditPartViewer viewer)`
Forwards the key down event to the drag tracker, if one exists.
`void`
`keyUp(KeyEvent evt, EditPartViewer viewer)`
Forwards the key up event to the drag tracker, if one exists.
`void`
`mouseDoubleClick(MouseEvent e, EditPartViewer viewer)`
Forwards the mouse double clicked event to the drag tracker, if one exists.
`void`
`mouseDown(MouseEvent e, EditPartViewer viewer)`
Forwards the mouse down event to the drag tracker, if one exists.
`void`
`mouseDrag(MouseEvent e, EditPartViewer viewer)`
Forwards the mouse drag event to the drag tracker, if one exists.
`void`
`mouseHover(MouseEvent me, EditPartViewer viewer)`
Forwards the mouse hover event to the drag tracker, if one exists.
`void`
`mouseMove(MouseEvent me, EditPartViewer viewer)`
Forwards the mouse move event to the drag tracker, if one exists.
`void`
`mouseUp(MouseEvent e, EditPartViewer viewer)`
Forwards the mouse up event to the drag tracker, if one exists.
`void`
`mouseWheelScrolled(Event event, EditPartViewer viewer)`
Delegates the scrolling to the DragTracker (if there is one).
`protected void`
`refreshCursor()`
If there is a drag tracker, this method does nothing so that the drag tracker can take care of the cursor.
`void`
`setDragTracker(DragTracker newDragTracker)`
Sets the drag tracker for this SelectionTool.
`protected void`
`showHoverFeedback()`
Asks the target edit part (if there is one) to show hover feedback via `EditPart.showTargetFeedback(Request)` with a hover request.
`protected void`
`updateHoverRequest()`
Updates the location of the hover request.
`protected void`
`updateTargetRequest()`
Sets the modifiers , type and location of the target request (which is a `SelectionRequest`) and then calls `updateHoverRequest()`.

### Methods inherited from class org.eclipse.gef.tools.TargetingTool

`doAutoexpose, eraseTargetFeedback, getAutoexposeHelper, getCommand, getDirection, getExclusionSet, getTargetEditPart, handleAutoexpose, handleEnteredEditPart, handleExitingEditPart, handleInvalidInput, handleLeavingEditPart, isShowingTargetFeedback, isTargetLocked, lockTargetEditPart, resetFlags, resetHover, setAutoexposeHelper, setRefreshRate, setTargetEditPart, setTargetRequest, showTargetFeedback, unlockTargetEditPart, updateAutoexposeHelper, updateTargetUnderMouse`

### Methods inherited from class org.eclipse.gef.tools.AbstractTool

`acceptArrowKey, accGetStep, accStepIncrement, accStepReset, activate, addFeedback, applyProperty, calculateCursor, commitDrag, createOperationSet, debug, executeCommand, executeCurrentCommand, focusGained, focusLost, getCurrentCommand, getCurrentInput, getCurrentViewer, getDefaultCursor, getDisabledCursor, getDomain, getDragMoveDelta, getLocation, getOperationSet, getStartLocation, getState, handleDoubleClick, handleDrag, handleDragInProgress, handleDragStarted, handleFinished, handleFocusGained, handleKeyTraversed, handleViewerEntered, isActive, isHoverActive, isInState, isViewerImportant, keyTraversed, movedPastThreshold, nativeDragFinished, nativeDragStarted, performViewerMouseWheel, placeMouseInViewer, reactivate, releaseToolCapture, removeFeedback, setCurrentCommand, setCursor, setDefaultCursor, setDisabledCursor, setEditDomain, setHoverActive, setProperties, setStartLocation, setState, setToolCapture, setUnloadWhenFinished, setViewer, stateTransition, unloadWhenFinished, viewerEntered, viewerExited`

### Methods inherited from class org.eclipse.gef.util.FlagSupport

`getFlag, setFlag`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### MAX_FLAG

protected static final int MAX_FLAG
Max flag

See Also:
  - Constant Field Values

### STATE_TRAVERSE_HANDLE

protected static final int STATE_TRAVERSE_HANDLE
Traverse handle state

See Also:
  - Constant Field Values

### MAX_STATE

protected static final int MAX_STATE
Max state

See Also:
  - Constant Field Values

## Constructor Details

### SelectionTool

public SelectionTool()

## Method Details

### createHoverRequest

protected void createHoverRequest()
Creates the hover request (a `LocationRequest`) and sets its type to `RequestConstants.REQ_SELECTION_HOVER`.

### createTargetRequest

protected Request createTargetRequest()
Creates a `SelectionRequest` for the target request.

Overrides:
  `createTargetRequest` in class `TargetingTool`
Returns:
  the new target request
See Also:
  - `TargetingTool.createTargetRequest()`

### deactivate

public void deactivate()
Deactivates the tool. This method is called whenever the user switches to another tool. Use this method to do some clean-up when the tool is switched. Sets the drag tracker to `null`.

Specified by:
  `deactivate` in interface `Tool`
Overrides:
  `deactivate` in class `TargetingTool`
See Also:
  - `Tool.deactivate()`

### eraseHoverFeedback

protected void eraseHoverFeedback()
Erases the hover feedback by calling `EditPart.eraseTargetFeedback(Request)`.

### getCommandName

protected String getCommandName()
Description copied from class: `AbstractTool`
Returns the identifier of the command that is being sought. This name is also the named that will be logged in the debug view.

Specified by:
  `getCommandName` in class `AbstractTool`
Returns:
  the identifier for the command
See Also:
  - `AbstractTool.getCommandName()`

### getDebugName

protected String getDebugName()
Description copied from class: `AbstractTool`
Returns the debug name for this tool.

Overrides:
  `getDebugName` in class `AbstractTool`
Returns:
  the debug name
See Also:
  - `AbstractTool.getDebugName()`

### getDragTracker

protected DragTracker getDragTracker()
Returns the current drag tracker.

Returns:
  the drag tracker

### getTargetingConditional

protected EditPartViewer.Conditional getTargetingConditional()
Returns a new Conditional that evaluates to `true` if the queried edit part's `EditPart.isSelectable()` method returns `true`.

Overrides:
  `getTargetingConditional` in class `TargetingTool`
Returns:
  the targeting conditional
See Also:
  - `TargetingTool.getTargetingConditional()`

### getTargetRequest

protected SelectionRequest getTargetRequest()
Description copied from class: `TargetingTool`
Lazily creates and returns the request used when communicating with the target editpart.

Overrides:
  `getTargetRequest` in class `TargetingTool`
Returns:
  the target request
Since:
  3.21

### getTargetHoverRequest

protected Request getTargetHoverRequest()
Returns the target hover request. If `null`, it will be created via `createHoverRequest()`.

Returns:
  the hover request

### handleButtonDown

protected boolean handleButtonDown(int button)
If there is a `Handle` under the mouse, this method sets the drag tracker returned from the handle. If there's an `EditPart` under the mouse, this method sets the drag tracker returned from the edit part.

Overrides:
  `handleButtonDown` in class `AbstractTool`
Parameters:
  `button` - which button went down
Returns:
  `true` if the buttonDown was handled
See Also:
  - `AbstractTool.handleButtonDown(int)`

### handleButtonUp

protected boolean handleButtonUp(int button)
Resets this tool when the last button is released.

Overrides:
  `handleButtonUp` in class `AbstractTool`
Parameters:
  `button` - the button being released
Returns:
  `true` if the button up was handled
See Also:
  - `AbstractTool.handleButtonUp(int)`

### handleCommandStackChanged

protected boolean handleCommandStackChanged()
Description copied from class: `AbstractTool`
Called when the command stack has changed, for instance, when a delete or undo command has been executed. By default, state is set to `STATE_INVALID` and handleInvalidInput is called. Subclasses may override this method to change what happens when the command stack changes. Returning `true` indicates that the change was handled in some way.

Overrides:
  `handleCommandStackChanged` in class `AbstractTool`
Returns:
  `true` if the change was handled in some way
See Also:
  - `AbstractTool.handleCommandStackChanged()`

### handleFocusLost

protected boolean handleFocusLost()
Sets the drag tracker to `null` and goes into the initial state when focus is lost.

Overrides:
  `handleFocusLost` in class `AbstractTool`
Returns:
  `true` if the event was handled
See Also:
  - `AbstractTool.handleFocusLost()`

### handleHover

protected boolean handleHover()
Called when the mouse hovers. Calls `showHoverFeedback()`.

Overrides:
  `handleHover` in class `AbstractTool`
Returns:
  `true` if the hover was handled
See Also:
  - `AbstractTool.handleHover()`

### handleHoverStop

protected boolean handleHoverStop()
Called when the mouse hover stops (i.e. the mouse moves or a button is clicked). Calls `eraseHoverFeedback()`.

Overrides:
  `handleHoverStop` in class `TargetingTool`
Returns:
  `true` if the hover stop is processed in some way
See Also:
  - `TargetingTool.handleHoverStop()`

### handleKeyDown

protected boolean handleKeyDown(KeyEvent e)
Processes key down events. Specifically, arrow keys for moving edit parts, the ESC key for aborting a drag, the period '.' key for traversing handles, and the ENTER key for committing a drag. If none of these keys were pressed and the current viewer has a `KeyHandler`, it calls `KeyHandler.keyPressed(KeyEvent)`.

Overrides:
  `handleKeyDown` in class `AbstractTool`
Parameters:
  `e` - the key event
Returns:
  `true` if the key down was handled.
See Also:
  - `AbstractTool.handleKeyDown(KeyEvent)`

### handleKeyUp

protected boolean handleKeyUp(KeyEvent e)
If in the initial state and the viewer has a `KeyHandler`, calls `KeyHandler.keyReleased(KeyEvent)` sending it the given key event.

Overrides:
  `handleKeyUp` in class `AbstractTool`
Parameters:
  `e` - the key event
Returns:
  `true` if the event was handled
See Also:
  - `AbstractTool.handleKeyUp(KeyEvent)`

### handleMove

protected boolean handleMove()
If in the initial state, updates the request and the mouse target and asks to show target feedback. If in the traverse handle state, finds the next handle, moves the mouse cursor to that handle, and gets a drag tracker from the handle.

Overrides:
  `handleMove` in class `AbstractTool`
Returns:
  `true` if the mouse move was handled
See Also:
  - `AbstractTool.handleMove()`

### handleNativeDragFinished

public boolean handleNativeDragFinished(DragSourceEvent event)
If there's a drag tracker, calls handleNativeDragFinished() on the drag tracker and then sets the drag tracker to `null`.

Overrides:
  `handleNativeDragFinished` in class `AbstractTool`
Parameters:
  `event` - the drag event
Returns:
  `true` if the native drag finished was handled
See Also:
  - `AbstractTool.handleNativeDragFinished(DragSourceEvent)`

### handleNativeDragStarted

public boolean handleNativeDragStarted(DragSourceEvent event)
If there's a drag tracker, calls nativeDragStarted() on the drag tracker.

Overrides:
  `handleNativeDragStarted` in class `AbstractTool`
Parameters:
  `event` - the drag event
Returns:
  `true` if the native drag start was handled
See Also:
  - `AbstractTool.handleNativeDragStarted(DragSourceEvent)`

### handleViewerExited

protected boolean handleViewerExited()
If there's a drag tracker, sets it to `null` and then sets this tool's state to the initial state.

Overrides:
  `handleViewerExited` in class `TargetingTool`
Returns:
  `true` if the viewer exited was handled
See Also:
  - `AbstractTool.handleViewerExited()`

### keyDown

public void keyDown(KeyEvent evt, EditPartViewer viewer)
Forwards the key down event to the drag tracker, if one exists.

Specified by:
  `keyDown` in interface `Tool`
Overrides:
  `keyDown` in class `AbstractTool`
Parameters:
  `evt` - the key event
  `viewer` - the originating viewer
See Also:
  - `Tool.keyDown(KeyEvent, org.eclipse.gef.EditPartViewer)`

### keyUp

public void keyUp(KeyEvent evt, EditPartViewer viewer)
Forwards the key up event to the drag tracker, if one exists.

Specified by:
  `keyUp` in interface `Tool`
Overrides:
  `keyUp` in class `AbstractTool`
Parameters:
  `evt` - the key event
  `viewer` - the originating viewer
See Also:
  - `Tool.keyUp(KeyEvent, org.eclipse.gef.EditPartViewer)`

### mouseDown

public void mouseDown(MouseEvent e, EditPartViewer viewer)
Forwards the mouse down event to the drag tracker, if one exists.

Specified by:
  `mouseDown` in interface `Tool`
Overrides:
  `mouseDown` in class `AbstractTool`
Parameters:
  `e` - the mouse event
  `viewer` - the originating viewer
See Also:
  - `Tool.mouseDown(MouseEvent, org.eclipse.gef.EditPartViewer)`

### mouseDoubleClick

public void mouseDoubleClick(MouseEvent e, EditPartViewer viewer)
Forwards the mouse double clicked event to the drag tracker, if one exists.

Specified by:
  `mouseDoubleClick` in interface `Tool`
Overrides:
  `mouseDoubleClick` in class `AbstractTool`
Parameters:
  `e` - the mouse event
  `viewer` - the originating viewer
See Also:
  - `Tool.mouseDoubleClick(MouseEvent, org.eclipse.gef.EditPartViewer)`

### mouseDrag

public void mouseDrag(MouseEvent e, EditPartViewer viewer)
Forwards the mouse drag event to the drag tracker, if one exists.

Specified by:
  `mouseDrag` in interface `Tool`
Overrides:
  `mouseDrag` in class `AbstractTool`
Parameters:
  `e` - the mouse event
  `viewer` - the originating viewer
See Also:
  - `Tool.mouseDrag(MouseEvent, org.eclipse.gef.EditPartViewer)`

### mouseHover

public void mouseHover(MouseEvent me, EditPartViewer viewer)
Forwards the mouse hover event to the drag tracker, if one exists.

Specified by:
  `mouseHover` in interface `Tool`
Overrides:
  `mouseHover` in class `AbstractTool`
Parameters:
  `me` - the mouse event
  `viewer` - the originating viewer
See Also:
  - `Tool.mouseHover(MouseEvent, org.eclipse.gef.EditPartViewer)`

### mouseMove

public void mouseMove(MouseEvent me, EditPartViewer viewer)
Forwards the mouse move event to the drag tracker, if one exists.

Specified by:
  `mouseMove` in interface `Tool`
Overrides:
  `mouseMove` in class `AbstractTool`
Parameters:
  `me` - the mouse event
  `viewer` - the originating viewer
See Also:
  - `Tool.mouseMove(MouseEvent, org.eclipse.gef.EditPartViewer)`

### mouseUp

public void mouseUp(MouseEvent e, EditPartViewer viewer)
Forwards the mouse up event to the drag tracker, if one exists.

Specified by:
  `mouseUp` in interface `Tool`
Overrides:
  `mouseUp` in class `AbstractTool`
Parameters:
  `e` - the mouse event
  `viewer` - the originating viewer
See Also:
  - `Tool.mouseUp(MouseEvent, org.eclipse.gef.EditPartViewer)`

### mouseWheelScrolled

public void mouseWheelScrolled(Event event, EditPartViewer viewer)
Delegates the scrolling to the DragTracker (if there is one). If not, invokes the super method.

Specified by:
  `mouseWheelScrolled` in interface `Tool`
Overrides:
  `mouseWheelScrolled` in class `AbstractTool`
Parameters:
  `event` - the SWT scroll event
  `viewer` - the originating viewer
See Also:
  - `Tool.mouseWheelScrolled(org.eclipse.swt.widgets.Event, org.eclipse.gef.EditPartViewer)`

### refreshCursor

protected void refreshCursor()
If there is a drag tracker, this method does nothing so that the drag tracker can take care of the cursor. Otherwise, calls `super`.

Overrides:
  `refreshCursor` in class `AbstractTool`
See Also:
  - `AbstractTool.refreshCursor()`

### setDragTracker

public void setDragTracker(DragTracker newDragTracker)
Sets the drag tracker for this SelectionTool. If the current drag tracker is not `null`, this method deactivates it. If the new drag tracker is not `null`, this method will activate it and set the `EditDomain` and `EditPartViewer`.

Parameters:
  `newDragTracker` - the new drag tracker

### showHoverFeedback

protected void showHoverFeedback()
Asks the target edit part (if there is one) to show hover feedback via `EditPart.showTargetFeedback(Request)` with a hover request.

### updateHoverRequest

protected void updateHoverRequest()
Updates the location of the hover request.

### updateTargetRequest

protected void updateTargetRequest()
Sets the modifiers , type and location of the target request (which is a `SelectionRequest`) and then calls `updateHoverRequest()`.

Overrides:
  `updateTargetRequest` in class `TargetingTool`
See Also:
  - `TargetingTool.updateTargetRequest()`

### getDebugNameForState

protected String getDebugNameForState(int state)
Description copied from class: `AbstractTool`
Returns a String representation of the given state for debug purposes.

Overrides:
  `getDebugNameForState` in class `AbstractTool`
Parameters:
  `state` - the state
Returns:
  the string for the given state
See Also:
  - `AbstractTool.getDebugNameForState(int)`