Search in sources :

Example 1 with SpoonBrowser

use of org.pentaho.di.ui.spoon.SpoonBrowser 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;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) Composite(org.eclipse.swt.widgets.Composite) AbstractMeta(org.pentaho.di.base.AbstractMeta) TransMeta(org.pentaho.di.trans.TransMeta) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) TabMapEntry(org.pentaho.di.ui.spoon.TabMapEntry) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) SpoonBrowser(org.pentaho.di.ui.spoon.SpoonBrowser) FileObject(org.apache.commons.vfs2.FileObject) TabItemInterface(org.pentaho.di.ui.spoon.TabItemInterface)

Example 2 with SpoonBrowser

use of org.pentaho.di.ui.spoon.SpoonBrowser in project pentaho-kettle by pentaho.

the class SpoonTabsDelegate method addSpoonBrowser.

public boolean addSpoonBrowser(String name, String urlString, boolean isURL, LocationListener listener, Map<String, Runnable> functions, boolean showControls) {
    TabSet tabfolder = spoon.tabfolder;
    try {
        // OK, now we have the HTML, create a new browser tab.
        // See if there already is a tab for this browser
        // If no, add it
        // If yes, select that tab
        // 
        TabMapEntry tabMapEntry = findTabMapEntry(name, ObjectType.BROWSER);
        if (tabMapEntry == null) {
            CTabFolder cTabFolder = tabfolder.getSwtTabset();
            final SpoonBrowser browser = new SpoonBrowser(cTabFolder, spoon, urlString, isURL, showControls, listener);
            browser.getBrowser().addOpenWindowListener(new OpenWindowListener() {

                @Override
                public void open(WindowEvent event) {
                    if (event.required) {
                        event.browser = browser.getBrowser();
                    }
                }
            });
            if (functions != null) {
                for (String functionName : functions.keySet()) {
                    new BrowserFunction(browser.getBrowser(), functionName) {

                        public Object function(Object[] arguments) {
                            functions.get(functionName).run();
                            return null;
                        }
                    };
                }
            }
            new BrowserFunction(browser.getBrowser(), "genericFunction") {

                public Object function(Object[] arguments) {
                    try {
                        ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonBrowserFunction.id, arguments);
                    } catch (KettleException ignored) {
                    }
                    return null;
                }
            };
            new BrowserFunction(browser.getBrowser(), "openURL") {

                public Object function(Object[] arguments) {
                    Program.launch(arguments[0].toString());
                    return null;
                }
            };
            PropsUI props = PropsUI.getInstance();
            TabItem tabItem = new TabItem(tabfolder, name, name, props.getSashWeights());
            tabItem.setImage(GUIResource.getInstance().getImageLogoSmall());
            tabItem.setControl(browser.getComposite());
            tabMapEntry = new TabMapEntry(tabItem, isURL ? urlString : null, name, null, null, browser, ObjectType.BROWSER);
            tabMap.add(tabMapEntry);
        }
        int idx = tabfolder.indexOf(tabMapEntry.getTabItem());
        // keep the focus on the graph
        tabfolder.setSelected(idx);
        return true;
    } catch (Throwable e) {
        boolean ok = false;
        if (isURL) {
            // Retry to show the welcome page in an external browser.
            // 
            Status status = Launch.openURL(urlString);
            ok = status.equals(Status.Success);
        }
        if (!ok) {
            // Log an error
            // 
            log.logError("Unable to open browser tab", e);
            return false;
        } else {
            return true;
        }
    }
}
Also used : Status(org.pentaho.ui.util.Launch.Status) KettleException(org.pentaho.di.core.exception.KettleException) CTabFolder(org.eclipse.swt.custom.CTabFolder) TabMapEntry(org.pentaho.di.ui.spoon.TabMapEntry) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) PropsUI(org.pentaho.di.ui.core.PropsUI) TabItem(org.pentaho.xul.swt.tab.TabItem) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) SpoonBrowser(org.pentaho.di.ui.spoon.SpoonBrowser) TabSet(org.pentaho.xul.swt.tab.TabSet) WindowEvent(org.eclipse.swt.browser.WindowEvent) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener)

Aggregations

KettleException (org.pentaho.di.core.exception.KettleException)2 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)2 SpoonBrowser (org.pentaho.di.ui.spoon.SpoonBrowser)2 TabMapEntry (org.pentaho.di.ui.spoon.TabMapEntry)2 FileObject (org.apache.commons.vfs2.FileObject)1 BrowserFunction (org.eclipse.swt.browser.BrowserFunction)1 OpenWindowListener (org.eclipse.swt.browser.OpenWindowListener)1 WindowEvent (org.eclipse.swt.browser.WindowEvent)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 Composite (org.eclipse.swt.widgets.Composite)1 AbstractMeta (org.pentaho.di.base.AbstractMeta)1 JobMeta (org.pentaho.di.job.JobMeta)1 TransMeta (org.pentaho.di.trans.TransMeta)1 PropsUI (org.pentaho.di.ui.core.PropsUI)1 TabItemInterface (org.pentaho.di.ui.spoon.TabItemInterface)1 JobGraph (org.pentaho.di.ui.spoon.job.JobGraph)1 TransGraph (org.pentaho.di.ui.spoon.trans.TransGraph)1 Status (org.pentaho.ui.util.Launch.Status)1 TabItem (org.pentaho.xul.swt.tab.TabItem)1 TabSet (org.pentaho.xul.swt.tab.TabSet)1