DropTarget target = new DropTarget(control, operations);
final TextTransfer textTransfer = TextTransfer.getInstance();
final FileTransfer fileTransfer = FileTransfer.getInstance();
final URLTransfer urlTransfer = URLTransfer.getInstance();
final UDigByteAndLocalTransfer omsboxTransfer = UDigByteAndLocalTransfer.getInstance();
Transfer[] types = new Transfer[]{fileTransfer, textTransfer, urlTransfer, omsboxTransfer};
target.setTransfer(types);
target.addDropListener(new DropTargetListener(){
@SuppressWarnings("nls")
public void drop( DropTargetEvent event ) {
if (textTransfer.isSupportedType(event.currentDataType)) {
String text = (String) event.data;
System.out.println(text);
}
if (fileTransfer.isSupportedType(event.currentDataType)) {
String[] files = (String[]) event.data;
if (files.length > 0) {
File file = new File(files[0]);
if (file.exists()) {
addFileToViewer(file);
OmsBoxPlugin.getDefault().setLastFolderChosen(file.getParentFile().getAbsolutePath());
}
}
}
if (urlTransfer.isSupportedType(event.currentDataType)) {
Object data2 = event.data;
System.out.println(data2);
}
if (omsboxTransfer.isSupportedType(event.currentDataType)) {
try {
Object data = event.data;
if (data instanceof TreeSelection) {
TreeSelection selection = (TreeSelection) data;
Object firstElement = selection.getFirstElement();