// Allow data to be copied or moved to the drop target
int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT;
DropTarget target = new DropTarget(tree, operations);
// Receive data in Text or File format
final FileTransfer fileTransfer = FileTransfer.getInstance();
Transfer[] types = new Transfer[] { fileTransfer };
target.setTransfer(types);
target.addDropListener(new DropTargetListener() {
public void dragEnter(DropTargetEvent event) {
if (event.detail == DND.DROP_DEFAULT) {
if ((event.operations & DND.DROP_COPY) != 0) {
event.detail = DND.DROP_COPY;
} else {
event.detail = DND.DROP_NONE;
}
}
// will accept text but prefer to have files dropped
for (int i = 0; i < event.dataTypes.length; i++) {
if (fileTransfer.isSupportedType(event.dataTypes[i])) {
event.currentDataType = event.dataTypes[i];
// files should only be copied
if (event.detail != DND.DROP_COPY) {
event.detail = DND.DROP_NONE;
}
break;
}
}
}
public void dragOver(DropTargetEvent event) {
}
public void dragOperationChanged(DropTargetEvent event) {
if (event.detail == DND.DROP_DEFAULT) {
if ((event.operations & DND.DROP_COPY) != 0) {
event.detail = DND.DROP_COPY;
} else {
event.detail = DND.DROP_NONE;
}
}
// allow text to be moved but files should only be copied
if (fileTransfer.isSupportedType(event.currentDataType)) {
if (event.detail != DND.DROP_COPY) {
event.detail = DND.DROP_NONE;
}
}
}
public void dragLeave(DropTargetEvent event) {
}
public void dropAccept(DropTargetEvent event) {
}
public void drop(DropTargetEvent event) {
if (fileTransfer.isSupportedType(event.currentDataType)) {
String[] files = (String[]) event.data;
if (files.length == 1) {
File file = new File(files[0]);
if (file.isDirectory()) {
PySourceLocatorBase locator = new PySourceLocatorBase();