Search in sources :

Example 1 with MissingTransDialog

use of org.pentaho.di.ui.trans.steps.missing.MissingTransDialog in project pentaho-kettle by pentaho.

the class TransFileListener method open.

public boolean open(Node transNode, String fname, boolean importfile) throws KettleMissingPluginsException {
    final Spoon spoon = Spoon.getInstance();
    final PropsUI props = PropsUI.getInstance();
    try {
        // Call extension point(s) before the file has been opened
        ExtensionPointHandler.callExtensionPoint(spoon.getLog(), KettleExtensionPoint.TransBeforeOpen.id, fname);
        TransMeta transMeta = new TransMeta();
        transMeta.loadXML(transNode, fname, spoon.getMetaStore(), spoon.getRepository(), true, new Variables(), new OverwritePrompter() {

            public boolean overwritePrompt(String message, String rememberText, String rememberPropertyName) {
                MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
                Object[] res = spoon.messageDialogWithToggle(BaseMessages.getString(PKG, "System.Button.Yes"), null, message, Const.WARNING, new String[] { BaseMessages.getString(PKG, "System.Button.Yes"), BaseMessages.getString(PKG, "System.Button.No") }, 1, rememberText, !props.askAboutReplacingDatabaseConnections());
                int idx = ((Integer) res[0]).intValue();
                boolean toggleState = ((Boolean) res[1]).booleanValue();
                props.setAskAboutReplacingDatabaseConnections(!toggleState);
                // Yes means: overwrite
                return ((idx & 0xFF) == 0);
            }
        });
        if (transMeta.hasMissingPlugins()) {
            StepMeta stepMeta = transMeta.getStep(0);
            MissingTransDialog missingDialog = new MissingTransDialog(spoon.getShell(), transMeta.getMissingTrans(), stepMeta.getStepMetaInterface(), transMeta, stepMeta.getName());
            if (missingDialog.open() == null) {
                return true;
            }
        }
        transMeta.setRepositoryDirectory(spoon.getDefaultSaveLocation(transMeta));
        transMeta.setRepository(spoon.getRepository());
        transMeta.setMetaStore(spoon.getMetaStore());
        spoon.setTransMetaVariables(transMeta);
        spoon.getProperties().addLastFile(LastUsedFile.FILE_TYPE_TRANSFORMATION, fname, null, false, null);
        spoon.addMenuLast();
        // if any exist.
        if (importfile) {
            if (spoon.getRepository() != null) {
                transMeta = fixLinks(transMeta);
            }
        } else {
            transMeta.clearChanged();
        }
        transMeta.setFilename(fname);
        spoon.addTransGraph(transMeta);
        spoon.sharedObjectsFileMap.put(transMeta.getSharedObjects().getFilename(), transMeta.getSharedObjects());
        // Call extension point(s) now that the file has been opened
        ExtensionPointHandler.callExtensionPoint(spoon.getLog(), KettleExtensionPoint.TransAfterOpen.id, transMeta);
        SpoonPerspectiveManager.getInstance().activatePerspective(MainSpoonPerspective.class);
        spoon.refreshTree();
        return true;
    } catch (KettleMissingPluginsException e) {
        throw e;
    } catch (KettleException e) {
        new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorOpening.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorOpening.Message") + fname, e);
    }
    return false;
}
Also used : Variables(org.pentaho.di.core.variables.Variables) KettleException(org.pentaho.di.core.exception.KettleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) MissingTransDialog(org.pentaho.di.ui.trans.steps.missing.MissingTransDialog) TransMeta(org.pentaho.di.trans.TransMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) OverwritePrompter(org.pentaho.di.core.gui.OverwritePrompter) StepMeta(org.pentaho.di.trans.step.StepMeta) PropsUI(org.pentaho.di.ui.core.PropsUI)

Example 2 with MissingTransDialog

use of org.pentaho.di.ui.trans.steps.missing.MissingTransDialog in project pentaho-kettle by pentaho.

the class TransLoadProgressDialog method open.

public TransMeta open() {
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            Spoon spoon = Spoon.getInstance();
            try {
                // Call extension point(s) before the file has been opened
                ExtensionPointHandler.callExtensionPoint(spoon.getLog(), KettleExtensionPoint.TransBeforeOpen.id, (objectId == null) ? transname : objectId.toString());
                if (objectId != null) {
                    transInfo = rep.loadTransformation(objectId, versionLabel);
                } else {
                    transInfo = rep.loadTransformation(transname, repdir, new ProgressMonitorAdapter(monitor), true, versionLabel);
                }
                // Call extension point(s) now that the file has been opened
                ExtensionPointHandler.callExtensionPoint(spoon.getLog(), KettleExtensionPoint.TransAfterOpen.id, transInfo);
                if (transInfo.hasMissingPlugins()) {
                    StepMeta stepMeta = transInfo.getStep(0);
                    Display.getDefault().syncExec(() -> {
                        MissingTransDialog missingTransDialog = new MissingTransDialog(shell, transInfo.getMissingTrans(), stepMeta.getStepMetaInterface(), transInfo, stepMeta.getName());
                        if (missingTransDialog.open() == null) {
                            transInfo = null;
                        }
                    });
                }
            } catch (KettleException e) {
                throw new InvocationTargetException(e, BaseMessages.getString(PKG, "TransLoadProgressDialog.Exception.ErrorLoadingTransformation"));
            }
        }
    };
    try {
        ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
        pmd.run(true, false, op);
    } catch (InvocationTargetException e) {
        KettleRepositoryLostException krle = KettleRepositoryLostException.lookupStackStrace(e);
        if (krle != null) {
            throw krle;
        }
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TransLoadProgressDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "TransLoadProgressDialog.ErrorLoadingTransformation.DialogMessage"), e);
        transInfo = null;
    } catch (InterruptedException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TransLoadProgressDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "TransLoadProgressDialog.ErrorLoadingTransformation.DialogMessage"), e);
        transInfo = null;
    }
    return transInfo;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MissingTransDialog(org.pentaho.di.ui.trans.steps.missing.MissingTransDialog) Spoon(org.pentaho.di.ui.spoon.Spoon) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ProgressMonitorAdapter(org.pentaho.di.core.ProgressMonitorAdapter) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) StepMeta(org.pentaho.di.trans.step.StepMeta) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

KettleException (org.pentaho.di.core.exception.KettleException)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 MissingTransDialog (org.pentaho.di.ui.trans.steps.missing.MissingTransDialog)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 ProgressMonitorAdapter (org.pentaho.di.core.ProgressMonitorAdapter)1 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)1 OverwritePrompter (org.pentaho.di.core.gui.OverwritePrompter)1 Variables (org.pentaho.di.core.variables.Variables)1 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)1 TransMeta (org.pentaho.di.trans.TransMeta)1 PropsUI (org.pentaho.di.ui.core.PropsUI)1 Spoon (org.pentaho.di.ui.spoon.Spoon)1