Search in sources :

Example 31 with TransGraph

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

the class Spoon method quitFile.

public boolean quitFile(boolean canCancel) throws KettleException {
    if (log.isDetailed()) {
        // "Quit application."
        log.logDetailed(BaseMessages.getString(PKG, "Spoon.Log.QuitApplication"));
    }
    boolean exit = true;
    saveSettings();
    if (props.showExitWarning() && canCancel) {
        // Display message: are you sure you want to exit?
        // 
        MessageDialogWithToggle md = new MessageDialogWithToggle(shell, // "Warning!"
        BaseMessages.getString(PKG, "System.Warning"), null, BaseMessages.getString(PKG, "Spoon.Message.Warning.PromptExit"), MessageDialog.WARNING, new String[] { // "Yes",
        BaseMessages.getString(PKG, "Spoon.Message.Warning.Yes"), // "No"
        BaseMessages.getString(PKG, "Spoon.Message.Warning.No") }, 1, // "Please, don't show this warning anymore."
        BaseMessages.getString(PKG, "Spoon.Message.Warning.NotShowWarning"), !props.showExitWarning());
        MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        int idx = md.open();
        props.setExitWarningShown(!md.getToggleState());
        props.saveProps();
        if ((idx & 0xFF) == 1) {
            // No selected: don't exit!
            return false;
        }
    }
    // Check all tabs to see if we can close them...
    // 
    List<TabMapEntry> list = delegates.tabs.getTabs();
    for (TabMapEntry mapEntry : list) {
        TabItemInterface itemInterface = mapEntry.getObject();
        if (!itemInterface.canBeClosed()) {
            // Show the tab
            tabfolder.setSelected(mapEntry.getTabItem());
            // Unsaved work that needs to changes to be applied?
            // 
            int reply = itemInterface.showChangedWarning();
            if (reply == SWT.YES) {
                exit = itemInterface.applyChanges();
            } else {
                if (reply == SWT.CANCEL) {
                    return false;
                } else {
                    // SWT.NO
                    exit = true;
                }
            }
        }
    }
    if (exit || !canCancel) {
        // all the tabs, stop the running transformations
        for (TabMapEntry mapEntry : list) {
            if (!mapEntry.getObject().canBeClosed()) {
                // 
                if (mapEntry.getObject() instanceof TransGraph) {
                    TransMeta transMeta = (TransMeta) mapEntry.getObject().getManagedObject();
                    if (transMeta.hasChanged()) {
                        delegates.tabs.removeTab(mapEntry);
                    }
                }
                // 
                if (mapEntry.getObject() instanceof TransGraph) {
                    TransGraph transGraph = (TransGraph) mapEntry.getObject();
                    if (transGraph.isRunning()) {
                        transGraph.stop();
                        delegates.tabs.removeTab(mapEntry);
                    }
                }
            }
        }
    }
    try {
        lifecycleSupport.onExit(this);
    } catch (LifecycleException e) {
        MessageBox box = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
        box.setMessage(e.getMessage());
        box.open();
    }
    if (exit) {
        // so we first move the focus to somewhere else
        if (this.selectionFilter != null && !this.selectionFilter.isDisposed()) {
            this.selectionFilter.forceFocus();
        }
        close();
    }
    return exit;
}
Also used : LifecycleException(org.pentaho.di.core.lifecycle.LifecycleException) TransMeta(org.pentaho.di.trans.TransMeta) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 32 with TransGraph

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

the class Spoon method zoom100Percent.

public void zoom100Percent() {
    TransGraph transGraph = getActiveTransGraph();
    if (transGraph != null) {
        transGraph.zoom100Percent();
    }
    JobGraph jobGraph = getActiveJobGraph();
    if (jobGraph != null) {
        jobGraph.zoom100Percent();
    }
}
Also used : JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph)

Example 33 with TransGraph

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

the class Spoon method printTransFile.

private void printTransFile(TransMeta transMeta) {
    TransGraph transGraph = getActiveTransGraph();
    if (transGraph == null) {
        return;
    }
    PrintSpool ps = new PrintSpool();
    Printer printer = ps.getPrinter(shell);
    // Create an image of the screen
    Point max = transMeta.getMaximum();
    Image img = transGraph.getTransformationImage(printer, max.x, max.y, 1.0f);
    ps.printImage(shell, img);
    img.dispose();
    ps.dispose();
}
Also used : TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) PrintSpool(org.pentaho.di.ui.core.PrintSpool) Printer(org.eclipse.swt.printing.Printer) Image(org.eclipse.swt.graphics.Image)

