Search in sources :

Example 86 with RowMetaInterface

use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.

the class ScriptDialog method test.

private boolean test(boolean getvars, boolean popup) {
    boolean retval = true;
    StyledTextComp wScript = getStyledTextComp();
    String scr = wScript.getText();
    KettleException testException = null;
    Context jscx;
    Scriptable jsscope;
    // Script jsscript;
    // Making Refresh to get Active Script State
    refreshScripts();
    jscx = ContextFactory.getGlobal().enterContext();
    jscx.setOptimizationLevel(-1);
    jsscope = jscx.initStandardObjects(null, false);
    // Adding the existing Scripts to the Context
    for (int i = 0; i < folder.getItemCount(); i++) {
        StyledTextComp sItem = getStyledTextComp(folder.getItem(i));
        Scriptable jsR = Context.toObject(sItem.getText(), jsscope);
        jsscope.put(folder.getItem(i).getText(), jsscope, jsR);
    }
    // Adding the Name of the Transformation to the Context
    jsscope.put("_TransformationName_", jsscope, this.stepname);
    try {
        RowMetaInterface rowMeta = transMeta.getPrevStepFields(stepname);
        if (rowMeta != null) {
            ScriptDummy dummyStep = new ScriptDummy(rowMeta, transMeta.getStepFields(stepname));
            Scriptable jsvalue = Context.toObject(dummyStep, jsscope);
            jsscope.put("_step_", jsscope, jsvalue);
            // Modification for Additional Script parsing
            try {
                if (input.getAddClasses() != null) {
                    for (int i = 0; i < input.getAddClasses().length; i++) {
                        Object jsOut = Context.javaToJS(input.getAddClasses()[i].getAddObject(), jsscope);
                        ScriptableObject.putProperty(jsscope, input.getAddClasses()[i].getJSName(), jsOut);
                    }
                }
            } catch (Exception e) {
                testException = new KettleException(BaseMessages.getString(PKG, "ScriptDialog.CouldNotAddToContext", e.toString()));
                retval = false;
            }
            // Adding some default JavaScriptFunctions to the System
            try {
                Context.javaToJS(ScriptAddedFunctions.class, jsscope);
                ((ScriptableObject) jsscope).defineFunctionProperties(jsFunctionList, ScriptAddedFunctions.class, ScriptableObject.DONTENUM);
            } catch (Exception ex) {
                testException = new KettleException(BaseMessages.getString(PKG, "ScriptDialog.CouldNotAddDefaultFunctions", ex.toString()));
                retval = false;
            }
            // Adding some Constants to the JavaScript
            try {
                jsscope.put("SKIP_TRANSFORMATION", jsscope, Integer.valueOf(SKIP_TRANSFORMATION));
                jsscope.put("ABORT_TRANSFORMATION", jsscope, Integer.valueOf(ABORT_TRANSFORMATION));
                jsscope.put("ERROR_TRANSFORMATION", jsscope, Integer.valueOf(ERROR_TRANSFORMATION));
                jsscope.put("CONTINUE_TRANSFORMATION", jsscope, Integer.valueOf(CONTINUE_TRANSFORMATION));
            } catch (Exception ex) {
                testException = new KettleException(BaseMessages.getString(PKG, "ScriptDialog.CouldNotAddTransformationConstants", ex.toString()));
                retval = false;
            }
            try {
                Object[] row = new Object[rowMeta.size()];
                Scriptable jsRowMeta = Context.toObject(rowMeta, jsscope);
                jsscope.put("rowMeta", jsscope, jsRowMeta);
                for (int i = 0; i < rowMeta.size(); i++) {
                    ValueMetaInterface valueMeta = rowMeta.getValueMeta(i);
                    Object valueData = null;
                    // 
                    if (valueMeta.isDate()) {
                        valueData = new Date();
                    }
                    if (valueMeta.isString()) {
                        valueData = "test value test value test value test value test " + "value test value test value test value test value test value";
                    }
                    if (valueMeta.isInteger()) {
                        valueData = Long.valueOf(0L);
                    }
                    if (valueMeta.isNumber()) {
                        valueData = new Double(0.0);
                    }
                    if (valueMeta.isBigNumber()) {
                        valueData = BigDecimal.ZERO;
                    }
                    if (valueMeta.isBoolean()) {
                        valueData = Boolean.TRUE;
                    }
                    if (valueMeta.isBinary()) {
                        valueData = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
                    }
                    if (valueMeta.isStorageBinaryString()) {
                        valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
                    }
                    row[i] = valueData;
                    Scriptable jsarg = Context.toObject(valueData, jsscope);
                    jsscope.put(valueMeta.getName(), jsscope, jsarg);
                }
                // OK, for these input values, we're going to allow the user to edit the default values...
                // We are displaying a
                // 2)
                // Add support for Value class (new Value())
                Scriptable jsval = Context.toObject(Value.class, jsscope);
                jsscope.put("Value", jsscope, jsval);
                // Add the old style row object for compatibility reasons...
                // 
                Scriptable jsRow = Context.toObject(row, jsscope);
                jsscope.put("row", jsscope, jsRow);
            } catch (Exception ev) {
                testException = new KettleException(BaseMessages.getString(PKG, "ScriptDialog.CouldNotAddInputFields", ev.toString()));
                retval = false;
            }
            try {
                // Checking for StartScript
                if (strActiveStartScript != null && !folder.getSelection().getText().equals(strActiveStartScript) && strActiveStartScript.length() > 0) {
                    String strStartScript = getStyledTextComp(folder.getItem(getCTabPosition(strActiveStartScript))).getText();
                    /* Object startScript = */
                    jscx.evaluateString(jsscope, strStartScript, "trans_Start", 1, null);
                }
            } catch (Exception e) {
                testException = new KettleException(BaseMessages.getString(PKG, "ScriptDialog.CouldProcessStartScript", e.toString()));
                retval = false;
            }
            try {
                Script evalScript = jscx.compileString(scr, "script", 1, null);
                evalScript.exec(jscx, jsscope);
                if (getvars) {
                    ScriptNode tree = parseVariables(jscx, jsscope, scr, "script", 1, null);
                    for (int i = 0; i < tree.getParamAndVarCount(); i++) {
                        String varname = tree.getParamOrVarName(i);
                        if (!varname.equalsIgnoreCase("row") && !varname.equalsIgnoreCase("trans_Status")) {
                            int type = ValueMetaInterface.TYPE_STRING;
                            int length = -1, precision = -1;
                            Object result = jsscope.get(varname, jsscope);
                            if (result != null) {
                                String classname = result.getClass().getName();
                                if (classname.equalsIgnoreCase("java.lang.Byte")) {
                                    // MAX = 127
                                    type = ValueMetaInterface.TYPE_INTEGER;
                                    length = 3;
                                    precision = 0;
                                } else if (classname.equalsIgnoreCase("java.lang.Integer")) {
                                    // MAX = 2147483647
                                    type = ValueMetaInterface.TYPE_INTEGER;
                                    length = 9;
                                    precision = 0;
                                } else if (classname.equalsIgnoreCase("java.lang.Long")) {
                                    // MAX = 9223372036854775807
                                    type = ValueMetaInterface.TYPE_INTEGER;
                                    length = 18;
                                    precision = 0;
                                } else if (classname.equalsIgnoreCase("java.lang.Double")) {
                                    type = ValueMetaInterface.TYPE_NUMBER;
                                    length = 16;
                                    precision = 2;
                                } else if (classname.equalsIgnoreCase("org.mozilla.javascript.NativeDate") || classname.equalsIgnoreCase("java.util.Date")) {
                                    type = ValueMetaInterface.TYPE_DATE;
                                } else if (classname.equalsIgnoreCase("java.lang.Boolean")) {
                                    type = ValueMetaInterface.TYPE_BOOLEAN;
                                }
                            }
                            TableItem ti = new TableItem(wFields.table, SWT.NONE);
                            ti.setText(1, varname);
                            ti.setText(2, "");
                            ti.setText(3, ValueMetaFactory.getValueMetaName(type));
                            ti.setText(4, length >= 0 ? ("" + length) : "");
                            ti.setText(5, precision >= 0 ? ("" + precision) : "");
                            // If the variable name exists in the input, suggest to replace the value
                            // 
                            ti.setText(6, (rowMeta.indexOfValue(varname) >= 0) ? YES_NO_COMBO[1] : YES_NO_COMBO[0]);
                        }
                    }
                    wFields.removeEmptyRows();
                    wFields.setRowNums();
                    wFields.optWidth(true);
                }
            // End Script!
            } catch (EvaluatorException e) {
                String position = "(" + e.lineNumber() + ":" + e.columnNumber() + ")";
                String message = BaseMessages.getString(PKG, "ScriptDialog.Exception.CouldNotExecuteScript", position);
                testException = new KettleException(message, e);
                retval = false;
            } catch (JavaScriptException e) {
                String position = "(" + e.lineNumber() + ":" + e.columnNumber() + ")";
                String message = BaseMessages.getString(PKG, "ScriptDialog.Exception.CouldNotExecuteScript", position);
                testException = new KettleException(message, e);
                retval = false;
            } catch (Exception e) {
                testException = new KettleException(BaseMessages.getString(PKG, "ScriptDialog.Exception.CouldNotExecuteScript2"), e);
                retval = false;
            }
        } else {
            testException = new KettleException(BaseMessages.getString(PKG, "ScriptDialog.Exception.CouldNotGetFields"));
            retval = false;
        }
        if (popup) {
            if (retval) {
                if (!getvars) {
                    MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                    mb.setMessage(BaseMessages.getString(PKG, "ScriptDialog.ScriptCompilationOK") + Const.CR);
                    mb.setText("OK");
                    mb.open();
                }
            } else {
                new ErrorDialog(shell, BaseMessages.getString(PKG, "ScriptDialog.TestFailed.DialogTitle"), BaseMessages.getString(PKG, "ScriptDialog.TestFailed.DialogMessage"), testException);
            }
        }
    } catch (KettleException ke) {
        retval = false;
        new ErrorDialog(shell, BaseMessages.getString(PKG, "ScriptDialog.TestFailed.DialogTitle"), BaseMessages.getString(PKG, "ScriptDialog.TestFailed.DialogMessage"), ke);
    } finally {
        if (jscx != null) {
            Context.exit();
        }
    }
    return retval;
}
Also used : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) Context(org.mozilla.javascript.Context) KettleException(org.pentaho.di.core.exception.KettleException) Script(org.mozilla.javascript.Script) ScriptValuesScript(org.pentaho.di.trans.steps.script.ScriptValuesScript) ScriptableObject(org.mozilla.javascript.ScriptableObject) TableItem(org.eclipse.swt.widgets.TableItem) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Scriptable(org.mozilla.javascript.Scriptable) ScriptNode(org.mozilla.javascript.ast.ScriptNode) Point(org.eclipse.swt.graphics.Point) EvaluatorException(org.mozilla.javascript.EvaluatorException) JavaScriptException(org.mozilla.javascript.JavaScriptException) KettleException(org.pentaho.di.core.exception.KettleException) Date(java.util.Date) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) JavaScriptException(org.mozilla.javascript.JavaScriptException) MessageBox(org.eclipse.swt.widgets.MessageBox) EvaluatorException(org.mozilla.javascript.EvaluatorException) ScriptableObject(org.mozilla.javascript.ScriptableObject) ScriptDummy(org.pentaho.di.trans.steps.script.ScriptDummy)

