我正在SWT中实现拖放功能。
这是我的代码段
拖动
private class MyDragSourceAdapter extends DragSourceAdapter {
/** The m tree viewer. */
private final TreeViewer treeViewer;
/**
* Instantiates a new my drag source adapter.
*
* @param treeViewer the tree viewer
*/
public MyDragSourceAdapter(TreeViewer treeViewer) {
this.treeViewer = treeViewer;
}
/**
* {@inheritDoc}
*/
@Override
public void dragFinished(DragSourceEvent event) {
// clean buffer
// k = null;
}
/**
* {@inheritDoc}
*/
@Override
public void dragSetData(DragSourceEvent event) {
event.data = "test";
}
/**
* {@inheritDoc}
*/
@Override
public void dragStart(DragSourceEvent event) {
if (some condition) {
// do something
return;
}
event.doit = false;
}
}
要放弃
private class MyDropTargetAdapter extends DropTargetAdapter {
@Override
public void dragEnter(DropTargetEvent event) {
event.detail = DND.DROP_LINK;
}
/**
* {@inheritDoc}
*/
@Override
public void dragOver(DropTargetEvent event) {
// Do some functionality
}
/**
* {@inheritDoc}
*/
@Override
public void drop(DropTargetEvent event) {
event.detail = DND.DROP_NONE;
}
}
有时候" dragOver()" 方法被多次调用?所以拖动发生的次数与dragOver()方法一样多。
我想在第一次停止后停止操作。
请帮忙
答案 0 :(得分:1)
dragOver()
。您可能想要覆盖drop()
。但是,如果您希望停止发生停止,请将detail
上的字段DropTargetEvent
设置为DND.DROP_NONE
。