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

java.lang.Object
  extended by org.eclipse.swt.dnd.DropTargetAdapter
      extended by org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter
All Implemented Interfaces:
EventListener, org.eclipse.swt.dnd.DropTargetListener, org.eclipse.swt.internal.SWTEventListener
Direct Known Subclasses:
ECPDropAdapter

public class EditingDomainViewerDropAdapter
extends org.eclipse.swt.dnd.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.


Constructor Summary
EditingDomainViewerDropAdapter(org.eclipse.emf.edit.domain.EditingDomain domain, org.eclipse.jface.viewers.Viewer viewer)
          This creates an instance with the given domain and viewer.
 
Method Summary
 void dragEnter(org.eclipse.swt.dnd.DropTargetEvent event)
          This is called when the mouse first enters or starts dragging in the viewer.
 void dragLeave(org.eclipse.swt.dnd.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(org.eclipse.swt.dnd.DropTargetEvent event)
          This is called when the operation has changed in some way, typically because the user changes keyboard modifiers.
 void dragOver(org.eclipse.swt.dnd.DropTargetEvent event)
          This is called repeatedly, as the mouse moves over the viewer.
 void drop(org.eclipse.swt.dnd.DropTargetEvent event)
          This is called to indicate that the drop action should be invoked.
 void dropAccept(org.eclipse.swt.dnd.DropTargetEvent event)
          This is called when the mouse is released over the viewer to initiate a drop, between dragLeave and drop.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EditingDomainViewerDropAdapter

public EditingDomainViewerDropAdapter(org.eclipse.emf.edit.domain.EditingDomain domain,
                                      org.eclipse.jface.viewers.Viewer viewer)
This creates an instance with the given domain and viewer.

Method Detail

dragEnter

public void dragEnter(org.eclipse.swt.dnd.DropTargetEvent event)
This is called when the mouse first enters or starts dragging in the viewer.

Specified by:
dragEnter in interface org.eclipse.swt.dnd.DropTargetListener
Overrides:
dragEnter in class org.eclipse.swt.dnd.DropTargetAdapter

dragLeave

public void dragLeave(org.eclipse.swt.dnd.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 org.eclipse.swt.dnd.DropTargetListener
Overrides:
dragLeave in class org.eclipse.swt.dnd.DropTargetAdapter

dragOperationChanged

public void dragOperationChanged(org.eclipse.swt.dnd.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 org.eclipse.swt.dnd.DropTargetListener
Overrides:
dragOperationChanged in class org.eclipse.swt.dnd.DropTargetAdapter

dragOver

public void dragOver(org.eclipse.swt.dnd.DropTargetEvent event)
This is called repeatedly, as the mouse moves over the viewer.

Specified by:
dragOver in interface org.eclipse.swt.dnd.DropTargetListener
Overrides:
dragOver in class org.eclipse.swt.dnd.DropTargetAdapter

dropAccept

public void dropAccept(org.eclipse.swt.dnd.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 org.eclipse.swt.dnd.DropTargetListener
Overrides:
dropAccept in class org.eclipse.swt.dnd.DropTargetAdapter

drop

public void drop(org.eclipse.swt.dnd.DropTargetEvent event)
This is called to indicate that the drop action should be invoked.

Specified by:
drop in interface org.eclipse.swt.dnd.DropTargetListener
Overrides:
drop in class org.eclipse.swt.dnd.DropTargetAdapter


Copyright © 2014. All Rights Reserved.