use of org.pentaho.di.ui.spoon.trans.TransGraph in project pentaho-kettle by pentaho.
the class JobGraph method loadReferencedObject.
protected void loadReferencedObject(JobEntryCopy jobEntryCopy, int index) {
try {
Object referencedMeta = jobEntryCopy.getEntry().loadReferencedObject(index, spoon.rep, spoon.metaStore, jobMeta);
if (referencedMeta == null) {
// Compatible re-try for older plugins.
referencedMeta = compatibleJobEntryLoadReferencedObject(jobEntryCopy.getEntry(), index, spoon.rep, jobMeta);
}
if (referencedMeta != null && (referencedMeta instanceof TransMeta)) {
TransMeta launchTransMeta = (TransMeta) referencedMeta;
// Try to see if this transformation is already loaded in another tab...
//
TabMapEntry tabEntry = spoon.delegates.tabs.findTabForTransformation(launchTransMeta);
if (tabEntry != null) {
// Switch to this one!
//
spoon.tabfolder.setSelected(tabEntry.getTabItem());
return;
}
copyInternalJobVariables(jobMeta, launchTransMeta);
spoon.setParametersAsVariablesInUI(launchTransMeta, launchTransMeta);
launchTransMeta.clearChanged();
spoon.addTransGraph(launchTransMeta);
TransGraph transGraph = spoon.getActiveTransGraph();
attachActiveTrans(transGraph, launchTransMeta, jobEntryCopy);
spoon.refreshTree();
spoon.applyVariables();
}
if (referencedMeta != null && (referencedMeta instanceof JobMeta)) {
JobMeta launchJobMeta = (JobMeta) referencedMeta;
// Try to see if this job is already loaded in another tab...
//
String tabName = spoon.delegates.tabs.makeTabName(launchJobMeta, true);
TabMapEntry tabEntry = spoon.delegates.tabs.findTabMapEntry(tabName, ObjectType.JOB_GRAPH);
if (tabEntry != null) {
// Switch to this one!
//
spoon.tabfolder.setSelected(tabEntry.getTabItem());
return;
}
spoon.setParametersAsVariablesInUI(launchJobMeta, launchJobMeta);
launchJobMeta.clearChanged();
spoon.addJobGraph(launchJobMeta);
JobGraph jobGraph = spoon.getActiveJobGraph();
attachActiveJob(jobGraph, launchJobMeta, jobEntryCopy);
spoon.refreshTree();
spoon.applyVariables();
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "JobGraph.Dialog.ErrorLaunchingSpoonCanNotLoadTransformation.Title"), BaseMessages.getString(PKG, "JobGraph.Dialog.ErrorLaunchingSpoonCanNotLoadTransformation.Message"), e);
}
}
use of org.pentaho.di.ui.spoon.trans.TransGraph in project pentaho-kettle by pentaho.
the class JobGraph method openTransformation.
protected void openTransformation(JobEntryTrans entry, JobEntryCopy jobEntryCopy) {
try {
TransMeta launchTransMeta = null;
switch(entry.getSpecificationMethod()) {
case FILENAME:
// See if this file is already loaded...
//
String exactFilename = jobMeta.environmentSubstitute(entry.getFilename());
if (Utils.isEmpty(exactFilename)) {
throw new Exception(BaseMessages.getString(PKG, "JobGraph.Exception.NoFilenameSpecified"));
}
//
if (KettleVFS.fileExists(exactFilename)) {
launchTransMeta = new TransMeta(exactFilename);
} else {
launchTransMeta = new TransMeta();
}
launchTransMeta.setFilename(exactFilename);
break;
case REPOSITORY_BY_NAME:
String exactTransname = jobMeta.environmentSubstitute(entry.getTransname());
String exactDirectory = jobMeta.environmentSubstitute(entry.getDirectory());
if (Utils.isEmpty(exactTransname)) {
throw new Exception(BaseMessages.getString(PKG, "JobGraph.Exception.NoTransNameSpecified"));
}
if (Utils.isEmpty(exactDirectory)) {
throw new Exception(BaseMessages.getString(PKG, "JobGraph.Exception.NoTransDirectorySpecified"));
}
// Open the transformation or create a new one...
// But first we look to see if the directory does exist
RepositoryDirectoryInterface repositoryDirectoryInterface = spoon.rep.findDirectory(jobMeta.environmentSubstitute(entry.getDirectory()));
if (repositoryDirectoryInterface == null) {
throw new Exception(BaseMessages.getString(PKG, "JobGraph.Exception.DirectoryDoesNotExist", jobMeta.environmentSubstitute(entry.getDirectory())));
}
boolean exists = spoon.rep.getTransformationID(exactTransname, repositoryDirectoryInterface) != null;
if (!exists) {
launchTransMeta = new TransMeta(null, exactTransname);
} else {
launchTransMeta = spoon.rep.loadTransformation(exactTransname, spoon.rep.findDirectory(jobMeta.environmentSubstitute(entry.getDirectory())), null, true, // reads last version
null);
}
break;
case REPOSITORY_BY_REFERENCE:
if (entry.getTransObjectId() == null) {
throw new Exception(BaseMessages.getString(PKG, "JobGraph.Exception.NoTransReferenceSpecified"));
}
launchTransMeta = spoon.rep.loadTransformation(entry.getTransObjectId(), null);
break;
default:
break;
}
//
if (launchTransMeta == null) {
throw new Exception(BaseMessages.getString(PKG, "JobGraph.Exception.NoValidTransSpecified"));
}
launchTransMeta.setRepository(spoon.getRepository());
launchTransMeta.setMetaStore(spoon.getMetaStore());
// Try to see if this transformation is already loaded in another tab...
//
TabMapEntry tabEntry = spoon.delegates.tabs.findTabForTransformation(launchTransMeta);
if (tabEntry != null) {
// Switch to this one!
//
spoon.tabfolder.setSelected(tabEntry.getTabItem());
return;
}
copyInternalJobVariables(jobMeta, launchTransMeta);
spoon.setParametersAsVariablesInUI(launchTransMeta, launchTransMeta);
spoon.addTransGraph(launchTransMeta);
launchTransMeta.clearChanged();
TransGraph transGraph = spoon.getActiveTransGraph();
attachActiveTrans(transGraph, launchTransMeta, jobEntryCopy);
spoon.refreshTree();
spoon.applyVariables();
} catch (Throwable e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "JobGraph.Dialog.ErrorLaunchingSpoonCanNotLoadTransformation.Title"), BaseMessages.getString(PKG, "JobGraph.Dialog.ErrorLaunchingSpoonCanNotLoadTransformation.Message"), (Exception) e);
}
}
use of org.pentaho.di.ui.spoon.trans.TransGraph in project pentaho-kettle by pentaho.
the class SpoonTabsDelegate method getActiveMeta.
public EngineMetaInterface getActiveMeta() {
TabSet tabfolder = spoon.tabfolder;
if (tabfolder == null) {
return null;
}
TabItem tabItem = tabfolder.getSelected();
if (tabItem == null) {
return null;
}
// What transformation is in the active tab?
// TransLog, TransGraph & TransHist contain the same transformation
//
TabMapEntry mapEntry = getTab(tabfolder.getSelected());
EngineMetaInterface meta = null;
if (mapEntry != null) {
if (mapEntry.getObject() instanceof TransGraph) {
meta = (mapEntry.getObject()).getMeta();
}
if (mapEntry.getObject() instanceof JobGraph) {
meta = (mapEntry.getObject()).getMeta();
}
}
return meta;
}
use of org.pentaho.di.ui.spoon.trans.TransGraph in project pentaho-kettle by pentaho.
the class SpoonTabsDelegate method tabClose.
public boolean tabClose(TabItem item, boolean force) throws KettleException {
// Try to find the tab-item that's being closed.
boolean createPerms = !RepositorySecurityUI.verifyOperations(Spoon.getInstance().getShell(), Spoon.getInstance().getRepository(), false, RepositoryOperation.MODIFY_TRANSFORMATION, RepositoryOperation.MODIFY_JOB);
boolean close = true;
boolean canSave = true;
for (TabMapEntry entry : tabMap) {
if (item.equals(entry.getTabItem())) {
final TabItemInterface itemInterface = entry.getObject();
final Object managedObject = itemInterface.getManagedObject();
if (!force) {
if (managedObject != null && AbstractMeta.class.isAssignableFrom(managedObject.getClass())) {
canSave = !((AbstractMeta) managedObject).hasMissingPlugins();
}
if (canSave) {
// Can we close this tab? Only allow users with create content perms to save
if (!itemInterface.canBeClosed() && createPerms) {
int reply = itemInterface.showChangedWarning();
if (reply == SWT.YES) {
close = itemInterface.applyChanges();
} else {
if (reply == SWT.CANCEL) {
close = false;
} else {
close = true;
}
}
}
}
}
String beforeCloseId = null;
String afterCloseId = null;
if (itemInterface instanceof TransGraph) {
beforeCloseId = KettleExtensionPoint.TransBeforeClose.id;
afterCloseId = KettleExtensionPoint.TransAfterClose.id;
} else if (itemInterface instanceof JobGraph) {
beforeCloseId = KettleExtensionPoint.JobBeforeClose.id;
afterCloseId = KettleExtensionPoint.JobAfterClose.id;
}
if (beforeCloseId != null) {
try {
ExtensionPointHandler.callExtensionPoint(log, beforeCloseId, managedObject);
} catch (KettleException e) {
// prevent tab close
close = false;
}
}
//
if (close) {
if (itemInterface instanceof TransGraph) {
TransMeta transMeta = (TransMeta) managedObject;
spoon.delegates.trans.closeTransformation(transMeta);
spoon.refreshTree();
// spoon.refreshCoreObjects();
} else if (itemInterface instanceof JobGraph) {
JobMeta jobMeta = (JobMeta) managedObject;
spoon.delegates.jobs.closeJob(jobMeta);
spoon.refreshTree();
// spoon.refreshCoreObjects();
} else if (itemInterface instanceof SpoonBrowser) {
this.removeTab(entry);
spoon.refreshTree();
} else if (itemInterface instanceof Composite) {
Composite comp = (Composite) itemInterface;
if (comp != null && !comp.isDisposed()) {
comp.dispose();
}
}
if (afterCloseId != null) {
try {
ExtensionPointHandler.callExtensionPoint(log, afterCloseId, managedObject);
} catch (KettleException e) {
// fails gracefully... what else could we do?
}
}
}
break;
}
}
return close;
}
use of org.pentaho.di.ui.spoon.trans.TransGraph in project pentaho-kettle by pentaho.
the class SpoonTransformationDelegate method addTransGraph.
public void addTransGraph(TransMeta transMeta) {
boolean added = addTransformation(transMeta);
if (added) {
// See if there already is a tab for this graph with the short default name.
// If there is, set that one to show the location as well.
// If not, simply add it without
// If no, add it
// If yes, select that tab
//
boolean showLocation = false;
boolean addTab = true;
String tabName = spoon.delegates.tabs.makeTabName(transMeta, showLocation);
TabMapEntry tabEntry = spoon.delegates.tabs.findTabMapEntry(tabName, ObjectType.TRANSFORMATION_GRAPH);
if (tabEntry != null) {
// We change the already loaded transformation to also show the location.
//
showLocation = true;
// Try again, including the location of the object...
//
tabName = spoon.delegates.tabs.makeTabName(transMeta, showLocation);
TabMapEntry exactSameEntry = spoon.delegates.tabs.findTabMapEntry(tabName, ObjectType.TRANSFORMATION_GRAPH);
if (exactSameEntry != null) {
// Already loaded, simply select the tab item in question...
//
addTab = false;
} else {
// We might need to rename the tab of the entry already loaded!
//
tabEntry.setShowingLocation(true);
String newTabName = spoon.delegates.tabs.makeTabName(tabEntry.getObject().getMeta(), showLocation);
tabEntry.getTabItem().setText(newTabName);
}
}
TransGraph transGraph = null;
if (addTab) {
transGraph = new TransGraph(spoon.tabfolder.getSwtTabset(), spoon, transMeta);
PropsUI props = PropsUI.getInstance();
if (tabName.length() >= getMaxTabLength()) {
tabName = new StringBuilder().append(tabName.substring(0, getMaxTabLength())).append("\u2026").toString();
}
TabItem tabItem = new TabItem(spoon.tabfolder, tabName, tabName, props.getSashWeights());
String toolTipText = BaseMessages.getString(PKG, "Spoon.TabTrans.Tooltip", spoon.delegates.tabs.makeTabName(transMeta, showLocation));
if (!Utils.isEmpty(transMeta.getFilename())) {
toolTipText += Const.CR + Const.CR + transMeta.getFilename();
}
tabItem.setToolTipText(toolTipText);
tabItem.setImage(GUIResource.getInstance().getImageTransGraph());
tabItem.setControl(transGraph);
TransLogTable logTable = transMeta.getTransLogTable();
String versionLabel = transMeta.getObjectRevision() == null ? null : transMeta.getObjectRevision().getName();
tabEntry = new TabMapEntry(tabItem, transMeta.getFilename(), transMeta.getName(), transMeta.getRepositoryDirectory(), versionLabel, transGraph, ObjectType.TRANSFORMATION_GRAPH, transMeta.getVariable(Spoon.CONNECTION));
tabEntry.setShowingLocation(showLocation);
spoon.delegates.tabs.addTab(tabEntry);
}
int idx = spoon.tabfolder.indexOf(tabEntry.getTabItem());
// keep the focus on the graph
spoon.tabfolder.setSelected(idx);
if (addTab) {
TransLogTable logTable = transMeta.getTransLogTable();
// OK, also see if we need to open a new history window.
if (isLogTableDefined(logTable) && !transMeta.isSlaveTransformation()) {
addTabsToTransGraph(transGraph);
}
}
spoon.setUndoMenu(transMeta);
spoon.enableMenus();
} else {
TabMapEntry tabEntry = spoon.delegates.tabs.findTabMapEntry(transMeta);
if (tabEntry != null) {
int idx = spoon.tabfolder.indexOf(tabEntry.getTabItem());
// keep the focus on the graph
spoon.tabfolder.setSelected(idx);
spoon.setUndoMenu(transMeta);
spoon.enableMenus();
}
}
}
Aggregations