Search in sources :

Example 21 with DropTargetListener

use of org.eclipse.swt.dnd.DropTargetListener 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)

Example 22 with DropTargetListener

use of org.eclipse.swt.dnd.DropTargetListener in project pentaho-kettle by pentaho.

the class RipDatabaseWizardPage2 method createControl.

public void createControl(Composite parent) {
    shell = parent.getShell();
    int margin = Const.MARGIN;
    // create the composite to hold the widgets
    Composite composite = new Composite(parent, SWT.NONE);
    props.setLook(composite);
    FormLayout compLayout = new FormLayout();
    compLayout.marginHeight = Const.FORM_MARGIN;
    compLayout.marginWidth = Const.FORM_MARGIN;
    composite.setLayout(compLayout);
    // Put it all on the composite!
    // //////////////////////////////////////////////////
    // Top & Bottom regions.
    // //////////////////////////////////////////////////
    Composite top = new Composite(composite, SWT.NONE);
    FormLayout topLayout = new FormLayout();
    topLayout.marginHeight = margin;
    topLayout.marginWidth = margin;
    top.setLayout(topLayout);
    FormData fdTop = new FormData();
    fdTop.left = new FormAttachment(0, 0);
    fdTop.top = new FormAttachment(0, 0);
    fdTop.right = new FormAttachment(100, 0);
    fdTop.bottom = new FormAttachment(100, -50);
    top.setLayoutData(fdTop);
    props.setLook(top);
    Composite bottom = new Composite(composite, SWT.NONE);
    bottom.setLayout(new FormLayout());
    FormData fdBottom = new FormData();
    fdBottom.left = new FormAttachment(0, 0);
    fdBottom.top = new FormAttachment(top, 0);
    fdBottom.right = new FormAttachment(100, 0);
    fdBottom.bottom = new FormAttachment(100, 0);
    bottom.setLayoutData(fdBottom);
    props.setLook(bottom);
    // //////////////////////////////////////////////////
    // Sashform
    // //////////////////////////////////////////////////
    SashForm sashform = new SashForm(top, SWT.HORIZONTAL);
    sashform.setLayout(new FormLayout());
    FormData fdSashform = new FormData();
    fdSashform.left = new FormAttachment(0, 0);
    fdSashform.top = new FormAttachment(0, 0);
    fdSashform.right = new FormAttachment(100, 0);
    fdSashform.bottom = new FormAttachment(100, 0);
    sashform.setLayoutData(fdSashform);
    // ////////////////////////
    // / LEFT
    // ////////////////////////
    Composite leftsplit = new Composite(sashform, SWT.NONE);
    leftsplit.setLayout(new FormLayout());
    FormData fdLeftsplit = new FormData();
    fdLeftsplit.left = new FormAttachment(0, 0);
    fdLeftsplit.top = new FormAttachment(0, 0);
    fdLeftsplit.right = new FormAttachment(100, 0);
    fdLeftsplit.bottom = new FormAttachment(100, 0);
    leftsplit.setLayoutData(fdLeftsplit);
    props.setLook(leftsplit);
    // Source list to the left...
    wlListSource = new Label(leftsplit, SWT.NONE);
    wlListSource.setText("Available items:");
    props.setLook(wlListSource);
    FormData fdlListSource = new FormData();
    fdlListSource.left = new FormAttachment(0, 0);
    fdlListSource.top = new FormAttachment(0, 0);
    wlListSource.setLayoutData(fdlListSource);
    wListSource = new List(leftsplit, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    props.setLook(wListSource);
    FormData fdListSource = new FormData();
    fdListSource.left = new FormAttachment(0, 0);
    fdListSource.top = new FormAttachment(wlListSource, 0);
    fdListSource.right = new FormAttachment(100, 0);
    fdListSource.bottom = new FormAttachment(100, 0);
    wListSource.setLayoutData(fdListSource);
    // /////////////////////////
    // MIDDLE
    // /////////////////////////
    Composite compmiddle = new Composite(sashform, SWT.NONE);
    compmiddle.setLayout(new FormLayout());
    FormData fdCompMiddle = new FormData();
    fdCompMiddle.left = new FormAttachment(0, 0);
    fdCompMiddle.top = new FormAttachment(0, 0);
    fdCompMiddle.right = new FormAttachment(100, 0);
    fdCompMiddle.bottom = new FormAttachment(100, 0);
    compmiddle.setLayoutData(fdCompMiddle);
    props.setLook(compmiddle);
    wAddOne = new Button(compmiddle, SWT.PUSH);
    wAddOne.setText(" > ");
    wAddOne.setToolTipText("Add the selected items on the left.");
    wAddAll = new Button(compmiddle, SWT.PUSH);
    wAddAll.setText(" >> ");
    wAddAll.setToolTipText("Add all items on the left.");
    wRemoveOne = new Button(compmiddle, SWT.PUSH);
    wRemoveOne.setText(" < ");
    wRemoveOne.setToolTipText("Remove the selected items on the right.");
    wRemoveAll = new Button(compmiddle, SWT.PUSH);
    wRemoveAll.setText(" << ");
    wRemoveAll.setToolTipText("Add all items on the right.");
    FormData fdAddOne = new FormData();
    fdAddOne.left = new FormAttachment(compmiddle, 0, SWT.CENTER);
    fdAddOne.top = new FormAttachment(30, 0);
    wAddOne.setLayoutData(fdAddOne);
    FormData fdAddAll = new FormData();
    fdAddAll.left = new FormAttachment(compmiddle, 0, SWT.CENTER);
    fdAddAll.top = new FormAttachment(wAddOne, margin);
    wAddAll.setLayoutData(fdAddAll);
    FormData fdRemoveAll = new FormData();
    fdRemoveAll.left = new FormAttachment(compmiddle, 0, SWT.CENTER);
    fdRemoveAll.top = new FormAttachment(wAddAll, margin);
    wRemoveAll.setLayoutData(fdRemoveAll);
    FormData fdRemoveOne = new FormData();
    fdRemoveOne.left = new FormAttachment(compmiddle, 0, SWT.CENTER);
    fdRemoveOne.top = new FormAttachment(wRemoveAll, margin);
    wRemoveOne.setLayoutData(fdRemoveOne);
    // ///////////////////////////////
    // RIGHT
    // ///////////////////////////////
    Composite rightsplit = new Composite(sashform, SWT.NONE);
    rightsplit.setLayout(new FormLayout());
    FormData fdRightsplit = new FormData();
    fdRightsplit.left = new FormAttachment(0, 0);
    fdRightsplit.top = new FormAttachment(0, 0);
    fdRightsplit.right = new FormAttachment(100, 0);
    fdRightsplit.bottom = new FormAttachment(100, 0);
    rightsplit.setLayoutData(fdRightsplit);
    props.setLook(rightsplit);
    wlListDest = new Label(rightsplit, SWT.NONE);
    wlListDest.setText("Your selection:");
    props.setLook(wlListDest);
    FormData fdlListDest = new FormData();
    fdlListDest.left = new FormAttachment(0, 0);
    fdlListDest.top = new FormAttachment(0, 0);
    wlListDest.setLayoutData(fdlListDest);
    wListDest = new List(rightsplit, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    props.setLook(wListDest);
    FormData fdListDest = new FormData();
    fdListDest.left = new FormAttachment(0, 0);
    fdListDest.top = new FormAttachment(wlListDest, 0);
    fdListDest.right = new FormAttachment(100, 0);
    fdListDest.bottom = new FormAttachment(100, 0);
    wListDest.setLayoutData(fdListDest);
    sashform.setWeights(new int[] { 45, 10, 45 });
    // Drag & Drop for steps
    Transfer[] ttypes = new Transfer[] { TextTransfer.getInstance() };
    DragSource ddSource = new DragSource(wListSource, DND.DROP_MOVE | DND.DROP_COPY);
    ddSource.setTransfer(ttypes);
    ddSource.addDragListener(new DragSourceListener() {

        public void dragStart(DragSourceEvent event) {
        }

        public void dragSetData(DragSourceEvent event) {
            String[] ti = wListSource.getSelection();
            String data = new String();
            for (int i = 0; i < ti.length; i++) {
                data += ti[i] + Const.CR;
            }
            event.data = data;
        }

        public void dragFinished(DragSourceEvent event) {
        }
    });
    DropTarget ddTarget = new DropTarget(wListDest, DND.DROP_MOVE | DND.DROP_COPY);
    ddTarget.setTransfer(ttypes);
    ddTarget.addDropListener(new DropTargetListener() {

        public void dragEnter(DropTargetEvent event) {
        }

        public void dragLeave(DropTargetEvent event) {
        }

        public void dragOperationChanged(DropTargetEvent event) {
        }

        public void dragOver(DropTargetEvent event) {
        }

        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                // no data to copy, indicate failure in event.detail
                event.detail = DND.DROP_NONE;
                return;
            }
            StringTokenizer strtok = new StringTokenizer((String) event.data, Const.CR);
            while (strtok.hasMoreTokens()) {
                String source = strtok.nextToken();
                addToDestination(source);
            }
        }

        public void dropAccept(DropTargetEvent event) {
        }
    });
    wListSource.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.character == SWT.CR) {
                addToSelection(wListSource.getSelection());
            }
        }
    });
    wListDest.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.character == SWT.CR) {
                delFromSelection(wListDest.getSelection());
            }
        }
    });
    // Double click adds to destination.
    wListSource.addSelectionListener(new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            addToSelection(wListSource.getSelection());
        }
    });
    // Double click adds to source
    wListDest.addSelectionListener(new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            String[] sel = wListDest.getSelection();
            delFromSelection(sel);
        }
    });
    wAddOne.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            addToSelection(wListSource.getSelection());
        }
    });
    wRemoveOne.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            delFromSelection(wListDest.getSelection());
        }
    });
    wAddAll.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            addAllToSelection();
        }
    });
    wRemoveAll.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            removeAllFromSelection();
        }
    });
    // set the composite as the control for this page
    setControl(composite);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSource(org.eclipse.swt.dnd.DragSource) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) SashForm(org.eclipse.swt.custom.SashForm) StringTokenizer(java.util.StringTokenizer) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) Button(org.eclipse.swt.widgets.Button) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) DropTarget(org.eclipse.swt.dnd.DropTarget) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 23 with DropTargetListener

