Search in sources :

Example 1 with DQRuleEditor

use of org.talend.dataprofiler.core.ui.editor.dqrules.DQRuleEditor in project tdq-studio-se by Talend.

the class WhereClauseDND method installDND.

public static void installDND(final Text 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);
    dropTarget.addDropListener(new DropTargetAdapter() {

        @Override
        public void dragEnter(DropTargetEvent event) {
            Object obj = ((IStructuredSelection) commonViewer.getSelection()).getFirstElement();
            if (!(obj instanceof DBColumnRepNode)) {
                event.detail = DND.DROP_NONE;
            } else {
                // event.detail = DND.DROP_MOVE;
                event.feedback = DND.FEEDBACK_INSERT_AFTER;
            }
        }

        @Override
        public void dropAccept(DropTargetEvent event) {
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (event.detail != DND.DROP_NONE) {
                IStructuredSelection selection = (IStructuredSelection) commonViewer.getSelection();
                if (!selection.isEmpty()) {
                    Iterator<DBColumnRepNode> it = selection.iterator();
                    IEditorPart currentActiveEditor = CorePlugin.getDefault().getCurrentActiveEditor();
                    if (currentActiveEditor instanceof DQRuleEditor) {
                        // // Analysis analysis = AnaResourceFileHelper.getInstance().findAnalysis(input.getFile());
                        while (it.hasNext()) {
                            // DbmsLanguage language = DbmsLanguageFactory.createDbmsLanguage(lang, null);
                            DBColumnRepNode next = it.next();
                            String name = next.getTdColumn().getName();
                            targetControl.insert(name);
                            targetControl.forceFocus();
                        }
                    }
                }
            }
        }
    });
}
Also used : CommonViewer(org.eclipse.ui.navigator.CommonViewer) DQRuleEditor(org.talend.dataprofiler.core.ui.editor.dqrules.DQRuleEditor) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DBColumnRepNode(org.talend.dq.nodes.DBColumnRepNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Iterator(java.util.Iterator) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DropTarget(org.eclipse.swt.dnd.DropTarget) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer)

Aggregations

Iterator (java.util.Iterator)1 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 DropTarget (org.eclipse.swt.dnd.DropTarget)1 DropTargetAdapter (org.eclipse.swt.dnd.DropTargetAdapter)1 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)1 Transfer (org.eclipse.swt.dnd.Transfer)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 CommonViewer (org.eclipse.ui.navigator.CommonViewer)1 DQRuleEditor (org.talend.dataprofiler.core.ui.editor.dqrules.DQRuleEditor)1 DBColumnRepNode (org.talend.dq.nodes.DBColumnRepNode)1