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
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
FieldsModifier and TypeFieldDescriptionprotected static final int
Max flagprotected static final int
Max stateprotected static final int
Traverse handle stateFields 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Creates the hover request (aLocationRequest
) and sets its type toRequestConstants.REQ_SELECTION_HOVER
.protected Request
Creates aSelectionRequest
for the target request.void
Deactivates the tool.protected void
Erases the hover feedback by callingEditPart.eraseTargetFeedback(Request)
.protected String
Returns the identifier of the command that is being sought.protected String
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
Returns the current drag tracker.protected Request
Returns the target hover request.protected EditPartViewer.Conditional
Returns a new Conditional that evaluates totrue
if the queried edit part'sEditPart.isSelectable()
method returnstrue
.protected boolean
handleButtonDown
(int button) If there is aHandle
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
Called when the command stack has changed, for instance, when a delete or undo command has been executed.protected boolean
Sets the drag tracker tonull
and goes into the initial state when focus is lost.protected boolean
Called when the mouse hovers.protected boolean
Called when the mouse hover stops (i.e. the mouse moves or a button is clicked).protected boolean
Processes key down events.protected boolean
If in the initial state and the viewer has aKeyHandler
, callsKeyHandler.keyReleased(KeyEvent)
sending it the given key event.protected boolean
If in the initial state, updates the request and the mouse target and asks to show target feedback.boolean
If there's a drag tracker, calls handleNativeDragFinished() on the drag tracker and then sets the drag tracker tonull
.boolean
If there's a drag tracker, calls nativeDragStarted() on the drag tracker.protected boolean
If there's a drag tracker, sets it tonull
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
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
Asks the target edit part (if there is one) to show hover feedback viaEditPart.showTargetFeedback(Request)
with a hover request.protected void
Updates the location of the hover request.protected void
Sets the modifiers , type and location of the target request (which is aSelectionRequest
) and then callsupdateHoverRequest()
.Methods inherited from class org.eclipse.gef.tools.TargetingTool
doAutoexpose, eraseTargetFeedback, getAutoexposeHelper, getCommand, getExclusionSet, getTargetEditPart, getTargetRequest, handleAutoexpose, handleEnteredEditPart, handleExitingEditPart, handleInvalidInput, handleLeavingEditPart, isShowingTargetFeedback, isTargetLocked, lockTargetEditPart, resetFlags, resetHover, setAutoexposeHelper, setTargetEditPart, setTargetRequest, showTargetFeedback, unlockTargetEditPart, updateAutoexposeHelper, updateTargetUnderMouse
Methods inherited from class org.eclipse.gef.tools.AbstractTool
acceptArrowKey, 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
-
Field Details
-
MAX_FLAG
protected static final int MAX_FLAGMax flag- See Also:
-
STATE_TRAVERSE_HANDLE
protected static final int STATE_TRAVERSE_HANDLETraverse handle state- See Also:
-
MAX_STATE
protected static final int MAX_STATEMax state- See Also:
-
-
Constructor Details
-
SelectionTool
public SelectionTool()Default constructor.
-
-
Method Details
-
createHoverRequest
protected void createHoverRequest()Creates the hover request (aLocationRequest
) and sets its type toRequestConstants.REQ_SELECTION_HOVER
. -
createTargetRequest
Creates aSelectionRequest
for the target request.- Overrides:
createTargetRequest
in classTargetingTool
- Returns:
- the new target request
- See Also:
-
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 tonull
.- Specified by:
deactivate
in interfaceTool
- Overrides:
deactivate
in classTargetingTool
- See Also:
-
eraseHoverFeedback
protected void eraseHoverFeedback()Erases the hover feedback by callingEditPart.eraseTargetFeedback(Request)
. -
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 classAbstractTool
- Returns:
- the identifier for the command
- See Also:
-
getDebugName
Description copied from class:AbstractTool
Returns the debug name for this tool.- Overrides:
getDebugName
in classAbstractTool
- Returns:
- the debug name
- See Also:
-
getDragTracker
Returns the current drag tracker.- Returns:
- the drag tracker
-
getTargetingConditional
Returns a new Conditional that evaluates totrue
if the queried edit part'sEditPart.isSelectable()
method returnstrue
.- Overrides:
getTargetingConditional
in classTargetingTool
- Returns:
- the targeting conditional
- See Also:
-
getTargetHoverRequest
Returns the target hover request. Ifnull
, it will be created viacreateHoverRequest()
.- Returns:
- the hover request
-
handleButtonDown
protected boolean handleButtonDown(int button) If there is aHandle
under the mouse, this method sets the drag tracker returned from the handle. If there's anEditPart
under the mouse, this method sets the drag tracker returned from the edit part.- Overrides:
handleButtonDown
in classAbstractTool
- Parameters:
button
- which button went down- Returns:
true
if the buttonDown was handled- See Also:
-
handleButtonUp
protected boolean handleButtonUp(int button) Resets this tool when the last button is released.- Overrides:
handleButtonUp
in classAbstractTool
- Parameters:
button
- the button being released- Returns:
true
if the button up was handled- See Also:
-
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 toSTATE_INVALID
and handleInvalidInput is called. Subclasses may override this method to change what happens when the command stack changes. Returningtrue
indicates that the change was handled in some way.- Overrides:
handleCommandStackChanged
in classAbstractTool
- Returns:
true
if the change was handled in some way- See Also:
-
handleFocusLost
protected boolean handleFocusLost()Sets the drag tracker tonull
and goes into the initial state when focus is lost.- Overrides:
handleFocusLost
in classAbstractTool
- Returns:
true
if the event was handled- See Also:
-
handleHover
protected boolean handleHover()Called when the mouse hovers. CallsshowHoverFeedback()
.- Overrides:
handleHover
in classAbstractTool
- Returns:
true
if the hover was handled- See Also:
-
handleHoverStop
protected boolean handleHoverStop()Called when the mouse hover stops (i.e. the mouse moves or a button is clicked). CallseraseHoverFeedback()
.- Overrides:
handleHoverStop
in classTargetingTool
- Returns:
true
if the hover stop is processed in some way- See Also:
-
handleKeyDown
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 aKeyHandler
, it callsKeyHandler.keyPressed(KeyEvent)
.- Overrides:
handleKeyDown
in classAbstractTool
- Parameters:
e
- the key event- Returns:
true
if the key down was handled.- See Also:
-
handleKeyUp
If in the initial state and the viewer has aKeyHandler
, callsKeyHandler.keyReleased(KeyEvent)
sending it the given key event.- Overrides:
handleKeyUp
in classAbstractTool
- Parameters:
e
- the key event- Returns:
true
if the event was handled- See Also:
-
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 classAbstractTool
- Returns:
true
if the mouse move was handled- See Also:
-
handleNativeDragFinished
If there's a drag tracker, calls handleNativeDragFinished() on the drag tracker and then sets the drag tracker tonull
.- Overrides:
handleNativeDragFinished
in classAbstractTool
- Parameters:
event
- the drag event- Returns:
true
if the native drag finished was handled- See Also:
-
handleNativeDragStarted
If there's a drag tracker, calls nativeDragStarted() on the drag tracker.- Overrides:
handleNativeDragStarted
in classAbstractTool
- Parameters:
event
- the drag event- Returns:
true
if the native drag start was handled- See Also:
-
handleViewerExited
protected boolean handleViewerExited()If there's a drag tracker, sets it tonull
and then sets this tool's state to the initial state.- Overrides:
handleViewerExited
in classTargetingTool
- Returns:
true
if the viewer exited was handled- See Also:
-
keyDown
Forwards the key down event to the drag tracker, if one exists.- Specified by:
keyDown
in interfaceTool
- Overrides:
keyDown
in classAbstractTool
- Parameters:
evt
- the key eventviewer
- the originating viewer- See Also:
-
keyUp
Forwards the key up event to the drag tracker, if one exists.- Specified by:
keyUp
in interfaceTool
- Overrides:
keyUp
in classAbstractTool
- Parameters:
evt
- the key eventviewer
- the originating viewer- See Also:
-
mouseDown
Forwards the mouse down event to the drag tracker, if one exists.- Specified by:
mouseDown
in interfaceTool
- Overrides:
mouseDown
in classAbstractTool
- Parameters:
e
- the mouse eventviewer
- the originating viewer- See Also:
-
mouseDoubleClick
Forwards the mouse double clicked event to the drag tracker, if one exists.- Specified by:
mouseDoubleClick
in interfaceTool
- Overrides:
mouseDoubleClick
in classAbstractTool
- Parameters:
e
- the mouse eventviewer
- the originating viewer- See Also:
-
mouseDrag
Forwards the mouse drag event to the drag tracker, if one exists.- Specified by:
mouseDrag
in interfaceTool
- Overrides:
mouseDrag
in classAbstractTool
- Parameters:
e
- the mouse eventviewer
- the originating viewer- See Also:
-
mouseHover
Forwards the mouse hover event to the drag tracker, if one exists.- Specified by:
mouseHover
in interfaceTool
- Overrides:
mouseHover
in classAbstractTool
- Parameters:
me
- the mouse eventviewer
- the originating viewer- See Also:
-
mouseMove
Forwards the mouse move event to the drag tracker, if one exists.- Specified by:
mouseMove
in interfaceTool
- Overrides:
mouseMove
in classAbstractTool
- Parameters:
me
- the mouse eventviewer
- the originating viewer- See Also:
-
mouseUp
Forwards the mouse up event to the drag tracker, if one exists.- Specified by:
mouseUp
in interfaceTool
- Overrides:
mouseUp
in classAbstractTool
- Parameters:
e
- the mouse eventviewer
- the originating viewer- See Also:
-
mouseWheelScrolled
Delegates the scrolling to the DragTracker (if there is one). If not, invokes the super method.- Specified by:
mouseWheelScrolled
in interfaceTool
- Overrides:
mouseWheelScrolled
in classAbstractTool
- Parameters:
event
- the SWT scroll eventviewer
- the originating viewer- See Also:
-
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, callssuper
.- Overrides:
refreshCursor
in classAbstractTool
- See Also:
-
setDragTracker
Sets the drag tracker for this SelectionTool. If the current drag tracker is notnull
, this method deactivates it. If the new drag tracker is notnull
, this method will activate it and set theEditDomain
andEditPartViewer
.- Parameters:
newDragTracker
- the new drag tracker
-
showHoverFeedback
protected void showHoverFeedback()Asks the target edit part (if there is one) to show hover feedback viaEditPart.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 aSelectionRequest
) and then callsupdateHoverRequest()
.- Overrides:
updateTargetRequest
in classTargetingTool
- See Also:
-
getDebugNameForState
Description copied from class:AbstractTool
Returns a String representation of the given state for debug purposes.- Overrides:
getDebugNameForState
in classAbstractTool
- Parameters:
state
- the state- Returns:
- the string for the given state
- See Also:
-