Example 87 with RowMetaInterface

use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.

the class GetTableNamesDialog method setSchemaField.

private void setSchemaField() {
    if (!gotpreviousfields) {
        try {
            String value = wSchemaField.getText();
            wSchemaField.removeAll();
            RowMetaInterface r = transMeta.getPrevStepFields(stepname);
            if (r != null) {
                wSchemaField.setItems(r.getFieldNames());
            }
            if (value != null) {
                wSchemaField.setText(value);
            }
        } catch (KettleException ke) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "GetTableNamesDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "GetTableNamesDialog.FailedToGetFields.DialogMessage"), ke);
        }
        gotpreviousfields = true;
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface)

Example 88 with RowMetaInterface

use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.

the class GroupByDialog method open.

public String open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
    props.setLook(shell);
    setShellImage(shell, input);
    ModifyListener lsMod = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            input.setChanged();
        }
    };
    backupChanged = input.hasChanged();
    backupAllRows = input.passAllRows();
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "GroupByDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "GroupByDialog.Stepname.Label"));
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.right = new FormAttachment(middle, -margin);
    fdlStepname.top = new FormAttachment(0, margin);
    wlStepname.setLayoutData(fdlStepname);
    wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wStepname.setText(stepname);
    props.setLook(wStepname);
    wStepname.addModifyListener(lsMod);
    fdStepname = new FormData();
    fdStepname.left = new FormAttachment(middle, 0);
    fdStepname.top = new FormAttachment(0, margin);
    fdStepname.right = new FormAttachment(100, 0);
    wStepname.setLayoutData(fdStepname);
    // Include all rows?
    wlAllRows = new Label(shell, SWT.RIGHT);
    wlAllRows.setText(BaseMessages.getString(PKG, "GroupByDialog.AllRows.Label"));
    props.setLook(wlAllRows);
    fdlAllRows = new FormData();
    fdlAllRows.left = new FormAttachment(0, 0);
    fdlAllRows.top = new FormAttachment(wStepname, margin);
    fdlAllRows.right = new FormAttachment(middle, -margin);
    wlAllRows.setLayoutData(fdlAllRows);
    wAllRows = new Button(shell, SWT.CHECK);
    props.setLook(wAllRows);
    fdAllRows = new FormData();
    fdAllRows.left = new FormAttachment(middle, 0);
    fdAllRows.top = new FormAttachment(wStepname, margin);
    fdAllRows.right = new FormAttachment(100, 0);
    wAllRows.setLayoutData(fdAllRows);
    wAllRows.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setPassAllRows(!input.passAllRows());
            input.setChanged();
            setFlags();
        }
    });
    wlSortDir = new Label(shell, SWT.RIGHT);
    wlSortDir.setText(BaseMessages.getString(PKG, "GroupByDialog.TempDir.Label"));
    props.setLook(wlSortDir);
    fdlSortDir = new FormData();
    fdlSortDir.left = new FormAttachment(0, 0);
    fdlSortDir.right = new FormAttachment(middle, -margin);
    fdlSortDir.top = new FormAttachment(wAllRows, margin);
    wlSortDir.setLayoutData(fdlSortDir);
    wbSortDir = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbSortDir);
    wbSortDir.setText(BaseMessages.getString(PKG, "GroupByDialog.Browse.Button"));
    fdbSortDir = new FormData();
    fdbSortDir.right = new FormAttachment(100, 0);
    fdbSortDir.top = new FormAttachment(wAllRows, margin);
    wbSortDir.setLayoutData(fdbSortDir);
    wSortDir = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wSortDir);
    wSortDir.addModifyListener(lsMod);
    fdSortDir = new FormData();
    fdSortDir.left = new FormAttachment(middle, 0);
    fdSortDir.top = new FormAttachment(wAllRows, margin);
    fdSortDir.right = new FormAttachment(wbSortDir, -margin);
    wSortDir.setLayoutData(fdSortDir);
    wbSortDir.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            DirectoryDialog dd = new DirectoryDialog(shell, SWT.NONE);
            dd.setFilterPath(wSortDir.getText());
            String dir = dd.open();
            if (dir != null) {
                wSortDir.setText(dir);
            }
        }
    });
    // Whenever something changes, set the tooltip to the expanded version:
    wSortDir.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            wSortDir.setToolTipText(transMeta.environmentSubstitute(wSortDir.getText()));
        }
    });
    // Prefix line...
    wlPrefix = new Label(shell, SWT.RIGHT);
    wlPrefix.setText(BaseMessages.getString(PKG, "GroupByDialog.FilePrefix.Label"));
    props.setLook(wlPrefix);
    fdlPrefix = new FormData();
    fdlPrefix.left = new FormAttachment(0, 0);
    fdlPrefix.right = new FormAttachment(middle, -margin);
    fdlPrefix.top = new FormAttachment(wbSortDir, margin * 2);
    wlPrefix.setLayoutData(fdlPrefix);
    wPrefix = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wPrefix);
    wPrefix.addModifyListener(lsMod);
    fdPrefix = new FormData();
    fdPrefix.left = new FormAttachment(middle, 0);
    fdPrefix.top = new FormAttachment(wbSortDir, margin * 2);
    fdPrefix.right = new FormAttachment(100, 0);
    wPrefix.setLayoutData(fdPrefix);
    // Include all rows?
    wlAddLineNr = new Label(shell, SWT.RIGHT);
    wlAddLineNr.setText(BaseMessages.getString(PKG, "GroupByDialog.AddLineNr.Label"));
    props.setLook(wlAddLineNr);
    fdlAddLineNr = new FormData();
    fdlAddLineNr.left = new FormAttachment(0, 0);
    fdlAddLineNr.top = new FormAttachment(wPrefix, margin);
    fdlAddLineNr.right = new FormAttachment(middle, -margin);
    wlAddLineNr.setLayoutData(fdlAddLineNr);
    wAddLineNr = new Button(shell, SWT.CHECK);
    props.setLook(wAddLineNr);
    fdAddLineNr = new FormData();
    fdAddLineNr.left = new FormAttachment(middle, 0);
    fdAddLineNr.top = new FormAttachment(wPrefix, margin);
    fdAddLineNr.right = new FormAttachment(100, 0);
    wAddLineNr.setLayoutData(fdAddLineNr);
    wAddLineNr.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setAddingLineNrInGroup(!input.isAddingLineNrInGroup());
            input.setChanged();
            setFlags();
        }
    });
    // LineNrField line...
    wlLineNrField = new Label(shell, SWT.RIGHT);
    wlLineNrField.setText(BaseMessages.getString(PKG, "GroupByDialog.LineNrField.Label"));
    props.setLook(wlLineNrField);
    fdlLineNrField = new FormData();
    fdlLineNrField.left = new FormAttachment(0, 0);
    fdlLineNrField.right = new FormAttachment(middle, -margin);
    fdlLineNrField.top = new FormAttachment(wAddLineNr, margin);
    wlLineNrField.setLayoutData(fdlLineNrField);
    wLineNrField = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wLineNrField);
    wLineNrField.addModifyListener(lsMod);
    fdLineNrField = new FormData();
    fdLineNrField.left = new FormAttachment(middle, 0);
    fdLineNrField.top = new FormAttachment(wAddLineNr, margin);
    fdLineNrField.right = new FormAttachment(100, 0);
    wLineNrField.setLayoutData(fdLineNrField);
    // Always pass a result rows as output
    // 
    wlAlwaysAddResult = new Label(shell, SWT.RIGHT);
    wlAlwaysAddResult.setText(BaseMessages.getString(PKG, "GroupByDialog.AlwaysAddResult.Label"));
    wlAlwaysAddResult.setToolTipText(BaseMessages.getString(PKG, "GroupByDialog.AlwaysAddResult.ToolTip"));
    props.setLook(wlAlwaysAddResult);
    fdlAlwaysAddResult = new FormData();
    fdlAlwaysAddResult.left = new FormAttachment(0, 0);
    fdlAlwaysAddResult.top = new FormAttachment(wLineNrField, margin);
    fdlAlwaysAddResult.right = new FormAttachment(middle, -margin);
    wlAlwaysAddResult.setLayoutData(fdlAlwaysAddResult);
    wAlwaysAddResult = new Button(shell, SWT.CHECK);
    wAlwaysAddResult.setToolTipText(BaseMessages.getString(PKG, "GroupByDialog.AlwaysAddResult.ToolTip"));
    props.setLook(wAlwaysAddResult);
    fdAlwaysAddResult = new FormData();
    fdAlwaysAddResult.left = new FormAttachment(middle, 0);
    fdAlwaysAddResult.top = new FormAttachment(wLineNrField, margin);
    fdAlwaysAddResult.right = new FormAttachment(100, 0);
    wAlwaysAddResult.setLayoutData(fdAlwaysAddResult);
    wlGroup = new Label(shell, SWT.NONE);
    wlGroup.setText(BaseMessages.getString(PKG, "GroupByDialog.Group.Label"));
    props.setLook(wlGroup);
    fdlGroup = new FormData();
    fdlGroup.left = new FormAttachment(0, 0);
    fdlGroup.top = new FormAttachment(wAlwaysAddResult, margin);
    wlGroup.setLayoutData(fdlGroup);
    int nrKeyCols = 1;
    int nrKeyRows = (input.getGroupField() != null ? input.getGroupField().length : 1);
    ciKey = new ColumnInfo[nrKeyCols];
    ciKey[0] = new ColumnInfo(BaseMessages.getString(PKG, "GroupByDialog.ColumnInfo.GroupField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    wGroup = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, ciKey, nrKeyRows, lsMod, props);
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "GroupByDialog.GetFields.Button"));
    fdGet = new FormData();
    fdGet.top = new FormAttachment(wlGroup, margin);
    fdGet.right = new FormAttachment(100, 0);
    wGet.setLayoutData(fdGet);
    fdGroup = new FormData();
    fdGroup.left = new FormAttachment(0, 0);
    fdGroup.top = new FormAttachment(wlGroup, margin);
    fdGroup.right = new FormAttachment(wGet, -margin);
    fdGroup.bottom = new FormAttachment(45, 0);
    wGroup.setLayoutData(fdGroup);
    // THE Aggregate fields
    wlAgg = new Label(shell, SWT.NONE);
    wlAgg.setText(BaseMessages.getString(PKG, "GroupByDialog.Aggregates.Label"));
    props.setLook(wlAgg);
    fdlAgg = new FormData();
    fdlAgg.left = new FormAttachment(0, 0);
    fdlAgg.top = new FormAttachment(wGroup, margin);
    wlAgg.setLayoutData(fdlAgg);
    int UpInsCols = 4;
    int UpInsRows = (input.getAggregateField() != null ? input.getAggregateField().length : 1);
    ciReturn = new ColumnInfo[UpInsCols];
    ciReturn[0] = new ColumnInfo(BaseMessages.getString(PKG, "GroupByDialog.ColumnInfo.Name"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    ciReturn[1] = new ColumnInfo(BaseMessages.getString(PKG, "GroupByDialog.ColumnInfo.Subject"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    ciReturn[2] = new ColumnInfo(BaseMessages.getString(PKG, "GroupByDialog.ColumnInfo.Type"), ColumnInfo.COLUMN_TYPE_CCOMBO, GroupByMeta.typeGroupLongDesc);
    ciReturn[3] = new ColumnInfo(BaseMessages.getString(PKG, "GroupByDialog.ColumnInfo.Value"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    ciReturn[3].setToolTip(BaseMessages.getString(PKG, "GroupByDialog.ColumnInfo.Value.Tooltip"));
    ciReturn[3].setUsingVariables(true);
    wAgg = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, ciReturn, UpInsRows, lsMod, props);
    wGetAgg = new Button(shell, SWT.PUSH);
    wGetAgg.setText(BaseMessages.getString(PKG, "GroupByDialog.GetLookupFields.Button"));
    fdGetAgg = new FormData();
    fdGetAgg.top = new FormAttachment(wlAgg, margin);
    fdGetAgg.right = new FormAttachment(100, 0);
    wGetAgg.setLayoutData(fdGetAgg);
    // 
    // Search the fields in the background
    final Runnable runnable = new Runnable() {

        public void run() {
            StepMeta stepMeta = transMeta.findStep(stepname);
            if (stepMeta != null) {
                try {
                    RowMetaInterface row = transMeta.getPrevStepFields(stepMeta);
                    // Remember these fields...
                    for (int i = 0; i < row.size(); i++) {
                        inputFields.put(row.getValueMeta(i).getName(), Integer.valueOf(i));
                    }
                    setComboBoxes();
                } catch (KettleException e) {
                    logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
                }
            }
        }
    };
    new Thread(runnable).start();
    // THE BUTTONS
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel }, margin, null);
    fdAgg = new FormData();
    fdAgg.left = new FormAttachment(0, 0);
    fdAgg.top = new FormAttachment(wlAgg, margin);
    fdAgg.right = new FormAttachment(wGetAgg, -margin);
    fdAgg.bottom = new FormAttachment(wOK, -margin);
    wAgg.setLayoutData(fdAgg);
    // Add listeners
    lsOK = new Listener() {

        public void handleEvent(Event e) {
            ok();
        }
    };
    lsGet = new Listener() {

        public void handleEvent(Event e) {
            get();
        }
    };
    lsGetAgg = new Listener() {

        public void handleEvent(Event e) {
            getAgg();
        }
    };
    lsCancel = new Listener() {

        public void handleEvent(Event e) {
            cancel();
        }
    };
    wOK.addListener(SWT.Selection, lsOK);
    wGet.addListener(SWT.Selection, lsGet);
    wGetAgg.addListener(SWT.Selection, lsGetAgg);
    wCancel.addListener(SWT.Selection, lsCancel);
    lsDef = new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    // Set the shell size, based upon previous time...
    setSize();
    getData();
    input.setChanged(backupChanged);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) ShellEvent(org.eclipse.swt.events.ShellEvent) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) TableView(org.pentaho.di.ui.core.widget.TableView) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) TextVar(org.pentaho.di.ui.core.widget.TextVar) Event(org.eclipse.swt.widgets.Event) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Display(org.eclipse.swt.widgets.Display)