use of org.eclipse.swt.dnd.DropTargetListener in project pentaho-kettle by pentaho.

the class Spoon method init.

public void init(TransMeta ti) {
    FormLayout layout = new FormLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    shell.setLayout(layout);
    addFileListener(new TransFileListener());
    addFileListener(new JobFileListener());
    // INIT Data structure
    if (ti != null) {
        delegates.trans.addTransformation(ti);
    }
    // Load settings in the props
    loadSettings();
    transExecutionConfiguration = new TransExecutionConfiguration();
    transExecutionConfiguration.setGatheringMetrics(true);
    transPreviewExecutionConfiguration = new TransExecutionConfiguration();
    transPreviewExecutionConfiguration.setGatheringMetrics(true);
    transDebugExecutionConfiguration = new TransExecutionConfiguration();
    transDebugExecutionConfiguration.setGatheringMetrics(true);
    jobExecutionConfiguration = new JobExecutionConfiguration();
    jobExecutionConfiguration.setGatheringMetrics(true);
    // Clean out every time we start, auto-loading etc, is not a good idea
    // If they are needed that often, set them in the kettle.properties file
    // 
    variables = new RowMetaAndData(new RowMeta());
    // props.setLook(shell);
    shell.setImage(GUIResource.getInstance().getImageSpoon());
    cursor_hourglass = new Cursor(display, SWT.CURSOR_WAIT);
    cursor_hand = new Cursor(display, SWT.CURSOR_HAND);
    Composite sashComposite = null;
    MainSpoonPerspective mainPerspective = null;
    try {
        KettleXulLoader xulLoader = new KettleXulLoader();
        xulLoader.setIconsSize(16, 16);
        xulLoader.setOuterContext(shell);
        xulLoader.setSettingsManager(XulSpoonSettingsManager.getInstance());
        ApplicationWindowLocal.setApplicationWindow(this);
        mainSpoonContainer = xulLoader.loadXul(XUL_FILE_MAIN, new XulSpoonResourceBundle());
        BindingFactory bf = new DefaultBindingFactory();
        bf.setDocument(mainSpoonContainer.getDocumentRoot());
        mainSpoonContainer.addEventHandler(this);
        /* menuBar = (XulMenubar) */
        mainSpoonContainer.getDocumentRoot().getElementById("spoon-menubar");
        mainToolbar = (XulToolbar) mainSpoonContainer.getDocumentRoot().getElementById("main-toolbar");
        props.setLook((Control) mainToolbar.getManagedObject(), Props.WIDGET_STYLE_TOOLBAR);
        /* canvas = (XulVbox) */
        mainSpoonContainer.getDocumentRoot().getElementById("trans-job-canvas");
        deck = (SwtDeck) mainSpoonContainer.getDocumentRoot().getElementById("canvas-deck");
        final Composite tempSashComposite = new Composite(shell, SWT.None);
        sashComposite = tempSashComposite;
        mainPerspective = new MainSpoonPerspective(tempSashComposite, tabfolder);
        if (startupPerspective == null) {
            startupPerspective = mainPerspective.getId();
        }
        SpoonPerspectiveManager.getInstance().setStartupPerspective(startupPerspective);
        SpoonPerspectiveManager.getInstance().addPerspective(mainPerspective);
        SpoonPluginManager.getInstance().applyPluginsForContainer("spoon", mainSpoonContainer);
        SpoonPerspectiveManager.getInstance().setDeck(deck);
        SpoonPerspectiveManager.getInstance().setXulDoc(mainSpoonContainer);
        SpoonPerspectiveManager.getInstance().initialize();
    } catch (Exception e) {
        LogChannel.GENERAL.logError("Error initializing transformation", e);
    }
    // addBar();
    // Set the shell size, based upon previous time...
    WindowProperty windowProperty = props.getScreen(APP_TITLE);
    if (windowProperty != null) {
        windowProperty.setShell(shell);
    } else {
        shell.pack();
        // Default = maximized!
        shell.setMaximized(true);
    }
    layout = new FormLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    GridData data = new GridData();
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    data.verticalAlignment = SWT.FILL;
    data.horizontalAlignment = SWT.FILL;
    sashComposite.setLayoutData(data);
    sashComposite.setLayout(layout);
    sashform = new SashForm(sashComposite, SWT.HORIZONTAL);
    FormData fdSash = new FormData();
    fdSash.left = new FormAttachment(0, 0);
    // fdSash.top = new FormAttachment((org.eclipse.swt.widgets.ToolBar)
    // toolbar.getNativeObject(), 0);
    fdSash.top = new FormAttachment(0, 0);
    fdSash.bottom = new FormAttachment(100, 0);
    fdSash.right = new FormAttachment(100, 0);
    sashform.setLayoutData(fdSash);
    createPopupMenus();
    addTree();
    addTabs();
    mainPerspective.setTabset(this.tabfolder);
    ((Composite) deck.getManagedObject()).layout(true, true);
    SpoonPluginManager.getInstance().notifyLifecycleListeners(SpoonLifeCycleEvent.STARTUP);
    // Add a browser widget
    if (props.showWelcomePageOnStartup()) {
        showWelcomePage();
    }
    // Allow data to be copied or moved to the drop target
    int operations = DND.DROP_COPY | DND.DROP_DEFAULT;
    DropTarget target = new DropTarget(shell, operations);
    // Receive data in File format
    final FileTransfer fileTransfer = FileTransfer.getInstance();
    Transfer[] types = new Transfer[] { fileTransfer };
    target.setTransfer(types);
    target.addDropListener(new DropTargetListener() {

        @Override
        public void dragEnter(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT) {
                if ((event.operations & DND.DROP_COPY) != 0) {
                    event.detail = DND.DROP_COPY;
                } else {
                    event.detail = DND.DROP_NONE;
                }
            }
        }

        @Override
        public void dragOver(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT) {
                if ((event.operations & DND.DROP_COPY) != 0) {
                    event.detail = DND.DROP_COPY;
                } else {
                    event.detail = DND.DROP_NONE;
                }
            }
        }

        @Override
        public void dragLeave(DropTargetEvent event) {
        }

        @Override
        public void dropAccept(DropTargetEvent event) {
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (fileTransfer.isSupportedType(event.currentDataType)) {
                String[] files = (String[]) event.data;
                for (String file : files) {
                    openFile(file, false);
                }
            }
        }
    });
    // listen for steps being added or removed
    PluginRegistry.getInstance().addPluginListener(StepPluginType.class, new PluginTypeListener() {

        @Override
        public void pluginAdded(Object serviceObject) {
            // hack to get the tree to reload
            previousShowTrans = false;
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    refreshCoreObjects();
                }
            });
        }

        @Override
        public void pluginRemoved(Object serviceObject) {
            // hack to get the tree to reload
            previousShowTrans = false;
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    refreshCoreObjects();
                }
            });
        }

        @Override
        public void pluginChanged(Object serviceObject) {
        }
    });
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Cursor(org.eclipse.swt.graphics.Cursor) DefaultBindingFactory(org.pentaho.ui.xul.binding.DefaultBindingFactory) WindowProperty(org.pentaho.di.ui.core.gui.WindowProperty) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginTypeListener(org.pentaho.di.core.plugins.PluginTypeListener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) FileTransfer(org.eclipse.swt.dnd.FileTransfer) KettleXulLoader(org.pentaho.di.ui.xul.KettleXulLoader) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) JobExecutionConfiguration(org.pentaho.di.job.JobExecutionConfiguration) SWTException(org.eclipse.swt.SWTException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleAuthException(org.pentaho.di.core.exception.KettleAuthException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) LifecycleException(org.pentaho.di.core.lifecycle.LifecycleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) MalformedURLException(java.net.MalformedURLException) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) SashForm(org.eclipse.swt.custom.SashForm) WaitBoxRunnable(org.pentaho.ui.xul.components.WaitBoxRunnable) GridData(org.eclipse.swt.layout.GridData) Transfer(org.eclipse.swt.dnd.Transfer) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) FileTransfer(org.eclipse.swt.dnd.FileTransfer) RepositoryObject(org.pentaho.di.repository.RepositoryObject) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) FileObject(org.apache.commons.vfs2.FileObject) DropTarget(org.eclipse.swt.dnd.DropTarget) DefaultBindingFactory(org.pentaho.ui.xul.binding.DefaultBindingFactory) BindingFactory(org.pentaho.ui.xul.binding.BindingFactory)

