Class DropAdapterAssistant


  • public class DropAdapterAssistant
    extends org.eclipse.ui.navigator.CommonDropAdapterAssistant
    Used by the org.eclipse.ui.navigator.navigatorContent/navigatorContent/commonDropAdapter extension point to carry out pluggable drop operations. The Drop Assistant is invoked whenever elements that are dragged match the possibleChildren expression of the containing navigatorContent extension and the drop target of the operation is described by the possibleDropTargets expression of the dropAssistant element.

    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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      static intconvertDNDOperation​(int op)
      Converts DND.DROP_* to DesignerProp.OP_*.
      static java.lang.StringgetDNDOperation​(int op)
      Gets DND.DROP_* description for the operation.
      org.eclipse.core.runtime.IStatushandleDrop​(org.eclipse.ui.navigator.CommonDropAdapter cda, org.eclipse.swt.dnd.DropTargetEvent event, java.lang.Object target)
      Carry out the DND operation.
      org.eclipse.core.runtime.IStatushandlePluginTransferDrop​(org.eclipse.jface.viewers.IStructuredSelection selection, java.lang.Object target)
      Handle the drop operation for the target viewer.
      booleanisSupportedType​(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 PasteFeedbackpaste​(boolean doPerformOperation, DesignerProp target, int position, IPropUndoRedo undoRedo)
      Performs a paste or tests for valid operation.
      static PasteFeedbackpasteLink​(boolean doPerformOperation, DesignerProp target, IPropUndoRedo undoRedo)
      Performs a paste-link or tests for valid operation.
      org.eclipse.core.runtime.IStatusvalidateDrop​(java.lang.Object target, int operation, org.eclipse.swt.dnd.TransferData transferType)
      Validates dropping on the given object.
      org.eclipse.core.runtime.IStatusvalidatePluginTransferDrop​(org.eclipse.jface.viewers.IStructuredSelection selection, java.lang.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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DropAdapterAssistant

        public DropAdapterAssistant()
        Eclipse constructor.
    • Method Detail

      • 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 class org.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​(java.lang.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 class org.eclipse.ui.navigator.CommonDropAdapterAssistant
        Parameters:
        target - The object that the mouse is currently hovering over, or null 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.
      • handleDrop

        public org.eclipse.core.runtime.IStatus handleDrop​(org.eclipse.ui.navigator.CommonDropAdapter cda,
                                                           org.eclipse.swt.dnd.DropTargetEvent event,
                                                           java.lang.Object target)
        Carry out the DND operation.

        Note: Contrary to the SWT DropTargetListener specification, you must make sure that the dropTargetEvent.detail is not set to DND.DROP_MOVE unless actual work is required in the DragSourceListener.dragFinished(org.eclipse.swt.dnd.DragSourceEvent) to complete the operation (for example removing the moved file). In particular for the LocalSelectionTransfer case, DND.DROP_MOVE cannot be used as it will cause incorrect behavior in some existing drag handlers.

        In case of move operations where no action is required on the source side (e.g. LocalSelectionTransfer) you must set dropTargetEvent.detail to DND.DROP_NONE to signal this to the drag source. Even though the SWT specification says this is canceling the drop, it is not really doing so, it is only preventing the DND.DROP_MOVE from being passed through to the dragFinished() method.

        Specified by:
        handleDrop in class org.eclipse.ui.navigator.CommonDropAdapterAssistant
        Parameters:
        cda - The Drop Adapter contains information that has already been parsed from the drop event.
        event - The drop target event.
        target - The object being dragged onto.
        Returns:
        A status indicating whether the drop completed OK.
      • validatePluginTransferDrop

        public org.eclipse.core.runtime.IStatus validatePluginTransferDrop​(org.eclipse.jface.viewers.IStructuredSelection selection,
                                                                           java.lang.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 class org.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,
                                                                         java.lang.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 class org.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

        public static java.lang.String getDNDOperation​(int op)
        Gets DND.DROP_* description for the operation.
        Parameters:
        op - The Drag-and-Drop DND.DROP_* operation.