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:
org.eclipse.swt.dnd.DropTargetListener, java.util.EventListener, org.eclipse.swt.internal.SWTEventListener

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 involed.

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 overriden to change the behaviour. The implementation also only handles an IStructuredSelection, but the method extractDragSource(java.lang.Object) can be overriden to change the behaviour.

You can call setHoverThreshold(int) to set the amount of time, in milliseconds, to hover over an item before hover(java.lang.Object) is called; the default is 1500 milliseconds.


Inner Class Summary
protected static class EditingDomainViewerDropAdapter.DragAndDropCommandInformation
           
 
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 the current command.
protected  long hoverStart
          The is the time the mouse first started hovering over the current item.
protected  int hoverThreshold
          The amount of time to hover over a tree item before expanding it
protected  int originalOperation
          This keeps track of the original operation that was in effect before we set the event.detail in here.
protected  org.eclipse.swt.widgets.Widget previousItem
          This keeps track of the most recent item for the hoverStart.
protected  java.util.Collection source
          This is the collection of source objects being dragged.
protected  org.eclipse.jface.viewers.Viewer viewer
          This is the viewer for which this is a drop target listener.
 
Constructor Summary
EditingDomainViewerDropAdapter(EditingDomain domain, org.eclipse.jface.viewers.Viewer viewer)
          This creates and instance of 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
 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 repeated when the mouse over the viewer.
 void drop(org.eclipse.swt.dnd.DropTargetEvent event)
          This is called to indate that the drop action should be invoked.
 void dropAccept(org.eclipse.swt.dnd.DropTargetEvent event)
          This is called just as the mouse is released over the viewer to initiate a 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.util.Collection getDragSource(org.eclipse.swt.dnd.DropTargetEvent event)
          This attempts to extract the drag source from the event early, i.e., before the drop method.
 int getHoverThreshold()
          This gets the amount of time, in milliseconds, to hover over an item before hover(java.lang.Object) is called.
protected static float getLocation(org.eclipse.swt.dnd.DropTargetEvent event)
           
protected  void helper(org.eclipse.swt.dnd.DropTargetEvent event)
          This method is called the same way for each of the DropTargetListener methods, except during leave.
protected  void hover(java.lang.Object target)
          This is called when the cursor has hovered over the given target for longer than hoverThreshold.
protected  boolean scrollIfNeeded(org.eclipse.swt.dnd.DropTargetEvent event)
          This returns whether a scroll was performed based on the given drag coordinates.
 void setHoverThreshold(int hoverThreshold)
          This set the amount of time, in milliseconds, to hover over an item before hover(java.lang.Object) is called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

viewer

protected org.eclipse.jface.viewers.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.

hoverThreshold

protected int hoverThreshold
The amount of time to hover over a tree item before expanding it

hoverStart

protected long hoverStart
The is the time the mouse first started hovering over the current item.

previousItem

protected org.eclipse.swt.widgets.Widget previousItem
This keeps track of the most recent item for the hoverStart.

originalOperation

protected int originalOperation
This keeps track of the original operation that was in effect before we set the event.detail in here.

dragAndDropCommandInformation

protected EditingDomainViewerDropAdapter.DragAndDropCommandInformation dragAndDropCommandInformation
This keeps track of the information used to create the current command.
Constructor Detail

EditingDomainViewerDropAdapter

public EditingDomainViewerDropAdapter(EditingDomain domain,
                                      org.eclipse.jface.viewers.Viewer viewer)
This creates and instance of 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.
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
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.
Overrides:
dragOperationChanged in class org.eclipse.swt.dnd.DropTargetAdapter

dragOver

public void dragOver(org.eclipse.swt.dnd.DropTargetEvent event)
This is called repeated when the mouse over the viewer.
Overrides:
dragOver in class org.eclipse.swt.dnd.DropTargetAdapter

dropAccept

public void dropAccept(org.eclipse.swt.dnd.DropTargetEvent event)
This is called just as the mouse is released over the viewer to initiate a drop.
Overrides:
dropAccept in class org.eclipse.swt.dnd.DropTargetAdapter

drop

public void drop(org.eclipse.swt.dnd.DropTargetEvent event)
This is called to indate that the drop action should be invoked.
Overrides:
drop in class org.eclipse.swt.dnd.DropTargetAdapter

helper

protected void helper(org.eclipse.swt.dnd.DropTargetEvent event)
This method is called the same way for each of the DropTargetListener methods, except during leave.

getDragSource

protected java.util.Collection getDragSource(org.eclipse.swt.dnd.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.

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.

getHoverThreshold

public int getHoverThreshold()
This gets the amount of time, in milliseconds, to hover over an item before hover(java.lang.Object) is called.

setHoverThreshold

public void setHoverThreshold(int hoverThreshold)
This set the amount of time, in milliseconds, to hover over an item before hover(java.lang.Object) is called.

hover

protected void hover(java.lang.Object target)
This is called when the cursor has hovered over the given target for longer than hoverThreshold.

scrollIfNeeded

protected boolean scrollIfNeeded(org.eclipse.swt.dnd.DropTargetEvent event)
This returns whether a scroll was performed based on the given drag coordinates.

getLocation

protected static float getLocation(org.eclipse.swt.dnd.DropTargetEvent event)

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