我想在星云网格上实现拖放。我找到了侦听器DragDetectListener
,但我不知道如何找到目标(这是我要释放行的位置)。我不能使用SWT表,因为必须使用星云网格。
更清楚:
我有一个N行的星云网格,我想在其他两行之间拖动其中一行。我知道我已经搬走的那排。我怎样才能使该行掉下去?
拖放应包含两个侦听器。一个在开始拖动的组件上,另一个在完成放置的组件上。
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
}
});
然后在目标上:
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]);
}
}
}
});