public class EditingDomainViewerDropAdapter
extends DropTargetAdapter
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(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.
In EMF 2.9, this class was enhanced to also handle LocalSelectionTransfer
and FileTransfer
.
For the latter, the file names are converted to a list of URIs
by extractDragSource(java.lang.Object)
.
SWT's auto-scroll
and auto-expand
(hover) are enabled by default. The method getAutoFeedback()
can be overridden
to change this behaviour.
Modifier and Type | Class and Description |
---|---|
protected static class |
EditingDomainViewerDropAdapter.DragAndDropCommandInformation
This holds all of the information used to create a
DragAndDropCommand , but does not need to be disposed. |
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
EditingDomainViewerDropAdapter(EditingDomain domain,
Viewer viewer)
This creates an instance with the given domain and viewer.
|
Modifier and Type | Method and Description |
---|---|
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
org.eclipse.swt.dnd.DropTargetListener methods, except for leave
and drop. |
protected static final boolean IS_MOTIF
protected Viewer viewer
protected EditingDomain domain
protected java.util.Collection<?> source
protected Command command
protected java.lang.Object commandTarget
command
was created.protected int originalOperation
protected EditingDomainViewerDropAdapter.DragAndDropCommandInformation dragAndDropCommandInformation
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.public EditingDomainViewerDropAdapter(EditingDomain domain, Viewer viewer)
public void dragEnter(DropTargetEvent event)
public void dragLeave(DropTargetEvent event)
public void dragOperationChanged(DropTargetEvent event)
public void dragOver(DropTargetEvent event)
public void dropAccept(DropTargetEvent event)
public void drop(DropTargetEvent event)
protected void helper(DropTargetEvent event)
org.eclipse.swt.dnd.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.protected int getAutoFeedback()
auto-scroll
and
auto-expand
(hover).protected java.util.Collection<?> getDragSource(DropTargetEvent event)
LocalTransfer
. If the data is not yet
available (e.g. on platforms other than win32), it just returns null.protected java.util.Collection<?> extractDragSource(java.lang.Object object)
structured selection
into a collection of elements.
As of EMF 2.9,
an array of strings is converted to a collection of file URI
s
and each IResource
in a selection is converted to a URI
.protected java.lang.Object extractDropTarget(Widget item)
ExtendedTableTreeViewer.ExtendedTableTreeItem
.protected float getLocation(DropTargetEvent event)