Search in sources :

Example 1 with DragAndDropContainer

use of org.pentaho.di.core.dnd.DragAndDropContainer in project pentaho-kettle by pentaho.

the class SpoonTreeDelegate method addDragSourceToTree.

public void addDragSourceToTree(final Tree tree, final Tree selectionTree, final Tree coreObjectsTree) {
    // Drag & Drop for steps
    Transfer[] ttypes = new Transfer[] { XMLTransfer.getInstance() };
    DragSource ddSource = new DragSource(tree, DND.DROP_MOVE);
    ddSource.setTransfer(ttypes);
    ddSource.addDragListener(new DragSourceListener() {

        public void dragStart(DragSourceEvent event) {
            TreeSelection[] treeObjects = getTreeObjects(tree, selectionTree, coreObjectsTree);
            if (treeObjects.length == 0) {
                event.doit = false;
                return;
            }
            spoon.hideToolTips();
            TreeSelection treeObject = treeObjects[0];
            Object object = treeObject.getSelection();
            TransMeta transMeta = spoon.getActiveTransformation();
            if (object instanceof StepMeta || object instanceof PluginInterface || (object instanceof DatabaseMeta && transMeta != null) || object instanceof TransHopMeta || object instanceof JobEntryCopy) {
                event.doit = true;
            } else {
                event.doit = false;
            }
        }

        public void dragSetData(DragSourceEvent event) {
            TreeSelection[] treeObjects = getTreeObjects(tree, selectionTree, coreObjectsTree);
            if (treeObjects.length == 0) {
                event.doit = false;
                return;
            }
            int type = 0;
            String id = null;
            String data = null;
            TreeSelection treeObject = treeObjects[0];
            Object object = treeObject.getSelection();
            if (object instanceof StepMeta) {
                StepMeta stepMeta = (StepMeta) object;
                type = DragAndDropContainer.TYPE_STEP;
                // name of the step.
                data = stepMeta.getName();
            } else if (object instanceof PluginInterface) {
                PluginInterface plugin = (PluginInterface) object;
                Class<? extends PluginTypeInterface> pluginType = plugin.getPluginType();
                if (Const.classIsOrExtends(pluginType, StepPluginType.class)) {
                    type = DragAndDropContainer.TYPE_BASE_STEP_TYPE;
                    id = plugin.getIds()[0];
                    // Step type name
                    data = plugin.getName();
                } else {
                    type = DragAndDropContainer.TYPE_BASE_JOB_ENTRY;
                    // job entry type name
                    data = plugin.getName();
                    if (treeObject.getItemText().equals(JobMeta.createStartEntry().getName())) {
                        data = treeObject.getItemText();
                    } else if (treeObject.getItemText().equals(JobMeta.createDummyEntry().getName())) {
                        data = treeObject.getItemText();
                    }
                }
            } else if (object instanceof DatabaseMeta) {
                DatabaseMeta databaseMeta = (DatabaseMeta) object;
                type = DragAndDropContainer.TYPE_DATABASE_CONNECTION;
                data = databaseMeta.getName();
            } else if (object instanceof TransHopMeta) {
                TransHopMeta hop = (TransHopMeta) object;
                type = DragAndDropContainer.TYPE_TRANS_HOP;
                // nothing for really ;-)
                data = hop.toString();
            } else if (object instanceof JobEntryCopy) {
                JobEntryCopy jobEntryCopy = (JobEntryCopy) object;
                type = DragAndDropContainer.TYPE_JOB_ENTRY;
                // name of the job entry.
                data = jobEntryCopy.getName();
            } else {
                event.doit = false;
                // ignore anything else you drag.
                return;
            }
            event.data = new DragAndDropContainer(type, data, id);
        }

        public void dragFinished(DragSourceEvent event) {
        }
    });
}
Also used : PluginInterface(org.pentaho.di.core.plugins.PluginInterface) TransMeta(org.pentaho.di.trans.TransMeta) DragSource(org.eclipse.swt.dnd.DragSource) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) StepMeta(org.pentaho.di.trans.step.StepMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) TreeSelection(org.pentaho.di.ui.spoon.TreeSelection) Transfer(org.eclipse.swt.dnd.Transfer) XMLTransfer(org.pentaho.di.core.dnd.XMLTransfer) DragAndDropContainer(org.pentaho.di.core.dnd.DragAndDropContainer) TransHopMeta(org.pentaho.di.trans.TransHopMeta)

Aggregations

DragSource (org.eclipse.swt.dnd.DragSource)1 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)1 DragSourceListener (org.eclipse.swt.dnd.DragSourceListener)1 Transfer (org.eclipse.swt.dnd.Transfer)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 DragAndDropContainer (org.pentaho.di.core.dnd.DragAndDropContainer)1 XMLTransfer (org.pentaho.di.core.dnd.XMLTransfer)1 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)1 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)1 TransHopMeta (org.pentaho.di.trans.TransHopMeta)1 TransMeta (org.pentaho.di.trans.TransMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 TreeSelection (org.pentaho.di.ui.spoon.TreeSelection)1