*代码示例,为Control添加Drop支持 DropTarget示例int ops = DND.DROP_COPY;Transfer[] transfers = new Transfer[]{ Lo...
*代码示例,为Control添加Drop支持
DropTarget示例int ops = DND.DROP_COPY; Transfer[] transfers = new Transfer[]{ LocalSelectionTransfer.getInstance(), }; DropTarget target =new DropTarget(YourControl,ops); //定义DropTarget target.setTransfer(transfers); target.addDropListener(new DropTargetAdapter(){ public void dragEnter(DropTargetEvent event) { if(event.operations==DND.DROP_COPY) event.detail =DND.DROP_COPY; else event.detail =DND.DROP_NONE; //否决drop } public void drop(DropTargetEvent event) { if(LocalSelectionTransfer.getInstance().isSupportedType(event.currentDataType)){ if(event.data instanceof IStructuredSelection){ Object obj =((IStructuredSelection)event.data).getFirstElement(); //TODO 实现代码 } } public void dropAccept(DropTargetEvent event) { if (event.operations == DND.DROP_COPY) event.detail = DND.DROP_COPY; else event.detail = DND.DROP_NONE; } }