## org.eclipse.emf.edit.ui.dnd
Class EditingDomainViewerDropAdapter

    java.lang.Object
      org.eclipse.swt.dnd.DropTargetAdapter
          org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter

All Implemented Interfaces:
  java.util.EventListener, DropTargetListener, org.eclipse.swt.internal.SWTEventListener

    public class EditingDomainViewerDropAdapter

extends DropTargetAdapter

This implementation of a drop target listener is designed to turn a drag and drop operation into a `Command` based on the model objects of an `EditingDomain` and created by `DragAndDropCommand.create(org.eclipse.emf.edit.domain.EditingDomain, java.lang.Object, float, int, int, java.util.Collection<?>)`. It is designed to do early data transfer so the the enablement and feedback of the drag and drop interaction can intimately depend on the state of the model objects involved. On some platforms, however, early data transfer is not available, so this feedback cannot be provided.

The base implementation of this class should be sufficient for most applications. Any change in behaviour is typically accomplished by overriding `ItemProviderAdapter`.createDragAndDropCommand to return a derived implementation of `DragAndDropCommand`. This is how one these adapters is typically hooked up:

       viewer.addDropSupport
         (DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK,
          new Transfer [] { LocalTransfer.getInstance() },
          EditingDomainViewerDropAdapter(viewer));

This implementation prefers to use a `LocalTransfer`, which short-circuits the transfer process for simple transfers within the workbench, the method `getDragSource(org.eclipse.swt.dnd.DropTargetEvent)` can be overridden to change the behaviour. The implementation also only handles an `IStructuredSelection`, but the method `extractDragSource(java.lang.Object)` can be overridden to change the behaviour.

SWT's `auto-scroll` and `auto-expand` (hover) are enabled by default. The method `getAutoFeedback()` can be overridden to change this behaviour.

Nested Class Summary
`protected static class` `EditingDomainViewerDropAdapter.DragAndDropCommandInformation` This holds all of the information used to create a `DragAndDropCommand`, but does not need to be disposed.

Field Summary
`protected Command` `command` This is the command created during dragging which provides the feedback and will carry out the action upon completion.
`protected java.lang.Object` `commandTarget` This records the object for which the `command` was created.
`protected EditingDomain` `domain` This is the domain in which drag and drop commands will be executed.
`protected EditingDomainViewerDropAdapter.DragAndDropCommandInformation` `dragAndDropCommandInformation` This keeps track of the information used to create `command`, but does not need to be disposed.
`protected static boolean` `IS_MOTIF` This indicates whether the current platform is motif, which needs special treatment, since it cannot do early data transfer, but doesn't cleanly return null either.
`protected int` `originalOperation` This keeps track of the original operation that the user requested, before we started changing the event.detail.
`protected java.util.Collection<?>` `source` This is the collection of source objects being dragged.
`protected Viewer` `viewer` This is the viewer for which this is a drop target listener.

Constructor Summary
`EditingDomainViewerDropAdapter(EditingDomain domain, Viewer viewer)` This creates an instance with the given domain and viewer.

Method Summary
`void` `dragEnter(DropTargetEvent event)` This is called when the mouse first enters or starts dragging in the viewer.
`void` `dragLeave(DropTargetEvent event)` This is called when the mouse leaves or stops dragging in the viewer, whether the operation was aborted or is about to do a dropAccept and drop.
`void` `dragOperationChanged(DropTargetEvent event)` This is called when the operation has changed in some way, typically because the user changes keyboard modifiers.
`void` `dragOver(DropTargetEvent event)` This is called repeatedly, as the mouse moves over the viewer.
`void` `drop(DropTargetEvent event)` This is called to indicate that the drop action should be invoked.
`void` `dropAccept(DropTargetEvent event)` This is called when the mouse is released over the viewer to initiate a drop, between dragLeave and drop.
`protected java.util.Collection<?>` `extractDragSource(java.lang.Object object)` This extracts a collection of dragged source objects from the given object retrieved from the transfer agent.
`protected java.lang.Object` `extractDropTarget(Widget item)` This extracts an object from the given item widget, providing the special support required by an `ExtendedTableTreeViewer.ExtendedTableTreeItem`.
`protected int` `getAutoFeedback()` This returns the bitwise OR'ed flags for desired auto-feedback effects.
`protected java.util.Collection<?>` `getDragSource(DropTargetEvent event)` This attempts to extract the drag source from the event early, i.e., before the drop method.
`protected float` `getLocation(DropTargetEvent event)` This returns the location of the mouse in the vertical direction, relative to the item widget, from 0 (top) to 1 (bottom).
`protected void` `helper(DropTargetEvent event)` This method is called the same way for each of the `DropTargetListener` methods, except for leave and drop.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### IS_MOTIF

    protected static final boolean IS_MOTIF

  This indicates whether the current platform is motif, which needs special treatment, since it cannot do early data transfer, but doesn't cleanly return null either.

