Package org.eclipse.jface.viewers
Class ViewerDropAdapter
java.lang.Object
org.eclipse.swt.dnd.DropTargetAdapter
org.eclipse.jface.viewers.ViewerDropAdapter
- All Implemented Interfaces:
EventListener,DropTargetListener
- Direct Known Subclasses:
PluginDropAdapter
This adapter class provides generic drag-and-drop support for a viewer.
Subclasses must implement the following methods:
validateDrop- identifies valid drop targets in viewerperformDrop- carries out a drop into a viewer
setFeedbackEnabled method can be called to turn on and off
visual insertion feedback (on by default).-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConstant describing the position of the cursor relative to the target object.static final intConstant describing the position of the cursor relative to the target object.static final intConstant describing the position of the cursor relative to the target object.static final intConstant describing the position of the cursor relative to the target object. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedViewerDropAdapter(Viewer viewer) Creates a new drop adapter for the given viewer. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidClears internal state of this drop adapter.protected intdetermineLocation(DropTargetEvent event) Returns the position of the given event's coordinates relative to its target.protected ObjectdetermineTarget(DropTargetEvent event) Returns the target item of the given drop event.voiddragEnter(DropTargetEvent event) This implementation ofdragEnterpermits the default operation defined inevent.detailto be performed on the current data type defined inevent.currentDataType.voidThis implementation ofdragOperationChangedpermits the default operation defined inevent.detailto be performed on the current data type defined inevent.currentDataType.voiddragOver(DropTargetEvent event) This implementation ofdragOverpermits the default operation defined inevent.detailto be performed on the current data type defined inevent.currentDataType.voiddrop(DropTargetEvent event) This implementation ofdropdoes nothing.voiddropAccept(DropTargetEvent event) This implementation ofdropAcceptpermits the default operation defined inevent.detailto be performed on the current data type defined inevent.currentDataType.protected RectangleReturns the bounds of the given SWT tree or table item.protected DropTargetEventReturns the currentDropTargetEvent.protected intReturns a constant describing the position of the mouse relative to the target (before, on, or after the target.protected intReturns the current operation.protected ObjectReturns the target object currently under the mouse.booleanReturns whether visible insertion feedback should be presented to the user.protected ObjectReturns the object currently selected by the viewer.protected intGet the threshold to determine whether to have before/after feedback or select feedback.protected Viewerprotected voidhandleException(Throwable exception, DropTargetEvent event) Deprecated.this method should not be used.protected voidoverrideOperation(int operation) Overrides the current operation for a drop that happens immediately after the current validateDrop.abstract booleanperformDrop(Object data) Performs any work associated with the drop.voidsetExpandEnabled(boolean value) Sets whether auto expanding should be provided during dragging.voidsetFeedbackEnabled(boolean value) Sets whether visible insertion feedback should be presented to the user.voidsetScrollEnabled(boolean value) Sets whether auto scrolling should be provided during dragging.voidsetScrollExpandEnabled(boolean value) Sets whether auto scrolling and expanding should be provided during dragging.voidsetSelectionFeedbackEnabled(boolean value) Sets whether selection feedback should be provided during dragging.abstract booleanvalidateDrop(Object target, int operation, TransferData transferType) Validates dropping on the given object.Methods inherited from class org.eclipse.swt.dnd.DropTargetAdapter
dragLeave
-
Field Details
-
LOCATION_BEFORE
public static final int LOCATION_BEFOREConstant describing the position of the cursor relative to the target object. This means the mouse is positioned slightly before the target.- See Also:
-
LOCATION_AFTER
public static final int LOCATION_AFTERConstant describing the position of the cursor relative to the target object. This means the mouse is positioned slightly after the target.- See Also:
-
LOCATION_ON
public static final int LOCATION_ONConstant describing the position of the cursor relative to the target object. This means the mouse is positioned directly on the target.- See Also:
-
LOCATION_NONE
public static final int LOCATION_NONEConstant describing the position of the cursor relative to the target object. This means the mouse is not positioned over or near any valid target.- See Also:
-
-
Constructor Details
-
ViewerDropAdapter
Creates a new drop adapter for the given viewer.- Parameters:
viewer- the viewer
-
-
Method Details
-
clearState
protected void clearState()Clears internal state of this drop adapter. This method can be called when no DnD operation is underway, to clear internal state from previous drop operations.- Since:
- 3.5
-
determineLocation
Returns the position of the given event's coordinates relative to its target. The position is determined to be before, after, or on the item, based on some threshold value.- Parameters:
event- the event- Returns:
- one of the
LOCATION_*constants defined in this class
-
getThreshold
protected int getThreshold()Get the threshold to determine whether to have before/after feedback or select feedback. Threshold shall not be bigger than itemHeight/2.- Returns:
- amount of pixels from top/bottom of element that trigger before/after behavior.
- Since:
- 3.16
-
determineTarget
Returns the target item of the given drop event.- Parameters:
event- the event- Returns:
- The target of the drop, may be
null.
-
dragEnter
Description copied from class:DropTargetAdapterThis implementation ofdragEnterpermits the default operation defined inevent.detailto be performed on the current data type defined inevent.currentDataType. For additional information seeDropTargetListener.dragEnter.- Specified by:
dragEnterin interfaceDropTargetListener- Overrides:
dragEnterin classDropTargetAdapter- Parameters:
event- the information associated with the drag enter event- See Also:
-
dragOperationChanged
Description copied from class:DropTargetAdapterThis implementation ofdragOperationChangedpermits the default operation defined inevent.detailto be performed on the current data type defined inevent.currentDataType. For additional information seeDropTargetListener.dragOperationChanged.- Specified by:
dragOperationChangedin interfaceDropTargetListener- Overrides:
dragOperationChangedin classDropTargetAdapter- Parameters:
event- the information associated with the drag operation changed event- See Also:
-
dragOver
Description copied from class:DropTargetAdapterThis implementation ofdragOverpermits the default operation defined inevent.detailto be performed on the current data type defined inevent.currentDataType. For additional information seeDropTargetListener.dragOver.- Specified by:
dragOverin interfaceDropTargetListener- Overrides:
dragOverin classDropTargetAdapter- Parameters:
event- the information associated with the drag over event- See Also:
-
drop
Description copied from class:DropTargetAdapterThis implementation ofdropdoes nothing. For additional information seeDropTargetListener.drop.- Specified by:
dropin interfaceDropTargetListener- Overrides:
dropin classDropTargetAdapter- Parameters:
event- the information associated with the drop event- See Also:
-
dropAccept
Description copied from class:DropTargetAdapterThis implementation ofdropAcceptpermits the default operation defined inevent.detailto be performed on the current data type defined inevent.currentDataType. For additional information seeDropTargetListener.dropAccept.- Specified by:
dropAcceptin interfaceDropTargetListener- Overrides:
dropAcceptin classDropTargetAdapter- Parameters:
event- the information associated with the drop accept event- See Also:
-
getBounds
Returns the bounds of the given SWT tree or table item.- Parameters:
item- the SWT Item- Returns:
- the bounds, or
nullif it is not a known type of item
-
getCurrentLocation
protected int getCurrentLocation()Returns a constant describing the position of the mouse relative to the target (before, on, or after the target.- Returns:
- one of the
LOCATION_*constants defined in this type
-
getCurrentOperation
protected int getCurrentOperation()Returns the current operation.- Returns:
- a
DROP_*constant from classDND - See Also:
-
getCurrentTarget
Returns the target object currently under the mouse.- Returns:
- the current target object
-
getCurrentEvent
Returns the currentDropTargetEvent. This may be called only inside of thevalidateDrop(Object, int, TransferData)orperformDrop(Object)methods.- Returns:
- the DropTargetEvent
- Since:
- 3.5
-
getFeedbackEnabled
public boolean getFeedbackEnabled()Returns whether visible insertion feedback should be presented to the user.Typical insertion feedback is the horizontal insertion bars that appear between adjacent items while dragging.
- Returns:
trueif visual feedback is desired, andfalseif not
-
getSelectedObject
Returns the object currently selected by the viewer.- Returns:
- the selected object or the first element in current selection, and null if no objects are selected
-
getViewer
- Returns:
- the viewer to which this drop support has been added.
-
handleException
Deprecated.this method should not be used. Exception handling has been removed from DropTargetAdapter methods overridden by this class. Handles any exception that occurs during callback, including rethrowing behavior.[Issue: Implementation prints stack trace and eats exception to avoid crashing VA/J. Consider conditionalizing the implementation to do one thing in VAJ and something more reasonable in other operating environments. ]
- Parameters:
exception- the exceptionevent- the event
-
performDrop
Performs any work associated with the drop.Subclasses must implement this method to provide drop behavior.
- Parameters:
data- the drop data- Returns:
trueif the drop was successful, andfalseotherwise
-
overrideOperation
protected void overrideOperation(int operation) Overrides the current operation for a drop that happens immediately after the current validateDrop. This maybe called only from within avalidateDrop(Object, int, TransferData)method- Parameters:
operation- the operation to be used for the drop.- Since:
- 3.5
- See Also:
-
setFeedbackEnabled
public void setFeedbackEnabled(boolean value) Sets whether visible insertion feedback should be presented to the user.Typical insertion feedback is the horizontal insertion bars that appear between adjacent items while dragging.
- Parameters:
value-trueif visual feedback is desired, andfalseif not
-
setSelectionFeedbackEnabled
public void setSelectionFeedbackEnabled(boolean value) Sets whether selection feedback should be provided during dragging.- Parameters:
value-trueif selection feedback is desired, andfalseif not- Since:
- 3.2
-
setScrollExpandEnabled
public void setScrollExpandEnabled(boolean value) Sets whether auto scrolling and expanding should be provided during dragging.- Parameters:
value-trueif scrolling and expanding is desired, andfalseif not- Since:
- 2.0
-
setExpandEnabled
public void setExpandEnabled(boolean value) Sets whether auto expanding should be provided during dragging.- Parameters:
value-trueif expanding is desired, andfalseif not- Since:
- 3.4
-
setScrollEnabled
public void setScrollEnabled(boolean value) Sets whether auto scrolling should be provided during dragging.- Parameters:
value-trueif scrolling is desired, andfalseif not- Since:
- 3.4
-
validateDrop
Validates dropping on the given object. This method is called whenever some aspect of the drop operation changes.Subclasses must implement this method to define which drops make sense.
- Parameters:
target- the object that the mouse is currently hovering over, ornullif the mouse is hovering over empty spaceoperation- the current drag operation (copy, move, etc.)transferType- the current transfer type- Returns:
trueif the drop is valid, andfalseotherwise
-