use of org.eclipse.swt.dnd.TableDropTargetEffect in project tdq-studio-se by Talend.
the class ColumnViewerDND method installDND.
/**
* DOC xqliu Comment method "installDND". bug 8791 2009-08-31.
*
* @param myTable
*/
public static void installDND(final Table targetControl) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
final CommonViewer commonViewer = findView.getCommonViewer();
final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
int operations = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] { transfer };
DropTarget dropTarget = new DropTarget(targetControl, operations);
dropTarget.setTransfer(transfers);
DropTargetListener dndListener = new TableDropTargetEffect(targetControl) {
ISelectionReceiver receiver = null;
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
Object object = selection.getFirstElement();
// MOD klliu 2011-03-08 bug 19286
if (object instanceof DBColumnRepNode) {
receiver = new ColumnReceiverTable();
}
if (receiver == null) {
event.detail = DND.DROP_NONE;
} else {
event.feedback = DND.FEEDBACK_EXPAND;
receiver.doDropValidation(event, commonViewer);
}
}
@Override
public void dragOver(DropTargetEvent event) {
if (receiver == null) {
return;
}
super.dragOver(event);
receiver.doDropValidation(event, commonViewer);
}
@Override
public void drop(DropTargetEvent event) {
if (receiver == null) {
return;
}
int index = targetControl.getItemCount();
super.drop(event);
if (event.item == null) {
index = -1;
} else {
// Widget widget = event.widget;
// Object data = event.data;
TableItem item = (TableItem) event.item;
TableItem[] items = targetControl.getItems();
for (int i = 0; i < items.length; i++) {
if (items[i] == item) {
index = i;
break;
}
}
}
receiver.drop(event, commonViewer, index);
}
};
dropTarget.addDropListener(dndListener);
}
Aggregations