Example 24 with DropTargetListener

use of org.eclipse.swt.dnd.DropTargetListener in project pentaho-kettle by pentaho.

the class EnterListDialog method open.

public String[] open() {
    Shell parent = getParent();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
    props.setLook(shell);
    shell.setImage(GUIResource.getInstance().getImageTransGraph());
    shell.setText(BaseMessages.getString(PKG, "EnterListDialog.Title"));
    shell.setLayout(new FormLayout());
    int margin = Const.MARGIN;
    // //////////////////////////////////////////////////
    // Top & Bottom regions.
    // //////////////////////////////////////////////////
    Composite top = new Composite(shell, SWT.NONE);
    FormLayout topLayout = new FormLayout();
    topLayout.marginHeight = margin;
    topLayout.marginWidth = margin;
    top.setLayout(topLayout);
    FormData fdTop = new FormData();
    fdTop.left = new FormAttachment(0, 0);
    fdTop.top = new FormAttachment(0, 0);
    fdTop.right = new FormAttachment(100, 0);
    fdTop.bottom = new FormAttachment(100, -50);
    top.setLayoutData(fdTop);
    props.setLook(top);
    Composite bottom = new Composite(shell, SWT.NONE);
    bottom.setLayout(new FormLayout());
    FormData fdBottom = new FormData();
    fdBottom.left = new FormAttachment(0, 0);
    fdBottom.top = new FormAttachment(top, 0);
    fdBottom.right = new FormAttachment(100, 0);
    fdBottom.bottom = new FormAttachment(100, 0);
    bottom.setLayoutData(fdBottom);
    props.setLook(bottom);
    // //////////////////////////////////////////////////
    // Sashform
    // //////////////////////////////////////////////////
    SashForm sashform = new SashForm(top, SWT.HORIZONTAL);
    sashform.setLayout(new FormLayout());
    FormData fdSashform = new FormData();
    fdSashform.left = new FormAttachment(0, 0);
    fdSashform.top = new FormAttachment(0, 0);
    fdSashform.right = new FormAttachment(100, 0);
    fdSashform.bottom = new FormAttachment(100, 0);
    sashform.setLayoutData(fdSashform);
    // ////////////////////////
    // / LEFT
    // ////////////////////////
    Composite leftsplit = new Composite(sashform, SWT.NONE);
    leftsplit.setLayout(new FormLayout());
    FormData fdLeftsplit = new FormData();
    fdLeftsplit.left = new FormAttachment(0, 0);
    fdLeftsplit.top = new FormAttachment(0, 0);
    fdLeftsplit.right = new FormAttachment(100, 0);
    fdLeftsplit.bottom = new FormAttachment(100, 0);
    leftsplit.setLayoutData(fdLeftsplit);
    props.setLook(leftsplit);
    // Source list to the left...
    wlListSource = new Label(leftsplit, SWT.NONE);
    wlListSource.setText(BaseMessages.getString(PKG, "EnterListDialog.AvailableItems.Label"));
    props.setLook(wlListSource);
    FormData fdlListSource = new FormData();
    fdlListSource.left = new FormAttachment(0, 0);
    fdlListSource.top = new FormAttachment(0, 0);
    wlListSource.setLayoutData(fdlListSource);
    wListSource = new List(leftsplit, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    props.setLook(wListSource);
    FormData fdListSource = new FormData();
    fdListSource.left = new FormAttachment(0, 0);
    fdListSource.top = new FormAttachment(wlListSource, 0);
    fdListSource.right = new FormAttachment(100, 0);
    fdListSource.bottom = new FormAttachment(100, 0);
    wListSource.setLayoutData(fdListSource);
    // /////////////////////////
    // MIDDLE
    // /////////////////////////
    Composite compmiddle = new Composite(sashform, SWT.NONE);
    compmiddle.setLayout(new FormLayout());
    FormData fdCompMiddle = new FormData();
    fdCompMiddle.left = new FormAttachment(0, 0);
    fdCompMiddle.top = new FormAttachment(0, 0);
    fdCompMiddle.right = new FormAttachment(100, 0);
    fdCompMiddle.bottom = new FormAttachment(100, 0);
    compmiddle.setLayoutData(fdCompMiddle);
    props.setLook(compmiddle);
    Composite gButtonGroup = new Composite(compmiddle, SWT.NONE);
    GridLayout gridLayout = new GridLayout(1, false);
    gButtonGroup.setLayout(gridLayout);
    wAddOne = new Button(gButtonGroup, SWT.PUSH);
    wAddOne.setText(" > ");
    wAddOne.setToolTipText(BaseMessages.getString(PKG, "EnterListDialog.AddOne.Tooltip"));
    wAddAll = new Button(gButtonGroup, SWT.PUSH);
    wAddAll.setText(" >> ");
    wAddAll.setToolTipText(BaseMessages.getString(PKG, "EnterListDialog.AddAll.Tooltip"));
    wRemoveOne = new Button(gButtonGroup, SWT.PUSH);
    wRemoveOne.setText(" < ");
    wRemoveOne.setToolTipText(BaseMessages.getString(PKG, "EnterListDialog.RemoveOne.Tooltip"));
    wRemoveAll = new Button(gButtonGroup, SWT.PUSH);
    wRemoveAll.setText(" << ");
    wRemoveAll.setToolTipText(BaseMessages.getString(PKG, "EnterListDialog.RemoveAll.Tooltip"));
    GridData gdAddOne = new GridData(GridData.FILL_BOTH);
    wAddOne.setLayoutData(gdAddOne);
    GridData gdAddAll = new GridData(GridData.FILL_BOTH);
    wAddAll.setLayoutData(gdAddAll);
    GridData gdRemoveAll = new GridData(GridData.FILL_BOTH);
    wRemoveAll.setLayoutData(gdRemoveAll);
    GridData gdRemoveOne = new GridData(GridData.FILL_BOTH);
    wRemoveOne.setLayoutData(gdRemoveOne);
    FormData fdButtonGroup = new FormData();
    // get a size
    wAddAll.pack();
    fdButtonGroup.left = new FormAttachment(50, -(wAddAll.getSize().x / 2) - 5);
    fdButtonGroup.top = new FormAttachment(30, 0);
    // the default looks ugly
    gButtonGroup.setBackground(shell.getBackground());
    gButtonGroup.setLayoutData(fdButtonGroup);
    // ///////////////////////////////
    // RIGHT
    // ///////////////////////////////
    Composite rightsplit = new Composite(sashform, SWT.NONE);
    rightsplit.setLayout(new FormLayout());
    FormData fdRightsplit = new FormData();
    fdRightsplit.left = new FormAttachment(0, 0);
    fdRightsplit.top = new FormAttachment(0, 0);
    fdRightsplit.right = new FormAttachment(100, 0);
    fdRightsplit.bottom = new FormAttachment(100, 0);
    rightsplit.setLayoutData(fdRightsplit);
    props.setLook(rightsplit);
    wlListDest = new Label(rightsplit, SWT.NONE);
    wlListDest.setText(BaseMessages.getString(PKG, "EnterListDialog.Selection.Label"));
    props.setLook(wlListDest);
    FormData fdlListDest = new FormData();
    fdlListDest.left = new FormAttachment(0, 0);
    fdlListDest.top = new FormAttachment(0, 0);
    wlListDest.setLayoutData(fdlListDest);
    wListDest = new List(rightsplit, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    props.setLook(wListDest);
    FormData fdListDest = new FormData();
    fdListDest.left = new FormAttachment(0, 0);
    fdListDest.top = new FormAttachment(wlListDest, 0);
    fdListDest.right = new FormAttachment(100, 0);
    fdListDest.bottom = new FormAttachment(100, 0);
    wListDest.setLayoutData(fdListDest);
    sashform.setWeights(new int[] { 40, 16, 40 });
    // //////////////////////////////////////////////////////////////
    // THE BOTTOM BUTTONS...
    // //////////////////////////////////////////////////////////////
    wOK = new Button(bottom, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wCancel = new Button(bottom, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    FormData fdOK = new FormData();
    FormData fdCancel = new FormData();
    fdOK.left = new FormAttachment(35, 0);
    fdOK.bottom = new FormAttachment(100, 0);
    wOK.setLayoutData(fdOK);
    fdCancel.left = new FormAttachment(wOK, 10);
    fdCancel.bottom = new FormAttachment(100, 0);
    wCancel.setLayoutData(fdCancel);
    // Add listeners
    wCancel.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            dispose();
        }
    });
    // Add listeners
    wOK.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            handleOK();
        }
    });
    // Drag & Drop for steps
    Transfer[] ttypes = new Transfer[] { TextTransfer.getInstance() };
    DragSource ddSource = new DragSource(wListSource, DND.DROP_MOVE | DND.DROP_COPY);
    ddSource.setTransfer(ttypes);
    ddSource.addDragListener(new DragSourceListener() {

        public void dragStart(DragSourceEvent event) {
        }

        public void dragSetData(DragSourceEvent event) {
            String[] ti = wListSource.getSelection();
            String data = new String();
            for (int i = 0; i < ti.length; i++) {
                data += ti[i] + Const.CR;
            }
            event.data = data;
        }

        public void dragFinished(DragSourceEvent event) {
        }
    });
    DropTarget ddTarget = new DropTarget(wListDest, DND.DROP_MOVE | DND.DROP_COPY);
    ddTarget.setTransfer(ttypes);
    ddTarget.addDropListener(new DropTargetListener() {

        public void dragEnter(DropTargetEvent event) {
        }

        public void dragLeave(DropTargetEvent event) {
        }

        public void dragOperationChanged(DropTargetEvent event) {
        }

        public void dragOver(DropTargetEvent event) {
        }

        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                // no data to copy, indicate failure in event.detail
                event.detail = DND.DROP_NONE;
                return;
            }
            StringTokenizer strtok = new StringTokenizer((String) event.data, Const.CR);
            while (strtok.hasMoreTokens()) {
                String source = strtok.nextToken();
                addToDestination(source);
            }
        }

        public void dropAccept(DropTargetEvent event) {
        }
    });
    wListSource.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.character == SWT.CR) {
                addToSelection(wListSource.getSelection());
            }
        }
    });
    wListDest.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.character == SWT.CR) {
                delFromSelection(wListDest.getSelection());
            }
        }
    });
    // Double click adds to destination.
    wListSource.addSelectionListener(new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            addToSelection(wListSource.getSelection());
        }
    });
    // Double click adds to source
    wListDest.addSelectionListener(new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            delFromSelection(wListDest.getSelection());
        }
    });
    wAddOne.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            addToSelection(wListSource.getSelection());
        }
    });
    wRemoveOne.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            delFromSelection(wListDest.getSelection());
        }
    });
    wAddAll.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            addToSelection(wListSource.getItems());
        }
    });
    wRemoveAll.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            delFromSelection(wListDest.getItems());
        }
    });
    opened = true;
    getData();
    BaseStepDialog.setSize(shell);
    shell.open();
    Display display = parent.getDisplay();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return retval;
}
Also used : DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) Listener(org.eclipse.swt.widgets.Listener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSource(org.eclipse.swt.dnd.DragSource) SashForm(org.eclipse.swt.custom.SashForm) StringTokenizer(java.util.StringTokenizer) GridData(org.eclipse.swt.layout.GridData) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Event(org.eclipse.swt.widgets.Event) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DropTarget(org.eclipse.swt.dnd.DropTarget) Display(org.eclipse.swt.widgets.Display)

Example 25 with DropTargetListener

use of org.eclipse.swt.dnd.DropTargetListener in project yamcs-studio by yamcs.

the class PVTupleTableEditor method createPVTupleListTableViewer.

/**
 * Creates and configures a {@link TableViewer}.
 *
 * @param parent
 *            The parent for the table
 * @return The {@link TableViewer}
 */
private TableViewer createPVTupleListTableViewer(Composite parent, TableColumnLayout tcl) {
    var viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    var numColumn = new TableViewerColumn(viewer, SWT.NONE);
    numColumn.getColumn().setText("#");
    tcl.setColumnData(numColumn.getColumn(), new ColumnPixelData(50));
    var pvColumn = new TableViewerColumn(viewer, SWT.NONE);
    pvColumn.getColumn().setText("PV Name");
    tcl.setColumnData(pvColumn.getColumn(), new ColumnWeightData(50));
    pvColumn.setEditingSupport(new PVColumnEditingSupport(viewer, viewer.getTable()));
    var trigColumn = new TableViewerColumn(viewer, SWT.NONE);
    trigColumn.getColumn().setText("Trigger");
    tcl.setColumnData(trigColumn.getColumn(), new ColumnPixelData(50));
    trigColumn.setEditingSupport(new TriggerColumnEditingSupport(viewer, viewer.getTable()));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new PVTupleLabelProvider(pvTupleList));
    viewer.addSelectionChangedListener(event -> refreshToolbarOnSelection());
    viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    var target = new DropTarget(viewer.getControl(), DND.DROP_MOVE | DND.DROP_COPY);
    target.setTransfer(new Transfer[] { TextTransfer.getInstance() });
    target.addDropListener(new DropTargetListener() {

        @Override
        public void dragEnter(DropTargetEvent event) {
        }

        @Override
        public void dragLeave(DropTargetEvent event) {
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
        }

        @Override
        public void dragOver(DropTargetEvent event) {
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (event == null || !(event.data instanceof String)) {
                return;
            }
            var txt = (String) event.data;
            var names = txt.split("[\r\n]+");
            var tuples = new PVTuple[names.length];
            var i = 0;
            for (var name : names) {
                tuples[i] = new PVTuple(name, true);
                pvTupleList.add(tuples[i]);
                i++;
            }
            refreshTableViewerFromAction(tuples);
        }

        @Override
        public void dropAccept(DropTargetEvent event) {
        }
    });
    return viewer;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PVTuple(org.csstudio.opibuilder.script.PVTuple) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) DropTarget(org.eclipse.swt.dnd.DropTarget) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

DropTargetListener (org.eclipse.swt.dnd.DropTargetListener)25 DropTarget (org.eclipse.swt.dnd.DropTarget)22 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)19 Transfer (org.eclipse.swt.dnd.Transfer)11 TransferDropTargetListener (org.eclipse.jface.util.TransferDropTargetListener)6 DragSource (org.eclipse.swt.dnd.DragSource)6 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)6 TextTransfer (org.eclipse.swt.dnd.TextTransfer)6 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 DragSourceListener (org.eclipse.swt.dnd.DragSourceListener)5 Point (org.eclipse.swt.graphics.Point)5 Button (org.eclipse.swt.widgets.Button)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 FormAttachment (org.eclipse.swt.layout.FormAttachment)4 GridData (org.eclipse.swt.layout.GridData)4 SashForm (org.eclipse.swt.custom.SashForm)3 StyledText (org.eclipse.swt.custom.StyledText)3