Class DropAdapterAssistant
An extension may have multiple drop adapters with mutually exclusive possibleDropTargets expressions. The first drop adapter found that matches the given drop target and returns an OK status for CommonDropAdapterAssistant.validateDrop(...) will be given an opportunity to handle the drop.
Each CommonDropAdapterAssistant is contained by single content extension. The opportunity for each assistant to handle the drop operation is determined by the possibleChildren expression of the org.eclipse.ui.navigator.navigatorContent/navigatorContent extension; whenever every element in the drag set matches the possibleChildren expression of an extension, it is eligible to handle the drop operation. This initial set is further culled using the possibleDropTargets expression of the commonDropAdapter using the current drop target.
If drag operations originate outside of Eclipse, then the set of eligible drop adapters is determined based on the drop target (using the possibleDropTargets expression). Each assistant can then indicate whether isSupportedType(TransferData) the incoming type is supported.
Whenever a match is found, the assistant will be given an opportunity to first validateDrop(Object, int, TransferData), and then if the assistant returns true, the assist must handleDrop(CommonDropAdapter, DropTargetEvent, Object). If multiple assistants match the drop target, then the potential assistants are ordered based on priority and their override relationships and given an opportunity to validate the drop operation in turn. The first one to validate will have the opportunity to carry out the drop.
Clients may handle DND operations that begin and end in the current viewer by overriding the following methods:
- validateDrop(Object, int, TransferData): Indicate whether this assistant can handle a drop onto the current viewer.
- handleDrop(CommonDropAdapter, DropTargetEvent, Object): Handle the drop operation onto the current viewer.
If a user originates a drag operation to another viewer that cannot handle one of the available drag transfer types, drop assistants may handle the drop operation for the target viewer. Clients must override:
- validatePluginTransferDrop(IStructuredSelection, Object): Indicate whether this assistant can handle the drop onto another viewer.
- handlePluginTransferDrop(IStructuredSelection, Object): Handle the drop operation onto the other viewer.
- Author:
- Christopher Mindus
Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionstatic int
convertDNDOperation
(int op) Converts DND.DROP_* to DesignerProp.OP_*.static String
getDNDOperation
(int op) Gets DND.DROP_* description for the operation.org.eclipse.core.runtime.IStatus
handleDrop
(org.eclipse.ui.navigator.CommonDropAdapter cda, org.eclipse.swt.dnd.DropTargetEvent event, Object target) Carry out the DND operation.org.eclipse.core.runtime.IStatus
handlePluginTransferDrop
(org.eclipse.jface.viewers.IStructuredSelection selection, Object target) Handle the drop operation for the target viewer.boolean
isSupportedType
(org.eclipse.swt.dnd.TransferData transferType) Clients may extend the supported transfer types beyond the default LocalSelectionTransfer.getTransfer() and org.eclipse.ui.part.PluginTransfer.getInstance() transfer types.static PasteFeedback
paste
(boolean doPerformOperation, DesignerProp target, int position, IPropUndoRedo undoRedo) Performs a paste or tests for valid operation.static PasteFeedback
pasteLink
(boolean doPerformOperation, DesignerProp target, IPropUndoRedo undoRedo) Performs a paste-link or tests for valid operation.org.eclipse.core.runtime.IStatus
validateDrop
(Object target, int operation, org.eclipse.swt.dnd.TransferData transferType) Validates dropping on the given object.org.eclipse.core.runtime.IStatus
validatePluginTransferDrop
(org.eclipse.jface.viewers.IStructuredSelection selection, Object target) Return true if the client can handle the drop onto the target viewer of the drop operation.Methods inherited from class org.eclipse.ui.navigator.CommonDropAdapterAssistant
doInit, getCommonDropAdapter, getContentService, getCurrentEvent, getShell, init, setCommonDropAdapter
Constructor Details
DropAdapterAssistant
public DropAdapterAssistant()Eclipse constructor.
Method Details
paste
public static PasteFeedback paste(boolean doPerformOperation, DesignerProp target, int position, IPropUndoRedo undoRedo) Performs a paste or tests for valid operation.- Parameters:
doPerformOperation
- Flag to test or to perform the operation.target
- Target property.position
- The position in the target (0=inside, -1=before target in parent, 1=after target in parent).undoRedo
- Undo/redo instance.- Returns:
- A feed-back instance of operation.
pasteLink
public static PasteFeedback pasteLink(boolean doPerformOperation, DesignerProp target, IPropUndoRedo undoRedo) Performs a paste-link or tests for valid operation.- Parameters:
doPerformOperation
- Flag to test or to perform the operation.target
- Target property.undoRedo
- Undo/redo instance.- Returns:
- A feed-back instance of operation.
isSupportedType
public boolean isSupportedType(org.eclipse.swt.dnd.TransferData transferType) Clients may extend the supported transfer types beyond the default LocalSelectionTransfer.getTransfer() and org.eclipse.ui.part.PluginTransfer.getInstance() transfer types. When a transfer type other than one of these is encountered, the DND Service will query the visible and active descriptors that are enabled for the drop target of the current operation.- Overrides:
isSupportedType
in classorg.eclipse.ui.navigator.CommonDropAdapterAssistant
- Parameters:
transferType
- The transfer data from the drop operation.- Returns:
- True if the given TransferData can be understood by this assistant.
validateDrop
public org.eclipse.core.runtime.IStatus validateDrop(Object target, int operation, org.eclipse.swt.dnd.TransferData transferType) Validates dropping on the given object. This method is called whenever some aspect of the drop operation changes.- Specified by:
validateDrop
in classorg.eclipse.ui.navigator.CommonDropAdapterAssistant
- Parameters:
target
- The object that the mouse is currently hovering over, ornull
if the mouse is hovering over empty space.operation
- The current drag operation (copy, move, etc.).transferType
- The current transfer type.- Returns:
- A status indicating whether the drop is valid.
validatePluginTransferDrop
public org.eclipse.core.runtime.IStatus validatePluginTransferDrop(org.eclipse.jface.viewers.IStructuredSelection selection, Object target) Return true if the client can handle the drop onto the target viewer of the drop operation.The default behavior of this super-method is to return Status.CANCEL_STATUS.
- Overrides:
validatePluginTransferDrop
in classorg.eclipse.ui.navigator.CommonDropAdapterAssistant
- Parameters:
selection
- The selection dragged from the viewer.target
- The target of the drop operation.- Returns:
- OK if the plug-in transfer can be handled by this assistant.
handlePluginTransferDrop
public org.eclipse.core.runtime.IStatus handlePluginTransferDrop(org.eclipse.jface.viewers.IStructuredSelection selection, Object target) Handle the drop operation for the target viewer.The default behavior of this super-method is to return Status.CANCEL_STATUS.
- Overrides:
handlePluginTransferDrop
in classorg.eclipse.ui.navigator.CommonDropAdapterAssistant
- Parameters:
selection
- The selection dragged from the viewer.target
- The target of the drop operation.- Returns:
- OK if the drop operation succeeded.
convertDNDOperation
public static int convertDNDOperation(int op) Converts DND.DROP_* to DesignerProp.OP_*.- Parameters:
op
- The Drag-and-Drop DND.DROP_* operation.
getDNDOperation
Gets DND.DROP_* description for the operation.- Parameters:
op
- The Drag-and-Drop DND.DROP_* operation.