Example 34 with TransGraph

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

the class CsvInputDialog method updatePreview.

/**
 * Load metadata from step window
 */
protected void updatePreview() {
    if (initializing) {
        return;
    }
    if (previewBusy.get()) {
        return;
    }
    try {
        previewBusy.set(true);
        CsvInputMeta meta = new CsvInputMeta();
        getInfo(meta);
        // 
        if (Utils.isEmpty(meta.getFilename())) {
            return;
        }
        if (Utils.isEmpty(meta.getInputFields())) {
            return;
        }
        String stepname = wStepname.getText();
        // StepMeta stepMeta = new StepMeta(stepname, meta);
        StringBuffer buffer = new StringBuffer();
        final List<Object[]> rowsData = new ArrayList<Object[]>();
        final RowMetaInterface rowMeta = new RowMeta();
        try {
            meta.getFields(rowMeta, stepname, null, null, transMeta, repository, metaStore);
            TransMeta previewTransMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, meta, stepname);
            final Trans trans = new Trans(previewTransMeta);
            trans.prepareExecution(null);
            StepInterface step = trans.getRunThread(stepname, 0);
            step.addRowListener(new RowAdapter() {

                @Override
                public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                    rowsData.add(row);
                    // 
                    if (rowsData.size() > PropsUI.getInstance().getDefaultPreviewSize()) {
                        trans.stopAll();
                    }
                }
            });
            trans.startThreads();
            trans.waitUntilFinished();
            if (trans.getErrors() > 0) {
                StringBuffer log = KettleLogStore.getAppender().getBuffer(trans.getLogChannelId(), false);
                buffer.append(log);
            }
            KettleLogStore.discardLines(trans.getLogChannelId(), false);
            LoggingRegistry.getInstance().removeIncludingChildren(trans.getLogChannelId());
        } catch (Exception e) {
            buffer.append(Const.getStackTracker(e));
        }
        TransGraph transGraph = Spoon.getInstance().getActiveTransGraph();
        if (transGraph != null) {
            if (!transGraph.isExecutionResultsPaneVisible()) {
                transGraph.showExecutionResults();
            }
            transGraph.extraViewTabFolder.setSelection(5);
            transGraph.transPreviewDelegate.addPreviewData(stepMeta, rowMeta, rowsData, buffer);
            transGraph.transPreviewDelegate.setSelectedStep(stepMeta);
            transGraph.transPreviewDelegate.refreshView();
        }
    } finally {
        previewBusy.set(false);
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) CsvInputMeta(org.pentaho.di.trans.steps.csvinput.CsvInputMeta) ArrayList(java.util.ArrayList) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) SWTException(org.eclipse.swt.SWTException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) StepInterface(org.pentaho.di.trans.step.StepInterface) RowAdapter(org.pentaho.di.trans.step.RowAdapter) FileObject(org.apache.commons.vfs2.FileObject) Trans(org.pentaho.di.trans.Trans)

Example 35 with TransGraph

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

the class SpoonTransformationDelegate method executeTransformation.

