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 intMAX_FLAGMax flagprotected static intMAX_STATEMax stateprotected static intSTATE_TRAVERSE_HANDLETraverse 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()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcreateHoverRequest()Creates the hover request (aLocationRequest) and sets its type toRequestConstants.REQ_SELECTION_HOVER.protected RequestcreateTargetRequest()Creates aSelectionRequestfor the target request.voiddeactivate()Deactivates the tool.protected voideraseHoverFeedback()Erases the hover feedback by callingEditPart.eraseTargetFeedback(Request).protected java.lang.StringgetCommandName()Returns the identifier of the command that is being sought.protected java.lang.StringgetDebugName()Returns the debug name for this tool.protected java.lang.StringgetDebugNameForState(int state)Returns a String representation of the given state for debug purposes.protected DragTrackergetDragTracker()Returns the current drag tracker.protected RequestgetTargetHoverRequest()Returns the target hover request.protected EditPartViewer.ConditionalgetTargetingConditional()Returns a new Conditional that evaluates totrueif the queried edit part'sEditPart.isSelectable()method returnstrue.protected booleanhandleButtonDown(int button)If there is aHandleunder the mouse, this method sets the drag tracker returned from the handle.protected booleanhandleButtonUp(int button)Resets this tool when the last button is released.protected booleanhandleCommandStackChanged()Called when the command stack has changed, for instance, when a delete or undo command has been executed.protected booleanhandleFocusLost()Sets the drag tracker tonulland goes into the initial state when focus is lost.protected booleanhandleHover()Called when the mouse hovers.protected booleanhandleHoverStop()Called when the mouse hover stops (i.e. the mouse moves or a button is clicked).protected booleanhandleKeyDown(KeyEvent e)Processes key down events.protected booleanhandleKeyUp(KeyEvent e)If in the initial state and the viewer has aKeyHandler, callsKeyHandler.keyReleased(KeyEvent)sending it the given key event.protected booleanhandleMove()If in the initial state, updates the request and the mouse target and asks to show target feedback.booleanhandleNativeDragFinished(DragSourceEvent event)If there's a drag tracker, calls handleNativeDragFinished() on the drag tracker and then sets the drag tracker tonull.booleanhandleNativeDragStarted(DragSourceEvent event)If there's a drag tracker, calls nativeDragStarted() on the drag tracker.protected booleanhandleViewerExited()If there's a drag tracker, sets it tonulland then sets this tool's state to the initial state.voidkeyDown(KeyEvent evt, EditPartViewer viewer)Forwards the key down event to the drag tracker, if one exists.voidkeyUp(KeyEvent evt, EditPartViewer viewer)Forwards the key up event to the drag tracker, if one exists.voidmouseDoubleClick(MouseEvent e, EditPartViewer viewer)Forwards the mouse double clicked event to the drag tracker, if one exists.voidmouseDown(MouseEvent e, EditPartViewer viewer)Forwards the mouse down event to the drag tracker, if one exists.voidmouseDrag(MouseEvent e, EditPartViewer viewer)Forwards the mouse drag event to the drag tracker, if one exists.voidmouseHover(MouseEvent me, EditPartViewer viewer)Forwards the mouse hover event to the drag tracker, if one exists.voidmouseMove(MouseEvent me, EditPartViewer viewer)Forwards the mouse move event to the drag tracker, if one exists.voidmouseUp(MouseEvent e, EditPartViewer viewer)Forwards the mouse up event to the drag tracker, if one exists.voidmouseWheelScrolled(Event event, EditPartViewer viewer)Delegates the scrolling to the DragTracker (if there is one).protected voidrefreshCursor()If there is a drag tracker, this method does nothing so that the drag tracker can take care of the cursor.voidsetDragTracker(DragTracker newDragTracker)Sets the drag tracker for this SelectionTool.protected voidshowHoverFeedback()Asks the target edit part (if there is one) to show hover feedback viaEditPart.showTargetFeedback(Request)with a hover request.protected voidupdateHoverRequest()Updates the location of the hover request.protected voidupdateTargetRequest()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 Detail
-
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
-
-
Method Detail
-
createHoverRequest
protected void createHoverRequest()
Creates the hover request (aLocationRequest) and sets its type toRequestConstants.REQ_SELECTION_HOVER.
-
createTargetRequest
protected Request createTargetRequest()
Creates aSelectionRequestfor the target request.- Overrides:
createTargetRequestin classTargetingTool- 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 tonull.- Specified by:
deactivatein interfaceTool- Overrides:
deactivatein classTargetingTool- See Also:
Tool.deactivate()
-
eraseHoverFeedback
protected void eraseHoverFeedback()
Erases the hover feedback by callingEditPart.eraseTargetFeedback(Request).
-
getCommandName
protected java.lang.String getCommandName()
Description copied from class:AbstractToolReturns 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:
getCommandNamein classAbstractTool- Returns:
- the identifier for the command
- See Also:
AbstractTool.getCommandName()
-
getDebugName
protected java.lang.String getDebugName()
Description copied from class:AbstractToolReturns the debug name for this tool.- Overrides:
getDebugNamein classAbstractTool- 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 totrueif the queried edit part'sEditPart.isSelectable()method returnstrue.- Overrides:
getTargetingConditionalin classTargetingTool- Returns:
- the targeting conditional
- See Also:
TargetingTool.getTargetingConditional()
-
getTargetHoverRequest
protected Request 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 aHandleunder the mouse, this method sets the drag tracker returned from the handle. If there's anEditPartunder the mouse, this method sets the drag tracker returned from the edit part.- Overrides:
handleButtonDownin classAbstractTool- Parameters:
button- which button went down- Returns:
trueif 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:
handleButtonUpin classAbstractTool- Parameters:
button- the button being released- Returns:
trueif the button up was handled- See Also:
AbstractTool.handleButtonUp(int)
-
handleCommandStackChanged
protected boolean handleCommandStackChanged()
Description copied from class:AbstractToolCalled when the command stack has changed, for instance, when a delete or undo command has been executed. By default, state is set toSTATE_INVALIDand handleInvalidInput is called. Subclasses may override this method to change what happens when the command stack changes. Returningtrueindicates that the change was handled in some way.- Overrides:
handleCommandStackChangedin classAbstractTool- Returns:
trueif the change was handled in some way- See Also:
AbstractTool.handleCommandStackChanged()
-
handleFocusLost
protected boolean handleFocusLost()
Sets the drag tracker tonulland goes into the initial state when focus is lost.- Overrides:
handleFocusLostin classAbstractTool- Returns:
trueif the event was handled- See Also:
AbstractTool.handleFocusLost()
-
handleHover
protected boolean handleHover()
Called when the mouse hovers. CallsshowHoverFeedback().- Overrides:
handleHoverin classAbstractTool- Returns:
trueif 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). CallseraseHoverFeedback().- Overrides:
handleHoverStopin classTargetingTool- Returns:
trueif 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 aKeyHandler, it callsKeyHandler.keyPressed(KeyEvent).- Overrides:
handleKeyDownin classAbstractTool- Parameters:
e- the key event- Returns:
trueif 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 aKeyHandler, callsKeyHandler.keyReleased(KeyEvent)sending it the given key event.- Overrides:
handleKeyUpin classAbstractTool- Parameters:
e- the key event- Returns:
trueif 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:
handleMovein classAbstractTool- Returns:
trueif 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 tonull.- Overrides:
handleNativeDragFinishedin classAbstractTool- Parameters:
event- the drag event- Returns:
trueif 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:
handleNativeDragStartedin classAbstractTool- Parameters:
event- the drag event- Returns:
trueif the native drag start was handled- See Also:
AbstractTool.handleNativeDragStarted(DragSourceEvent)
-
handleViewerExited
protected boolean handleViewerExited()
If there's a drag tracker, sets it tonulland then sets this tool's state to the initial state.- Overrides:
handleViewerExitedin classTargetingTool- Returns:
trueif 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:
keyDownin interfaceTool- Overrides:
keyDownin classAbstractTool- Parameters:
evt- the key eventviewer- 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:
keyUpin interfaceTool- Overrides:
keyUpin classAbstractTool- Parameters:
evt- the key eventviewer- 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:
mouseDownin interfaceTool- Overrides:
mouseDownin classAbstractTool- Parameters:
e- the mouse eventviewer- 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:
mouseDoubleClickin interfaceTool- Overrides:
mouseDoubleClickin classAbstractTool- Parameters:
e- the mouse eventviewer- 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:
mouseDragin interfaceTool- Overrides:
mouseDragin classAbstractTool- Parameters:
e- the mouse eventviewer- 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:
mouseHoverin interfaceTool- Overrides:
mouseHoverin classAbstractTool- Parameters:
me- the mouse eventviewer- 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:
mouseMovein interfaceTool- Overrides:
mouseMovein classAbstractTool- Parameters:
me- the mouse eventviewer- 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:
mouseUpin interfaceTool- Overrides:
mouseUpin classAbstractTool- Parameters:
e- the mouse eventviewer- 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:
mouseWheelScrolledin interfaceTool- Overrides:
mouseWheelScrolledin classAbstractTool- Parameters:
event- the SWT scroll eventviewer- 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, callssuper.- Overrides:
refreshCursorin classAbstractTool- See Also:
AbstractTool.refreshCursor()
-
setDragTracker
public void setDragTracker(DragTracker newDragTracker)
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 theEditDomainandEditPartViewer.- 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:
updateTargetRequestin classTargetingTool- See Also:
TargetingTool.updateTargetRequest()
-
getDebugNameForState
protected java.lang.String getDebugNameForState(int state)
Description copied from class:AbstractToolReturns a String representation of the given state for debug purposes.- Overrides:
getDebugNameForStatein classAbstractTool- Parameters:
state- the state- Returns:
- the string for the given state
- See Also:
AbstractTool.getDebugNameForState(int)
-
-