# Class CommonDropAdapterAssistant

java.lang.Object
org.eclipse.ui.navigator.CommonDropAdapterAssistant

Direct Known Subclasses:
  `ResourceDropAdapterAssistant`

public abstract class CommonDropAdapterAssistant extends Object

Used by the org.eclipse.ui.navigator.navigatorContent/navigatorContent/commonDropAdapter extension point to carry out pluggable drop operations.

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 `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 opportunty 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.

Clients may subclass this.

Since:
  3.2
See Also:
  - `INavigatorDnDService`
  - `INavigatorDnDService.findCommonDropAdapterAssistants(Object, TransferData)`

## Constructor Summary

Constructors
Constructor
Description
`CommonDropAdapterAssistant()`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`doInit()`
Override to perform any one-time initialization.
`protected CommonDropAdapter`
`getCommonDropAdapter()`
Returns the `CommonDropAdapter`.
`protected INavigatorContentService`
`getContentService()`
`DropTargetEvent`
`getCurrentEvent()`
Returns the current `DropTargetEvent`.
`protected final Shell`
`getShell()`
`abstract IStatus`
`handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget)`
Carry out the DND operation.
`IStatus`
`handlePluginTransferDrop(IStructuredSelection aDragSelection, Object aDropTarget)`
Handle the drop operation for the target viewer.
`final void`
`init(INavigatorContentService aContentService)`
Perform any necessary initialization using the `INavigatorContentService`.
`boolean`
`isSupportedType(TransferData aTransferType)`
Clients may extend the supported transfer types beyond the default `LocalSelectionTransfer.getTransfer()` and `PluginTransfer.getInstance()` transfer types.
`void`
`setCommonDropAdapter(CommonDropAdapter dropAdapter)`
Sets the `CommonDropAdapter`.
`abstract IStatus`
`validateDrop(Object target, int operation, TransferData transferType)`
Validates dropping on the given object.
`IStatus`
`validatePluginTransferDrop(IStructuredSelection aDragSelection, Object aDropTarget)`
Return true if the client can handle the drop onto the target viewer of the drop operation.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### CommonDropAdapterAssistant

public CommonDropAdapterAssistant()

## Method Details

### init

public final void init(INavigatorContentService aContentService)
Perform any necessary initialization using the `INavigatorContentService`.

Parameters:
  `aContentService` - The instance of `INavigatorContentService` that the current CommonDropAdapterAssistant will be associated with

### doInit

protected void doInit()
Override to perform any one-time initialization.

### validateDrop

public abstract IStatus validateDrop(Object target, int operation, TransferData transferType)
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. If clients return true, then they will be allowed to handle the drop in `handleDrop(CommonDropAdapter, DropTargetEvent, Object)`.

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 abstract IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget)
Carry out the DND operation.

Note: Contrary to the SWT `DropTargetListener` specification, you must make sure that the aDropTargetEvent.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 aDropTargetEvent.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.

Parameters:
  `aDropAdapter` - The Drop Adapter contains information that has already been parsed from the drop event.
  `aDropTargetEvent` - The drop target event.
  `aTarget` - The object being dragged onto
Returns:
  A status indicating whether the drop completed OK.

### isSupportedType

public boolean isSupportedType(TransferData aTransferType)
Clients may extend the supported transfer types beyond the default `LocalSelectionTransfer.getTransfer()` and `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.

Parameters:
  `aTransferType` - The transfer data from the drop operation
Returns:
  True if the given TransferData can be understood by this assistant.

### validatePluginTransferDrop

public IStatus validatePluginTransferDrop(IStructuredSelection aDragSelection, Object aDropTarget)
Return true if the client can handle the drop onto the target viewer of the drop operation.

The default behavior of this method is to return Status.CANCEL_STATUS.

Parameters:
  `aDragSelection` - The selection dragged from the viewer.
  `aDropTarget` - The target of the drop operation.
Returns:
  OK if the plugin transfer can be handled by this assistant.

### handlePluginTransferDrop

public IStatus handlePluginTransferDrop(IStructuredSelection aDragSelection, Object aDropTarget)
Handle the drop operation for the target viewer.

The default behavior of this method is to return Status.CANCEL_STATUS.

Parameters:
  `aDragSelection` - The selection dragged from the viewer.
  `aDropTarget` - The target of the drop operation.
Returns:
  OK if the drop operation succeeded.

### getContentService

protected INavigatorContentService getContentService()

Returns:
  The associated content service.

### getShell

protected final Shell getShell()

Returns:
  A shell for the viewer currently used by the `INavigatorContentService`.

### getCurrentEvent

public DropTargetEvent getCurrentEvent()
Returns the current `DropTargetEvent`.

Returns:
  event the current DropTargetEvent.
Since:
  3.4

### setCommonDropAdapter

public void setCommonDropAdapter(CommonDropAdapter dropAdapter)
Sets the `CommonDropAdapter`.

Parameters:
  `dropAdapter` - the drop adapter
Restriction:
  This method is not intended to be referenced by clients.
Restriction:
  This method is not intended to be re-implemented or extended by clients.

### getCommonDropAdapter

protected CommonDropAdapter getCommonDropAdapter()
Returns the `CommonDropAdapter`.

Returns:
  the CommonDropAdapter.
Since:
  3.4