public void executeTransformation(final TransMeta transMeta, final boolean local, final boolean remote, final boolean cluster, final boolean preview, final boolean debug, final Date replayDate, final boolean safe, LogLevel logLevel) throws KettleException {
    if (transMeta == null) {
        return;
    }
    // See if we need to ask for debugging information...
    // 
    TransDebugMeta transDebugMeta = null;
    TransExecutionConfiguration executionConfiguration = null;
    if (preview) {
        executionConfiguration = spoon.getTransPreviewExecutionConfiguration();
    } else if (debug) {
        executionConfiguration = spoon.getTransDebugExecutionConfiguration();
    } else {
        executionConfiguration = spoon.getTransExecutionConfiguration();
    }
    // Set defaults so the run configuration can set it up correctly
    executionConfiguration.setExecutingLocally(true);
    executionConfiguration.setExecutingRemotely(false);
    executionConfiguration.setExecutingClustered(false);
    // Set repository and safe mode information in both the exec config and the metadata
    transMeta.setRepository(spoon.rep);
    transMeta.setMetaStore(spoon.metaStore);
    executionConfiguration.setRepository(spoon.rep);
    executionConfiguration.setSafeModeEnabled(safe);
    if (debug) {
        // See if we have debugging information stored somewhere?
        // 
        transDebugMeta = transDebugMetaMap.get(transMeta);
        if (transDebugMeta == null) {
            transDebugMeta = new TransDebugMeta(transMeta);
            transDebugMetaMap.put(transMeta, transDebugMeta);
        }
        // Set the default number of rows to retrieve on all selected steps...
        // 
        List<StepMeta> selectedSteps = transMeta.getSelectedSteps();
        if (selectedSteps != null && selectedSteps.size() > 0) {
            transDebugMeta.getStepDebugMetaMap().clear();
            for (StepMeta stepMeta : transMeta.getSelectedSteps()) {
                StepDebugMeta stepDebugMeta = new StepDebugMeta(stepMeta);
                stepDebugMeta.setRowCount(PropsUI.getInstance().getDefaultPreviewSize());
                stepDebugMeta.setPausingOnBreakPoint(true);
                stepDebugMeta.setReadingFirstRows(false);
                transDebugMeta.getStepDebugMetaMap().put(stepMeta, stepDebugMeta);
            }
        }
    } else if (preview) {
        // See if we have preview information stored somewhere?
        // 
        transDebugMeta = transPreviewMetaMap.get(transMeta);
        if (transDebugMeta == null) {
            transDebugMeta = new TransDebugMeta(transMeta);
            transPreviewMetaMap.put(transMeta, transDebugMeta);
        }
        // Set the default number of preview rows on all selected steps...
        // 
        List<StepMeta> selectedSteps = transMeta.getSelectedSteps();
        if (selectedSteps != null && selectedSteps.size() > 0) {
            transDebugMeta.getStepDebugMetaMap().clear();
            for (StepMeta stepMeta : transMeta.getSelectedSteps()) {
                StepDebugMeta stepDebugMeta = new StepDebugMeta(stepMeta);
                stepDebugMeta.setRowCount(PropsUI.getInstance().getDefaultPreviewSize());
                stepDebugMeta.setPausingOnBreakPoint(false);
                stepDebugMeta.setReadingFirstRows(true);
                transDebugMeta.getStepDebugMetaMap().put(stepMeta, stepDebugMeta);
            }
        }
    }
    int debugAnswer = TransDebugDialog.DEBUG_CONFIG;
    if (debug || preview) {
        // pass repository for mappings
        transDebugMeta.getTransMeta().setRepository(spoon.rep);
        TransDebugDialog transDebugDialog = new TransDebugDialog(spoon.getShell(), transDebugMeta);
        debugAnswer = transDebugDialog.open();
        if (debugAnswer != TransDebugDialog.DEBUG_CANCEL) {
            executionConfiguration.setExecutingLocally(true);
            executionConfiguration.setExecutingRemotely(false);
            executionConfiguration.setExecutingClustered(false);
        } else {
            // 
            return;
        }
    }
    Object[] data = spoon.variables.getData();
    String[] fields = spoon.variables.getRowMeta().getFieldNames();
    Map<String, String> variableMap = new HashMap<String, String>();
    // the default
    variableMap.putAll(executionConfiguration.getVariables());
    for (int idx = 0; idx < fields.length; idx++) {
        String value = executionConfiguration.getVariables().get(fields[idx]);
        if (Utils.isEmpty(value)) {
            value = data[idx].toString();
        }
        variableMap.put(fields[idx], value);
    }
    executionConfiguration.setVariables(variableMap);
    executionConfiguration.getUsedVariables(transMeta);
    executionConfiguration.getUsedArguments(transMeta, spoon.getArguments());
    executionConfiguration.setReplayDate(replayDate);
    executionConfiguration.setLogLevel(logLevel);
    boolean execConfigAnswer = true;
    if (debugAnswer == TransDebugDialog.DEBUG_CONFIG && replayDate == null && transMeta.isShowDialog()) {
        TransExecutionConfigurationDialog dialog = new TransExecutionConfigurationDialog(spoon.getShell(), executionConfiguration, transMeta);
        execConfigAnswer = dialog.open();
    }
    if (execConfigAnswer) {
        TransGraph activeTransGraph = spoon.getActiveTransGraph();
        activeTransGraph.transLogDelegate.addTransLog();
        // Set the named parameters
        Map<String, String> paramMap = executionConfiguration.getParams();
        for (String key : paramMap.keySet()) {
            transMeta.setParameterValue(key, Const.NVL(paramMap.get(key), ""));
        }
        transMeta.activateParameters();
        // 
        if (executionConfiguration.getLogLevel() != null) {
            transMeta.setLogLevel(executionConfiguration.getLogLevel());
        }
        // Set the run options
        transMeta.setClearingLog(executionConfiguration.isClearingLog());
        transMeta.setSafeModeEnabled(executionConfiguration.isSafeModeEnabled());
        transMeta.setGatheringMetrics(executionConfiguration.isGatheringMetrics());
        ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonTransMetaExecutionStart.id, transMeta);
        ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonTransExecutionConfiguration.id, executionConfiguration);
        try {
            ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonTransBeforeStart.id, new Object[] { executionConfiguration, transMeta, transMeta, spoon.getRepository() });
        } catch (KettleException e) {
            log.logError(e.getMessage(), transMeta.getFilename());
            return;
        }
        if (!executionConfiguration.isExecutingLocally() && !executionConfiguration.isExecutingRemotely()) {
            if (transMeta.hasChanged()) {
                activeTransGraph.showSaveFileMessage();
            }
        }
        // 
        if (debug || preview) {
            if (transDebugMeta.getNrOfUsedSteps() == 0) {
                MessageBox box = new MessageBox(spoon.getShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO);
                box.setText(BaseMessages.getString(PKG, "Spoon.Dialog.Warning.NoPreviewOrDebugSteps.Title"));
                box.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.Warning.NoPreviewOrDebugSteps.Message"));
                int answer = box.open();
                if (answer != SWT.YES) {
                    return;
                }
            }
        }
        // 
        if (executionConfiguration.isExecutingLocally()) {
            if (debug || preview) {
                activeTransGraph.debug(executionConfiguration, transDebugMeta);
            } else {
                activeTransGraph.start(executionConfiguration);
            }
        // Are we executing remotely?
        // 
        } else if (executionConfiguration.isExecutingRemotely()) {
            activeTransGraph.handleTransMetaChanges(transMeta);
            if (transMeta.hasChanged()) {
                showSaveTransformationBeforeRunningDialog(spoon.getShell());
            } else if (executionConfiguration.getRemoteServer() != null) {
                String carteObjectId = Trans.sendToSlaveServer(transMeta, executionConfiguration, spoon.rep, spoon.metaStore);
                monitorRemoteTrans(transMeta, carteObjectId, executionConfiguration.getRemoteServer());
                spoon.delegates.slaves.addSpoonSlave(executionConfiguration.getRemoteServer());
            } else {
                MessageBox mb = new MessageBox(spoon.getShell(), SWT.OK | SWT.ICON_INFORMATION);
                mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.NoRemoteServerSpecified.Message"));
                mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.NoRemoteServerSpecified.Title"));
                mb.open();
            }
        // Are we executing clustered?
        // 
        } else if (executionConfiguration.isExecutingClustered()) {
            activeTransGraph.handleTransMetaChanges(transMeta);
            if (transMeta.hasChanged()) {
                showSaveTransformationBeforeRunningDialog(spoon.getShell());
            } else {
                splitTrans(transMeta, executionConfiguration);
            }
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) HashMap(java.util.HashMap) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) MessageBox(org.eclipse.swt.widgets.MessageBox) TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) TransDebugDialog(org.pentaho.di.ui.trans.debug.TransDebugDialog) ArrayList(java.util.ArrayList) List(java.util.List) TransExecutionConfigurationDialog(org.pentaho.di.ui.trans.dialog.TransExecutionConfigurationDialog) TransDebugMeta(org.pentaho.di.trans.debug.TransDebugMeta) StepDebugMeta(org.pentaho.di.trans.debug.StepDebugMeta)

Aggregations

TransGraph (org.pentaho.di.ui.spoon.trans.TransGraph)37 JobGraph (org.pentaho.di.ui.spoon.job.JobGraph)15 TransMeta (org.pentaho.di.trans.TransMeta)10 Test (org.junit.Test)8 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)7 ArrayList (java.util.ArrayList)6 Point (org.pentaho.di.core.gui.Point)6 JobMeta (org.pentaho.di.job.JobMeta)6 StepMeta (org.pentaho.di.trans.step.StepMeta)6 EngineMetaInterface (org.pentaho.di.core.EngineMetaInterface)5 KettleException (org.pentaho.di.core.exception.KettleException)5 TabMapEntry (org.pentaho.di.ui.spoon.TabMapEntry)5 Browser (org.eclipse.swt.browser.Browser)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)4 FileObject (org.apache.commons.vfs2.FileObject)3 SashForm (org.eclipse.swt.custom.SashForm)3 Composite (org.eclipse.swt.widgets.Composite)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)3 TabItem (org.pentaho.xul.swt.tab.TabItem)3