Drag and Drop should involve two listeners.
One on the component that start the drag, and an other one on the component where the drop is done.
source.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
// Only start the drag if needed
if (iDoNotNeedToStartTheDrag) {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
// Provide the data of the requested type.
if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = "the data to transfert";
}
}
public void dragFinished(DragSourceEvent event) {
// At the end of the drag, if we need to do something on the source
}
});
Then on the target :
target.addDropListener(new DropTargetListener() {
public void dragEnter(DropTargetEvent event) {
}
public void dragOver(DropTargetEvent event) {
}
public void dragOperationChanged(DropTargetEvent event) {
}
public void dragLeave(DropTargetEvent event) {
}
public void dropAccept(DropTargetEvent event) {
}
public void drop(DropTargetEvent event) {
// do what ever you want...
if (textTransfer.isSupportedType(event.currentDataType)) {
String text = (String)event.data;
TableItem item = new TableItem(dropTable, SWT.NONE);
item.setText(text);
}
if (fileTransfer.isSupportedType(event.currentDataType)){
String[] files = (String[])event.data;
for (int i = 0; i < files.length; i++) {
TableItem item = new TableItem(dropTable, SWT.NONE);
item.setText(files[i]);
}
}
}
});