Example 89 with RowMetaInterface

use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.

the class HTTPPOSTDialog method get.

private void get() {
    try {
        RowMetaInterface r = transMeta.getPrevStepFields(stepname);
        if (r != null && !r.isEmpty()) {
            TableItemInsertListener listener = new TableItemInsertListener() {

                public boolean tableItemInserted(TableItem tableItem, ValueMetaInterface v) {
                    // default is "N"
                    tableItem.setText(3, NO);
                    return true;
                }
            };
            BaseStepDialog.getFieldsFromPrevious(r, wFields, 1, new int[] { 1, 2 }, null, -1, -1, listener);
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "HTTPPOSTDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "HTTPPOSTDialog.FailedToGetFields.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TableItemInsertListener(org.pentaho.di.ui.trans.step.TableItemInsertListener) TableItem(org.eclipse.swt.widgets.TableItem) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 90 with RowMetaInterface

use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.

the class InsertUpdateDialog method get.

private void get() {
    try {
        RowMetaInterface r = transMeta.getPrevStepFields(stepname);
        if (r != null) {
            TableItemInsertListener listener = new TableItemInsertListener() {

                public boolean tableItemInserted(TableItem tableItem, ValueMetaInterface v) {
                    tableItem.setText(2, "=");
                    return true;
                }
            };
            BaseStepDialog.getFieldsFromPrevious(r, wKey, 1, new int[] { 1, 3 }, new int[] {}, -1, -1, listener);
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "InsertUpdateDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "InsertUpdateDialog.FailedToGetFields.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TableItemInsertListener(org.pentaho.di.ui.trans.step.TableItemInsertListener) TableItem(org.eclipse.swt.widgets.TableItem) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)908 KettleException (org.pentaho.di.core.exception.KettleException)369 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)330 RowMeta (org.pentaho.di.core.row.RowMeta)275 ArrayList (java.util.ArrayList)206 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)196 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)180 Test (org.junit.Test)169 StepMeta (org.pentaho.di.trans.step.StepMeta)150 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)142 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)110 KettleStepException (org.pentaho.di.core.exception.KettleStepException)107 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)101 TableItem (org.eclipse.swt.widgets.TableItem)84 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)84 Database (org.pentaho.di.core.database.Database)81 TableItemInsertListener (org.pentaho.di.ui.trans.step.TableItemInsertListener)79 FormAttachment (org.eclipse.swt.layout.FormAttachment)76 FormData (org.eclipse.swt.layout.FormData)76 FormLayout (org.eclipse.swt.layout.FormLayout)76