use of org.talend.dataprofiler.core.ui.views.AbstractSelectionReceiver in project tdq-studio-se by Talend.
the class ComparisonTableViewerDNDDecorate method installDND.
/**
* Install a drag&drop function for target table viewer.
*
* @param targetViewer the target table viewer for installing drag&drop, it's input value must a <code>List</code>
* type.
* @param installDragListener decide to whether install a drag listener for targetViewer: if true, will install the
* listener; else, will not install.
* @param validateType
* @see ComparisonTableViewerDNDDecorate#NON_VALIDATETYPE
* @see ComparisonTableViewerDNDDecorate#COLUMN_VALIDATETYPE
*/
public void installDND(final TableViewer targetViewer, final boolean installDragListener, final int validateType, final boolean isLeftPart) {
int operations = DND.DROP_COPY | DND.DROP_MOVE;
if (installDragListener) {
installDragListener(targetViewer, operations);
}
DropTarget dropTarget = new DropTarget(targetViewer.getTable(), operations);
dropTarget.setTransfer(transferTypes);
DropTargetListener dndListener = new AbstractSelectionReceiver(targetViewer.getTable(), null) {
@Override
@SuppressWarnings("unchecked")
public void drop(DropTargetEvent event, LocalSelectionTransfer transfer) {
List inputElements = (List) targetViewer.getInput();
// MOD mzhao bug:12766,Avoid an null pointer exception error.
if (inputElements == null) {
inputElements = new ArrayList();
}
if (dragSelectedElement != null) {
TableItem item = (TableItem) event.item;
TableItem[] items = targetViewer.getTable().getItems();
int index = 0;
for (int i = 0; i < items.length; i++) {
if (items[i] == item) {
index = i;
break;
}
}
inputElements.remove(dragSelectedElement);
inputElements.add(index, dragSelectedElement);
dragSelectedElement = null;
} else {
StructuredSelection selection = (StructuredSelection) transfer.getSelection();
List selectionElements = selection.toList();
inputElements.addAll(selectionElements);
}
targetViewer.setInput(inputElements);
// Update connection widget.
compareTreeViewer.updateBindConnection(masterPage, tableViewerPosStack);
compareTreeViewer.setDirty(true);
// TDQ-11606 msjian: when add a column, will update the datapreview part
compareTreeViewer.computeRefreshDataPreviewPart(isLeftPart, inputElements, targetViewer);
}
@Override
public boolean doDropValidation(DropTargetEvent event, LocalSelectionTransfer transfer) {
StructuredSelection selection = (StructuredSelection) transfer.getSelection();
if (dragSelectedElement != null && selection != null) {
return true;
}
// boolean doDropValidation = super.doDropValidation(event, transfer);
boolean doDropValidation = false;
// if (doDropValidation) {
switch(validateType) {
case COLUMN_VALIDATETYPE:
doDropValidation = validateColumnType(selection, targetViewer);
break;
default:
doDropValidation = true;
}
// }
return doDropValidation;
}
};
dropTarget.addDropListener(dndListener);
}
Aggregations