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) {
}
});
}
Aggregations