Search in sources :

Example 1 with TableDropTargetEffect

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);
}
Also used : CommonViewer(org.eclipse.ui.navigator.CommonViewer) TableItem(org.eclipse.swt.widgets.TableItem) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBColumnRepNode(org.talend.dq.nodes.DBColumnRepNode) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DropTarget(org.eclipse.swt.dnd.DropTarget) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) TableDropTargetEffect(org.eclipse.swt.dnd.TableDropTargetEffect)

Aggregations

LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 DropTarget (org.eclipse.swt.dnd.DropTarget)1 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)1 DropTargetListener (org.eclipse.swt.dnd.DropTargetListener)1 TableDropTargetEffect (org.eclipse.swt.dnd.TableDropTargetEffect)1 Transfer (org.eclipse.swt.dnd.Transfer)1 TableItem (org.eclipse.swt.widgets.TableItem)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 CommonViewer (org.eclipse.ui.navigator.CommonViewer)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)1 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)1 DBColumnRepNode (org.talend.dq.nodes.DBColumnRepNode)1