|
|||||||||
| Home >> All >> org >> eclipse >> jface >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.eclipse.jface.util
Class DelegatingDragAdapter

java.lang.Objectorg.eclipse.jface.util.DelegatingDragAdapter
- All Implemented Interfaces:
- org.eclipse.swt.dnd.DragSourceListener, java.util.EventListener, org.eclipse.swt.internal.SWTEventListener
- public class DelegatingDragAdapter
- extends java.lang.Object
- implements org.eclipse.swt.dnd.DragSourceListener
- extends java.lang.Object
A DelegatingDragAdapter is a DragSourceListener that
maintains and delegates to a set of TransferDragSourceListeners. Each
TransferDragSourceListener can then be implemented as if it were the
DragSource's only DragSourceListener.
When a drag is started, a subset of all TransferDragSourceListeners
is generated and stored in a list of active listeners. This subset is
calculated by forwarding true.
DragSource's set of supported Transfer types ({@link
DragSource#setTransfer(Transfer[])}) is updated to reflect the Transfer types
corresponding to the active listener subset.
If and when {@link #dragSetData(DragSourceEvent)} is called, a single
TransferDragSourceListener is chosen, and only it is allowed to set the
drag data. The chosen listener is the first listener in the subset of active listeners
whose Transfer supports ({@link Transfer#isSupportedType(TransferData)}) the
dataType in the DragSourceEvent.
The following example snippet shows a DelegatingDragAdapter with two
TransferDragSourceListeners. One implements drag of text strings,
the other supports file transfer and demonstrates how a listener can be disabled using
the dragStart method.
final TreeViewer viewer = new TreeViewer(shell, SWT.NONE);
DelegatingDragAdapter dragAdapter = new DelegatingDragAdapter();
dragAdapter.addDragSourceListener(new TransferDragSourceListener() {
public Transfer getTransfer() {
return TextTransfer.getInstance();
>to
every listener, and checking if the {@link DragSourceEvent#doit doit} field is left
set to true.
The DragSource's set of supported Transfer types ({@link
DragSource#setTransfer(Transfer[])}) is updated to reflect the Transfer types
corresponding to the active listener subset.
If and when {@link #dragSetData(DragSourceEvent)} is called, a single
TransferDragSourceListener is chosen, and only it is allowed to set the
drag data. The chosen listener is the first listener in the subset of active listeners
whose Transfer supports ({@link Transfer#isSupportedType(TransferData)}) the
dataType in the DragSourceEvent.
The following example snippet shows a DelegatingDragAdapter with two
TransferDragSourceListeners. One implements drag of text strings,
the other supports file transfer and demonstrates how a listener can be disabled using
the dragStart method.
final TreeViewer viewer = new TreeViewer(shell, SWT.NONE);
DelegatingDragAdapter dragAdapter = new DelegatingDragAdapter();
dragAdapter.addDragSourceListener(new TransferDragSourceListener() {
public Transfer getTransfer() {
return TextTransfer.getInstance();
55
public void dragStart(DragSourceEvent event) {
// always enabled, can control enablement based on selection etc.
}
public void dragSetData(DragSourceEvent event) {
event.data = "Transfer data";
}
public void dragFinished(DragSourceEvent event) {
// no clean-up required
}
});
dragAdapter.addDragSourceListener(new TransferDragSourceListener() {
public Transfer getTransfer() {
return FileTransfer.getInstance();
}
public void dragStart(DragSourceEvent event) {
// enable drag listener if there is a viewer selection
event.doit = !viewer.getSelection().isEmpty();
}
public void dragSetData(DragSourceEvent event) {
File file1 = new File("C:/temp/file1");
File file2 = new File("C:/temp/file2");
event.data = new String[] {file1.getAbsolutePath(), file2.getAbsolutePath()};
}
public void dragFinished(DragSourceEvent event) {
// no clean-up required
}
});
viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, dragAdapter.getTransfers(), dragAdapter);
NOTE: This API is experimental and subject to change including removal.
- Since:
- 2.2
Field Summary
private java.util.List
activeListeners
private TransferDragSourceListener
currentListener
private java.util.List
listeners
Constructor Summary
DelegatingDragAdapter()
Method Summary
void
addDragSourceListener(TransferDragSourceListener listener)
Adds the given TransferDragSourceListener.
void
dragFinished(org.eclipse.swt.dnd.DragSourceEvent event)
The drop has successfully completed.
void
dragSetData(org.eclipse.swt.dnd.DragSourceEvent event)
The drop data is requested.
void
dragStart(org.eclipse.swt.dnd.DragSourceEvent event)
A drag operation has started.
org.eclipse.swt.dnd.Transfer[]
getTransfers()
Returns the Transfers from every TransferDragSourceListener.
boolean
isEmpty()
Returns true if there are no listeners to delegate drag events to.
void
removeDragSourceListener(TransferDragSourceListener listener)
Removes the given TransferDragSourceListener.
private void
updateCurrentListener(org.eclipse.swt.dnd.DragSourceEvent event)
Updates the current listener to one that can handle the drag.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Field Detail
listeners
private java.util.List listeners
activeListeners
private java.util.List activeListeners
currentListener
private TransferDragSourceListener currentListener
Constructor Detail
DelegatingDragAdapter
public DelegatingDragAdapter()
Method Detail
addDragSourceListener
public void addDragSourceListener(TransferDragSourceListener listener)
- Adds the given
TransferDragSourceListener.
dragFinished
public void dragFinished(org.eclipse.swt.dnd.DragSourceEvent event)
- The drop has successfully completed. This event is forwarded to the current
drag listener.
Doesn't update the current listener, since the current listener is already the one
that completed the drag operation.
- Specified by:
dragFinished in interface org.eclipse.swt.dnd.DragSourceListener
dragSetData
public void dragSetData(org.eclipse.swt.dnd.DragSourceEvent event)
- The drop data is requested.
Updates the current listener and then forwards the event to it.
- Specified by:
dragSetData in interface org.eclipse.swt.dnd.DragSourceListener
dragStart
public void dragStart(org.eclipse.swt.dnd.DragSourceEvent event)
- A drag operation has started.
Forwards this event to each listener. A listener must set
event.doit
to false if it cannot handle the drag operation. If a listener can
handle the drag, it is added to the list of active listeners.
The drag is aborted if there are no listeners that can handle it.
- Specified by:
dragStart in interface org.eclipse.swt.dnd.DragSourceListener
getTransfers
public org.eclipse.swt.dnd.Transfer[] getTransfers()
- Returns the
Transfers from every TransferDragSourceListener.
isEmpty
public boolean isEmpty()
- Returns
true if there are no listeners to delegate drag events to.
removeDragSourceListener
public void removeDragSourceListener(TransferDragSourceListener listener)
- Removes the given
TransferDragSourceListener.
Listeners should not be removed while a drag and drop operation is in progress.
updateCurrentListener
private void updateCurrentListener(org.eclipse.swt.dnd.DragSourceEvent event)
- Updates the current listener to one that can handle the drag. There can
be many listeners and each listener may be able to handle many
TransferData
types. The first listener found that supports one of the TransferData
types specified in the DragSourceEvent will be selected.
Overview
Package
Class
Use
Deprecated
Index
Home >> All >> org >> eclipse >> jface >> [ util overview ]
PREV CLASS NEXT CLASS
SUMMARY:
JAVADOC |
SOURCE |
DOWNLOAD | NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
org.eclipse.jface.util.DelegatingDragAdapter