/** * Finds the tab for the transformation that matches the metadata provided (either the file must * be the same or the repository id). * * @param trans Transformation metadata to look for * @return Tab with transformation open whose metadata matches {@code trans} or {@code null} if no * tab exists. * @throws KettleFileException If there is a problem loading the file object for an open * transformation with an invalid a filename. */ public TabMapEntry findTabForTransformation(TransMeta trans) throws KettleFileException { // File for the transformation we're looking for. It will be loaded upon first request. FileObject transFile = null; for (TabMapEntry entry : tabMap) { if (entry == null || entry.getTabItem().isDisposed()) { continue; } if (trans.getFilename() != null && entry.getFilename() != null) { // If the entry has a file name it is the same as trans iff. they originated from the same // files FileObject entryFile = KettleVFS.getFileObject(entry.getFilename()); if (transFile == null) { transFile = KettleVFS.getFileObject(trans.getFilename()); } if (entryFile.equals(transFile)) { return entry; } } else if (trans.getObjectId() != null && entry.getObject() != null) { EngineMetaInterface meta = entry.getObject().getMeta(); if (meta != null && trans.getObjectId().equals(meta.getObjectId())) { // If the transformation has an object id and the entry shares the same id they are the // same return entry; } } } // No tabs for the transformation exist and are not disposed return null; }
public void tabSelected(TabItem item) { List<TabMapEntry> collection = spoon.delegates.tabs.getTabs(); // See which core objects to show // for (TabMapEntry entry : collection) { if (item.equals(entry.getTabItem())) { // TabItemInterface itemInterface = entry.getObject(); // // Another way to implement this may be to keep track of the // state of the core object tree in method // addCoreObjectsToTree() // if (entry.getObject() instanceof TransGraph || entry.getObject() instanceof JobGraph) { EngineMetaInterface meta = entry.getObject().getMeta(); if (meta != null) { meta.setInternalKettleVariables(); } if (spoon.getCoreObjectsState() != SpoonInterface.STATE_CORE_OBJECTS_SPOON) { spoon.refreshCoreObjects(); } } } } // Also refresh the tree spoon.refreshTree(); spoon.enableMenus(); }
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; }
public TransGraph findTransGraphOfTransformation(TransMeta transMeta) { // Now loop over the entries in the tab-map for (TabMapEntry mapEntry : spoon.delegates.tabs.getTabs()) { if (mapEntry.getObject() instanceof TransGraph) { TransGraph transGraph = (TransGraph) mapEntry.getObject(); if (transGraph.getMeta().equals(transMeta)) return transGraph; } } return null; }
/** Rename the tabs */ public void renameTabs() { List<TabMapEntry> list = new ArrayList<TabMapEntry>(tabMap); for (TabMapEntry entry : list) { if (entry.getTabItem().isDisposed()) { // this should not be in the map, get rid of it. tabMap.remove(entry.getObjectName()); continue; } // TabItem before = entry.getTabItem(); // PDI-1683: need to get the String here, otherwise using only the "before" instance below, // the reference gets // changed and result is always the same // String beforeText=before.getText(); // Object managedObject = entry.getObject().getManagedObject(); if (managedObject != null) { if (entry.getObject() instanceof TransGraph) { TransMeta transMeta = (TransMeta) managedObject; String tabText = makeTabName(transMeta, entry.isShowingLocation()); entry.getTabItem().setText(tabText); String toolTipText = BaseMessages.getString(PKG, "Spoon.TabTrans.Tooltip", tabText); if (Const.isWindows() && !Const.isEmpty(transMeta.getFilename())) { toolTipText += Const.CR + Const.CR + transMeta.getFilename(); } entry.getTabItem().setToolTipText(toolTipText); } else if (entry.getObject() instanceof JobGraph) { JobMeta jobMeta = (JobMeta) managedObject; entry.getTabItem().setText(makeTabName(jobMeta, entry.isShowingLocation())); String toolTipText = BaseMessages.getString( PKG, "Spoon.TabJob.Tooltip", makeTabName(jobMeta, entry.isShowingLocation())); if (Const.isWindows() && !Const.isEmpty(jobMeta.getFilename())) { toolTipText += Const.CR + Const.CR + jobMeta.getFilename(); } entry.getTabItem().setToolTipText(toolTipText); } } /* * String after = entry.getTabItem().getText(); * * if (!beforeText.equals(after)) // PDI-1683, could be improved to rename all the time { * entry.setObjectName(after); * * // Also change the transformation map if (entry.getObject() instanceof TransGraph) { * spoon.delegates.trans.removeTransformation(beforeText); spoon.delegates.trans.addTransformation(after, * (TransMeta) entry.getObject().getManagedObject()); } // Also change the job map if (entry.getObject() * instanceof JobGraph) { spoon.delegates.jobs.removeJob(beforeText); spoon.delegates.jobs.addJob(after, (JobMeta) * entry.getObject().getManagedObject()); } } */ } spoon.setShellText(); }
public void tabSelected(TabItem item) { ArrayList<TabMapEntry> collection = new ArrayList<TabMapEntry>(tabMap); // See which core objects to show // for (TabMapEntry entry : collection) { boolean isTrans = (entry.getObject() instanceof TransGraph); if (item.equals(entry.getTabItem())) { if (isTrans || entry.getObject() instanceof JobGraph) { EngineMetaInterface meta = entry.getObject().getMeta(); if (meta != null) { meta.setInternalKettleVariables(); } if (spoon.getCoreObjectsState() != SpoonInterface.STATE_CORE_OBJECTS_SPOON) { spoon.refreshCoreObjects(); } } if (entry.getObject() instanceof JobGraph) { ((JobGraph) entry.getObject()).setFocus(); } else if (entry.getObject() instanceof TransGraph) { ((TransGraph) entry.getObject()).setFocus(); } break; } } // Also refresh the tree spoon.refreshTree(); spoon.setShellText(); // calls also enableMenus() and markTabsChanged() }
public TabMapEntry findTabMapEntry(Object managedObject) { for (TabMapEntry entry : tabMap) { if (entry.getTabItem().isDisposed()) { continue; } Object entryManagedObj = entry.getObject().getManagedObject(); // make sure they are the same class before comparing them if (entryManagedObj != null && managedObject != null) { if (entryManagedObj.getClass().equals(managedObject.getClass())) { if (entryManagedObj.equals(managedObject)) { return entry; } } } } return null; }
public boolean tabClose(TabItem item) throws KettleException { // Try to find the tab-item that's being closed. List<TabMapEntry> collection = new ArrayList<TabMapEntry>(); collection.addAll(tabMap); 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 : collection) { if (item.equals(entry.getTabItem())) { TabItemInterface itemInterface = entry.getObject(); if (itemInterface.getManagedObject() != null && AbstractMeta.class.isAssignableFrom(itemInterface.getManagedObject().getClass())) { canSave = !((AbstractMeta) itemInterface.getManagedObject()).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; } } } } // Also clean up the log/history associated with this // transformation/job // if (close) { if (entry.getObject() instanceof TransGraph) { TransMeta transMeta = (TransMeta) entry.getObject().getManagedObject(); spoon.delegates.trans.closeTransformation(transMeta); spoon.refreshTree(); // spoon.refreshCoreObjects(); } else if (entry.getObject() instanceof JobGraph) { JobMeta jobMeta = (JobMeta) entry.getObject().getManagedObject(); spoon.delegates.jobs.closeJob(jobMeta); spoon.refreshTree(); // spoon.refreshCoreObjects(); } else if (entry.getObject() instanceof SpoonBrowser) { this.removeTab(entry); spoon.refreshTree(); } else if (entry.getObject() instanceof Composite) { Composite comp = (Composite) entry.getObject(); if (comp != null && !comp.isDisposed()) { comp.dispose(); } } } break; } } return close; }