Search in sources :

Example 1 with AbstractSelectionReceiver

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);
}
Also used : AbstractSelectionReceiver(org.talend.dataprofiler.core.ui.views.AbstractSelectionReceiver) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) ArrayList(java.util.ArrayList) List(java.util.List) DropTarget(org.eclipse.swt.dnd.DropTarget) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 DropTarget (org.eclipse.swt.dnd.DropTarget)1 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)1 DropTargetListener (org.eclipse.swt.dnd.DropTargetListener)1 TableItem (org.eclipse.swt.widgets.TableItem)1 AbstractSelectionReceiver (org.talend.dataprofiler.core.ui.views.AbstractSelectionReceiver)1