use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.
the class SpoonTreeDelegate method getTreeObjects.
/**
* @return The object that is selected in the tree or null if we couldn't figure it out. (titles etc. == null)
*/
public TreeSelection[] getTreeObjects(final Tree tree, Tree selectionTree, Tree coreObjectsTree) {
List<TreeSelection> objects = new ArrayList<TreeSelection>();
if (selectionTree != null && !selectionTree.isDisposed() && tree.equals(selectionTree)) {
TreeItem[] selection = selectionTree.getSelection();
for (int s = 0; s < selection.length; s++) {
TreeItem treeItem = selection[s];
String[] path = ConstUI.getTreeStrings(treeItem);
TreeSelection object = null;
switch(path.length) {
case 0:
break;
case // ------complete-----
1:
if (path[0].equals(Spoon.STRING_TRANSFORMATIONS)) {
// the top level Transformations entry
object = new TreeSelection(path[0], TransMeta.class);
}
if (path[0].equals(Spoon.STRING_JOBS)) {
// the top level Jobs entry
object = new TreeSelection(path[0], JobMeta.class);
}
break;
case // ------complete-----
2:
if (path[0].equals(Spoon.STRING_BUILDING_BLOCKS)) {
if (path[1].equals(Spoon.STRING_TRANS_BASE)) {
object = new TreeSelection(path[1], PluginInterface.class);
}
}
if (path[0].equals(Spoon.STRING_TRANSFORMATIONS)) {
// Transformation title
object = new TreeSelection(path[1], spoon.delegates.trans.getTransformation(path[1]));
}
if (path[0].equals(Spoon.STRING_JOBS)) {
// Jobs title
object = new TreeSelection(path[1], spoon.delegates.jobs.getJob(path[1]));
}
break;
case // ------complete-----
3:
if (path[0].equals(Spoon.STRING_TRANSFORMATIONS)) {
// Transformations title
TransMeta transMeta = spoon.delegates.trans.getTransformation(path[1]);
if (path[2].equals(Spoon.STRING_CONNECTIONS)) {
object = new TreeSelection(path[2], DatabaseMeta.class, transMeta);
}
if (path[2].equals(Spoon.STRING_STEPS)) {
object = new TreeSelection(path[2], StepMeta.class, transMeta);
}
if (path[2].equals(Spoon.STRING_HOPS)) {
object = new TreeSelection(path[2], TransHopMeta.class, transMeta);
}
if (path[2].equals(Spoon.STRING_PARTITIONS)) {
object = new TreeSelection(path[2], PartitionSchema.class, transMeta);
}
if (path[2].equals(Spoon.STRING_SLAVES)) {
object = new TreeSelection(path[2], SlaveServer.class, transMeta);
}
if (path[2].equals(Spoon.STRING_CLUSTERS)) {
object = new TreeSelection(path[2], ClusterSchema.class, transMeta);
}
executeExtensionPoint(new SpoonTreeDelegateExtension(transMeta, path, 3, objects));
}
if (path[0].equals(Spoon.STRING_JOBS)) {
// Jobs title
JobMeta jobMeta = spoon.delegates.jobs.getJob(path[1]);
if (path[2].equals(Spoon.STRING_CONNECTIONS)) {
object = new TreeSelection(path[2], DatabaseMeta.class, jobMeta);
}
if (path[2].equals(Spoon.STRING_JOB_ENTRIES)) {
object = new TreeSelection(path[2], JobEntryCopy.class, jobMeta);
}
if (path[2].equals(Spoon.STRING_SLAVES)) {
object = new TreeSelection(path[2], SlaveServer.class, jobMeta);
}
executeExtensionPoint(new SpoonTreeDelegateExtension(jobMeta, path, 3, objects));
}
break;
case // ------complete-----
4:
if (path[0].equals(Spoon.STRING_TRANSFORMATIONS)) {
// The name of a transformation
final TransMeta transMeta = spoon.delegates.trans.getTransformation(path[1]);
if (transMeta != null) {
if (path[2].equals(Spoon.STRING_CONNECTIONS)) {
String dbName = path[3];
DatabaseMeta databaseMeta = transMeta.findDatabase(dbName);
if (databaseMeta != null) {
dbName = databaseMeta.getName();
}
object = new TreeSelection(dbName, databaseMeta, transMeta);
}
if (path[2].equals(Spoon.STRING_STEPS)) {
object = new TreeSelection(path[3], transMeta.findStep(path[3]), transMeta);
}
if (path[2].equals(Spoon.STRING_HOPS)) {
object = new TreeSelection(path[3], transMeta.findTransHop(path[3]), transMeta);
}
if (path[2].equals(Spoon.STRING_PARTITIONS)) {
object = new TreeSelection(path[3], transMeta.findPartitionSchema(path[3]), transMeta);
}
if (path[2].equals(Spoon.STRING_SLAVES)) {
object = new TreeSelection(path[3], transMeta.findSlaveServer(path[3]), transMeta);
}
if (path[2].equals(Spoon.STRING_CLUSTERS)) {
object = new TreeSelection(path[3], transMeta.findClusterSchema(path[3]), transMeta);
}
executeExtensionPoint(new SpoonTreeDelegateExtension(transMeta, path, 4, objects));
}
}
if (path[0].equals(Spoon.STRING_JOBS)) {
// The name of a job
JobMeta jobMeta = spoon.delegates.jobs.getJob(path[1]);
if (jobMeta != null && path[2].equals(Spoon.STRING_CONNECTIONS)) {
String dbName = path[3];
DatabaseMeta databaseMeta = jobMeta.findDatabase(dbName);
if (databaseMeta != null) {
dbName = databaseMeta.getName();
}
object = new TreeSelection(dbName, databaseMeta, jobMeta);
}
if (jobMeta != null && path[2].equals(Spoon.STRING_JOB_ENTRIES)) {
object = new TreeSelection(path[3], jobMeta.findJobEntry(path[3]), jobMeta);
}
if (jobMeta != null && path[2].equals(Spoon.STRING_SLAVES)) {
object = new TreeSelection(path[3], jobMeta.findSlaveServer(path[3]), jobMeta);
}
executeExtensionPoint(new SpoonTreeDelegateExtension(jobMeta, path, 4, objects));
}
break;
case 5:
if (path[0].equals(Spoon.STRING_TRANSFORMATIONS)) {
// The name of a transformation
TransMeta transMeta = spoon.delegates.trans.getTransformation(path[1]);
if (transMeta != null && path[2].equals(Spoon.STRING_CLUSTERS)) {
ClusterSchema clusterSchema = transMeta.findClusterSchema(path[3]);
object = new TreeSelection(path[4], clusterSchema.findSlaveServer(path[4]), clusterSchema, transMeta);
}
}
break;
default:
break;
}
if (object != null) {
objects.add(object);
}
}
}
if (tree != null && coreObjectsTree != null && tree.equals(coreObjectsTree)) {
TreeItem[] selection = coreObjectsTree.getSelection();
for (int s = 0; s < selection.length; s++) {
TreeItem treeItem = selection[s];
String[] path = ConstUI.getTreeStrings(treeItem);
TreeSelection object = null;
switch(path.length) {
case 0:
break;
case // Job entries
2:
if (spoon.showJob) {
PluginRegistry registry = PluginRegistry.getInstance();
Class<? extends PluginTypeInterface> pluginType = JobEntryPluginType.class;
PluginInterface plugin = registry.findPluginWithName(pluginType, path[1]);
//
if (plugin == null) {
if (path[1].equals(JobMeta.STRING_SPECIAL_START)) {
plugin = registry.findPluginWithId(pluginType, JobMeta.STRING_SPECIAL);
}
}
//
if (plugin == null) {
if (path[1].equals(JobMeta.STRING_SPECIAL_DUMMY)) {
plugin = registry.findPluginWithId(pluginType, JobMeta.STRING_SPECIAL);
}
}
if (plugin != null) {
object = new TreeSelection(path[1], plugin);
}
}
if (spoon.showTrans) {
String stepId = (String) treeItem.getData("StepId");
if (stepId != null) {
object = new TreeSelection(path[1], PluginRegistry.getInstance().findPluginWithId(StepPluginType.class, stepId));
} else {
object = new TreeSelection(path[1], PluginRegistry.getInstance().findPluginWithName(StepPluginType.class, path[1]));
}
}
break;
default:
break;
}
if (object != null) {
objects.add(object);
}
}
}
return objects.toArray(new TreeSelection[objects.size()]);
}
use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.
the class PartitionSettings method fillOptionsAndCodesByPlugins.
public void fillOptionsAndCodesByPlugins(List<PluginInterface> plugins) {
int pluginIndex = 0;
for (PluginInterface plugin : plugins) {
options[StepPartitioningMeta.methodDescriptions.length + pluginIndex] = plugin.getDescription();
codes[StepPartitioningMeta.methodCodes.length + pluginIndex] = plugin.getIds()[0];
pluginIndex++;
}
}
use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.
the class TransGraph method setMenu.
/**
* This sets the popup-menu on the background of the canvas based on the xy coordinate of the mouse. This method is
* called after a mouse-click.
*
* @param x X-coordinate on screen
* @param y Y-coordinate on screen
*/
private synchronized void setMenu(int x, int y) {
try {
currentMouseX = x;
currentMouseY = y;
final StepMeta stepMeta = transMeta.getStep(x, y, iconsize);
if (stepMeta != null) {
// We clicked on a Step!
setCurrentStep(stepMeta);
XulMenupopup menu = menuMap.get("trans-graph-entry");
try {
ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, KettleExtensionPoint.TransStepRightClick.id, new StepMenuExtension(this, menu));
} catch (Exception ex) {
LogChannel.GENERAL.logError("Error calling TransStepRightClick extension point", ex);
}
if (menu != null) {
List<StepMeta> selection = transMeta.getSelectedSteps();
doRightClickSelection(stepMeta, selection);
int sels = selection.size();
Document doc = getXulDomContainer().getDocumentRoot();
// TODO: cache the next line (seems fast enough)?
//
List<PluginInterface> rowDistributionPlugins = PluginRegistry.getInstance().getPlugins(RowDistributionPluginType.class);
JfaceMenupopup customRowDistMenu = (JfaceMenupopup) doc.getElementById("trans-graph-entry-data-movement-popup");
customRowDistMenu.setDisabled(false);
customRowDistMenu.removeChildren();
// Add the default round robin plugin...
//
Action action = new Action("RoundRobinRowDistribution", Action.AS_CHECK_BOX) {
@Override
public void run() {
// default
stepMeta.setRowDistribution(null);
stepMeta.setDistributes(true);
}
};
boolean selected = stepMeta.isDistributes() && stepMeta.getRowDistribution() == null;
action.setChecked(selected);
JfaceMenuitem child = new JfaceMenuitem(null, customRowDistMenu, xulDomContainer, "Round Robin row distribution", 0, action);
child.setLabel(BaseMessages.getString(PKG, "TransGraph.PopupMenu.RoundRobin"));
child.setDisabled(false);
child.setSelected(selected);
for (int p = 0; p < rowDistributionPlugins.size(); p++) {
final PluginInterface rowDistributionPlugin = rowDistributionPlugins.get(p);
selected = stepMeta.isDistributes() && stepMeta.getRowDistribution() != null && stepMeta.getRowDistribution().getCode().equals(rowDistributionPlugin.getIds()[0]);
action = new Action(rowDistributionPlugin.getIds()[0], Action.AS_CHECK_BOX) {
@Override
public void run() {
try {
stepMeta.setRowDistribution((RowDistributionInterface) PluginRegistry.getInstance().loadClass(rowDistributionPlugin));
} catch (Exception e) {
LogChannel.GENERAL.logError("Error loading row distribution plugin class: ", e);
}
}
};
action.setChecked(selected);
child = new JfaceMenuitem(null, customRowDistMenu, xulDomContainer, rowDistributionPlugin.getName(), p + 1, action);
child.setLabel(rowDistributionPlugin.getName());
child.setDisabled(false);
child.setSelected(selected);
}
// Add the default copy rows plugin...
//
action = new Action("CopyRowsDistribution", Action.AS_CHECK_BOX) {
@Override
public void run() {
stepMeta.setDistributes(false);
}
};
selected = !stepMeta.isDistributes();
action.setChecked(selected);
child = new JfaceMenuitem(null, customRowDistMenu, xulDomContainer, "Copy rows distribution", 0, action);
child.setLabel(BaseMessages.getString(PKG, "TransGraph.PopupMenu.CopyData"));
child.setDisabled(false);
child.setSelected(selected);
JfaceMenupopup launchMenu = (JfaceMenupopup) doc.getElementById("trans-graph-entry-launch-popup");
String[] referencedObjects = stepMeta.getStepMetaInterface().getReferencedObjectDescriptions();
boolean[] enabledObjects = stepMeta.getStepMetaInterface().isReferencedObjectEnabled();
launchMenu.setDisabled(Utils.isEmpty(referencedObjects));
launchMenu.removeChildren();
int childIndex = 0;
// First see if we need to add a special "active" entry (running transformation)
//
StepMetaInterface stepMetaInterface = stepMeta.getStepMetaInterface();
String activeReferencedObjectDescription = stepMetaInterface.getActiveReferencedObjectDescription();
if (getActiveSubtransformation(this, stepMeta) != null && activeReferencedObjectDescription != null) {
action = new Action(activeReferencedObjectDescription, Action.AS_DROP_DOWN_MENU) {
@Override
public void run() {
// negative by convention
openMapping(stepMeta, -1);
}
};
child = new JfaceMenuitem(null, launchMenu, xulDomContainer, activeReferencedObjectDescription, childIndex++, action);
child.setLabel(activeReferencedObjectDescription);
child.setDisabled(false);
}
if (!Utils.isEmpty(referencedObjects)) {
for (int i = 0; i < referencedObjects.length; i++) {
final int index = i;
String referencedObject = referencedObjects[i];
action = new Action(referencedObject, Action.AS_DROP_DOWN_MENU) {
@Override
public void run() {
openMapping(stepMeta, index);
}
};
child = new JfaceMenuitem(null, launchMenu, xulDomContainer, referencedObject, childIndex++, action);
child.setLabel(referencedObject);
child.setDisabled(!enabledObjects[i]);
}
}
initializeXulMenu(doc, selection, stepMeta);
ConstUI.displayMenu(menu, canvas);
}
} else {
final TransHopMeta hi = findHop(x, y);
if (hi != null) {
// We clicked on a HOP!
XulMenupopup menu = menuMap.get("trans-graph-hop");
if (menu != null) {
setCurrentHop(hi);
XulMenuitem item = (XulMenuitem) getXulDomContainer().getDocumentRoot().getElementById("trans-graph-hop-enabled");
if (item != null) {
if (hi.isEnabled()) {
item.setLabel(BaseMessages.getString(PKG, "TransGraph.PopupMenu.DisableHop"));
} else {
item.setLabel(BaseMessages.getString(PKG, "TransGraph.PopupMenu.EnableHop"));
}
}
ConstUI.displayMenu(menu, canvas);
}
} else {
// Clicked on the background: maybe we hit a note?
final NotePadMeta ni = transMeta.getNote(x, y);
setCurrentNote(ni);
if (ni != null) {
XulMenupopup menu = menuMap.get("trans-graph-note");
if (menu != null) {
ConstUI.displayMenu(menu, canvas);
}
} else {
XulMenupopup menu = menuMap.get("trans-graph-background");
if (menu != null) {
final String clipcontent = spoon.fromClipboard();
XulMenuitem item = (XulMenuitem) getXulDomContainer().getDocumentRoot().getElementById("trans-graph-background-paste");
if (item != null) {
item.setDisabled(clipcontent == null);
}
ConstUI.displayMenu(menu, canvas);
}
}
}
}
} catch (Throwable t) {
// TODO: fix this: log somehow, is IGNORED for now.
t.printStackTrace();
}
}
use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.
the class TransGraph method askUserForCustomDistributionMethod.
public RowDistributionInterface askUserForCustomDistributionMethod() {
List<PluginInterface> plugins = PluginRegistry.getInstance().getPlugins(RowDistributionPluginType.class);
if (Utils.isEmpty(plugins)) {
return null;
}
List<String> choices = new ArrayList<>();
for (PluginInterface plugin : plugins) {
choices.add(plugin.getName() + " : " + plugin.getDescription());
}
EnterSelectionDialog dialog = new EnterSelectionDialog(shell, choices.toArray(new String[choices.size()]), "Select distribution method", "Please select the row distribution method:");
if (dialog.open() != null) {
PluginInterface plugin = plugins.get(dialog.getSelectionNr());
try {
return (RowDistributionInterface) PluginRegistry.getInstance().loadClass(plugin);
} catch (Exception e) {
new ErrorDialog(shell, "Error", "Error loading row distribution plugin class", e);
return null;
}
} else {
return null;
}
}
use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.
the class JobDelegate method readJobEntry.
protected JobEntryInterface readJobEntry(DataNode copyNode, JobMeta jobMeta, List<JobEntryInterface> jobentries) throws KettleException {
try {
String name = getString(copyNode, PROP_NAME);
for (JobEntryInterface entry : jobentries) {
if (entry.getName().equalsIgnoreCase(name)) {
// already loaded!
return entry;
}
}
// load the entry from the node
//
String typeId = getString(copyNode, PROP_JOBENTRY_TYPE);
PluginRegistry registry = PluginRegistry.getInstance();
PluginInterface jobPlugin = registry.findPluginWithId(JobEntryPluginType.class, typeId);
JobEntryInterface jobMetaInterface = null;
boolean isMissing = jobPlugin == null;
if (!isMissing) {
jobMetaInterface = (JobEntryInterface) registry.loadClass(jobPlugin);
} else {
MissingEntry missingEntry = new MissingEntry(jobMeta.getName(), typeId);
jobMeta.addMissingEntry(missingEntry);
jobMetaInterface = missingEntry;
}
jobMetaInterface.setName(name);
jobMetaInterface.setDescription(getString(copyNode, PROP_DESCRIPTION));
jobMetaInterface.setObjectId(new StringObjectId(copyNode.getId().toString()));
RepositoryProxy proxy = new RepositoryProxy(copyNode.getNode(NODE_CUSTOM));
// make sure metastore is passed
jobMetaInterface.setMetaStore(jobMeta.getMetaStore());
if (!isMissing) {
compatibleJobEntryLoadRep(jobMetaInterface, proxy, null, jobMeta.getDatabases(), jobMeta.getSlaveServers());
jobMetaInterface.loadRep(proxy, jobMeta.getMetaStore(), null, jobMeta.getDatabases(), jobMeta.getSlaveServers());
}
jobentries.add(jobMetaInterface);
return jobMetaInterface;
} catch (Exception e) {
throw new KettleException("Unable to read job entry interface information from repository", e);
}
}
Aggregations