### viewer

    protected Viewer viewer

  This is the viewer for which this is a drop target listener.

### domain

    protected EditingDomain domain

  This is the domain in which drag and drop commands will be executed.

### source

    protected java.util.Collection<?> source

  This is the collection of source objects being dragged.

### command

    protected Command command

  This is the command created during dragging which provides the feedback and will carry out the action upon completion.

### commandTarget

    protected java.lang.Object commandTarget

  This records the object for which the `command` was created.

### originalOperation

    protected int originalOperation

  This keeps track of the original operation that the user requested, before we started changing the event.detail. We always try to create the command using this.

### dragAndDropCommandInformation

    protected EditingDomainViewerDropAdapter.DragAndDropCommandInformation dragAndDropCommandInformation

  This keeps track of the information used to create `command`, but does not need to be disposed. This allows us to dispose of the command in dragLeave, and then, if we need to execute it, recreate it in drop.

Constructor Detail

### EditingDomainViewerDropAdapter

    public EditingDomainViewerDropAdapter(EditingDomain domain,
                                          Viewer viewer)

  This creates an instance with the given domain and viewer.

Method Detail

### dragEnter

    public void dragEnter(DropTargetEvent event)

  This is called when the mouse first enters or starts dragging in the viewer.

  Specified by:
    `dragEnter` in interface `DropTargetListener`
  Overrides:
    `dragEnter` in class `DropTargetAdapter`

### dragLeave

    public void dragLeave(DropTargetEvent event)

  This is called when the mouse leaves or stops dragging in the viewer, whether the operation was aborted or is about to do a dropAccept and drop. The event argument is uninitialized, so it is impossible to distinguish between the two cases. So, we do the clean-up now and recreate the command later, if necessary.

  Specified by:
    `dragLeave` in interface `DropTargetListener`
  Overrides:
    `dragLeave` in class `DropTargetAdapter`

### dragOperationChanged

    public void dragOperationChanged(DropTargetEvent event)

  This is called when the operation has changed in some way, typically because the user changes keyboard modifiers.

  Specified by:
    `dragOperationChanged` in interface `DropTargetListener`
  Overrides:
    `dragOperationChanged` in class `DropTargetAdapter`

### dragOver

    public void dragOver(DropTargetEvent event)

  This is called repeatedly, as the mouse moves over the viewer.

  Specified by:
    `dragOver` in interface `DropTargetListener`
  Overrides:
    `dragOver` in class `DropTargetAdapter`

### dropAccept

    public void dropAccept(DropTargetEvent event)

  This is called when the mouse is released over the viewer to initiate a drop, between dragLeave and drop.

  Specified by:
    `dropAccept` in interface `DropTargetListener`
  Overrides:
    `dropAccept` in class `DropTargetAdapter`

### drop

    public void drop(DropTargetEvent event)

  This is called to indicate that the drop action should be invoked.

  Specified by:
    `drop` in interface `DropTargetListener`
  Overrides:
    `drop` in class `DropTargetAdapter`

### helper

    protected void helper(DropTargetEvent event)

  This method is called the same way for each of the `DropTargetListener` methods, except for leave and drop. If the source is available early, it creates or revalidates the `DragAndDropCommand`, and updates the event's detail (operation) and feedback (drag under effect), appropriately.

### getAutoFeedback

    protected int getAutoFeedback()

  This returns the bitwise OR'ed flags for desired auto-feedback effects. Drag under effect DND constants are always OR'ed with this to enable them. This implementation enables `auto-scroll` and `auto-expand` (hover).

### getDragSource

    protected java.util.Collection<?> getDragSource(DropTargetEvent event)

  This attempts to extract the drag source from the event early, i.e., before the drop method. This implementation tries to use a `LocalTransfer`. If the data is not yet available (e.g. on platforms other than win32), it just returns null.

### extractDragSource

    protected java.util.Collection<?> extractDragSource(java.lang.Object object)

  This extracts a collection of dragged source objects from the given object retrieved from the transfer agent. This default implementation converts a structured selection into a collection of elements.

### extractDropTarget

    protected java.lang.Object extractDropTarget(Widget item)

  This extracts an object from the given item widget, providing the special support required by an `ExtendedTableTreeViewer.ExtendedTableTreeItem`.

### getLocation

    protected float getLocation(DropTargetEvent event)

  This returns the location of the mouse in the vertical direction, relative to the item widget, from 0 (top) to 1 (bottom).

Copyright 2001-2006 IBM Corporation and others. All Rights Reserved.