Search in sources :

Example 6 with ValueMetaInterface

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

the class SetValueConstantDialog method get.

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

                public boolean tableItemInserted(TableItem tableItem, ValueMetaInterface v) {
                    return true;
                }
            };
            BaseStepDialog.getFieldsFromPrevious(r, wFields, 1, new int[] { 1 }, new int[] {}, -1, -1, insertListener);
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Title"), BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"), 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 7 with ValueMetaInterface

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

the class TextFileOutputDialog 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) {
                    if (v.isNumeric()) {
                        // currency symbol
                        tableItem.setText(6, Const.NVL(v.getCurrencySymbol(), ""));
                        // decimal and grouping
                        tableItem.setText(7, Const.NVL(v.getDecimalSymbol(), ""));
                        tableItem.setText(8, Const.NVL(v.getGroupingSymbol(), ""));
                    }
                    // trim type
                    tableItem.setText(9, Const.NVL(ValueMetaString.getTrimTypeDesc(v.getTrimType()), ""));
                    // conversion mask
                    if (!Utils.isEmpty(v.getConversionMask())) {
                        tableItem.setText(3, v.getConversionMask());
                    } else {
                        if (v.isNumber()) {
                            if (v.getLength() > 0) {
                                int le = v.getLength();
                                int pr = v.getPrecision();
                                if (v.getPrecision() <= 0) {
                                    pr = 0;
                                }
                                String mask = "";
                                for (int m = 0; m < le - pr; m++) {
                                    mask += "0";
                                }
                                if (pr > 0) {
                                    mask += ".";
                                }
                                for (int m = 0; m < pr; m++) {
                                    mask += "0";
                                }
                                tableItem.setText(3, mask);
                            }
                        }
                    }
                    return true;
                }
            };
            BaseStepDialog.getFieldsFromPrevious(r, wFields, 1, new int[] { 1 }, new int[] { 2 }, 4, 5, listener);
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Title"), BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"), 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) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Point(org.eclipse.swt.graphics.Point) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 8 with ValueMetaInterface

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

the class ValidatorDialog method showSelectedValidatorField.

private void showSelectedValidatorField(String selection) {
    // Someone hit a field...
    // 
    saveChanges();
    Validation field = Validation.findValidation(selectionList, selection);
    if (field == null) {
        field = new Validation(selection);
        ValueMetaInterface valueMeta = inputFields.searchValueMeta(selection);
        if (valueMeta != null) {
            // Set the default data type
            // 
            field.setDataType(valueMeta.getType());
        }
    }
    selectedField = field;
    getValidatorFieldData(selectedField);
    enableFields();
}
Also used : Validation(org.pentaho.di.trans.steps.validator.Validation) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 9 with ValueMetaInterface

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

the class WebServiceDialog method getOutWebServiceFields.

private RowMetaInterface getOutWebServiceFields() {
    RowMetaInterface r = null;
    if (outWsdlParamContainer != null) {
        r = new RowMeta();
        String[] outParams = outWsdlParamContainer.getParamNames();
        // If we have already saved fields mapping, we only show these mappings
        for (int cpt = 0; cpt < outParams.length; cpt++) {
            ValueMetaInterface value = new ValueMeta(outParams[cpt], XsdType.xsdTypeToKettleType(outWsdlParamContainer.getParamType(outParams[cpt])));
            r.addValueMeta(value);
        }
    }
    return r;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 10 with ValueMetaInterface

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

the class TableOutputDialog method generateMappings.

/**
 * Reads in the fields from the previous steps and from the ONE next step and opens an EnterMappingDialog with this
 * information. After the user did the mapping, those information is put into the Select/Rename table.
 */
private void generateMappings() {
    // Determine the source and target fields...
    // 
    RowMetaInterface sourceFields;
    RowMetaInterface targetFields;
    try {
        sourceFields = transMeta.getPrevStepFields(stepMeta);
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TableOutputDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "TableOutputDialog.DoMapping.UnableToFindSourceFields.Message"), e);
        return;
    }
    // refresh data
    input.setDatabaseMeta(transMeta.findDatabase(wConnection.getText()));
    input.setTableName(transMeta.environmentSubstitute(wTable.getText()));
    StepMetaInterface stepMetaInterface = stepMeta.getStepMetaInterface();
    try {
        targetFields = stepMetaInterface.getRequiredFields(transMeta);
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TableOutputDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "TableOutputDialog.DoMapping.UnableToFindTargetFields.Message"), e);
        return;
    }
    String[] inputNames = new String[sourceFields.size()];
    for (int i = 0; i < sourceFields.size(); i++) {
        ValueMetaInterface value = sourceFields.getValueMeta(i);
        inputNames[i] = value.getName() + EnterMappingDialog.STRING_ORIGIN_SEPARATOR + value.getOrigin() + ")";
    }
    // Create the existing mapping list...
    // 
    List<SourceToTargetMapping> mappings = new ArrayList<SourceToTargetMapping>();
    StringBuilder missingSourceFields = new StringBuilder();
    StringBuilder missingTargetFields = new StringBuilder();
    int nrFields = wFields.nrNonEmpty();
    for (int i = 0; i < nrFields; i++) {
        TableItem item = wFields.getNonEmpty(i);
        String source = item.getText(2);
        String target = item.getText(1);
        int sourceIndex = sourceFields.indexOfValue(source);
        if (sourceIndex < 0) {
            missingSourceFields.append(Const.CR).append("   ").append(source).append(" --> ").append(target);
        }
        int targetIndex = targetFields.indexOfValue(target);
        if (targetIndex < 0) {
            missingTargetFields.append(Const.CR).append("   ").append(source).append(" --> ").append(target);
        }
        if (sourceIndex < 0 || targetIndex < 0) {
            continue;
        }
        SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
        mappings.add(mapping);
    }
    // 
    if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
        String message = "";
        if (missingSourceFields.length() > 0) {
            message += BaseMessages.getString(PKG, "TableOutputDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
        }
        if (missingTargetFields.length() > 0) {
            message += BaseMessages.getString(PKG, "TableOutputDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
        }
        message += Const.CR;
        message += BaseMessages.getString(PKG, "TableOutputDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
        MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "TableOutputDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
        if (!goOn) {
            return;
        }
    }
    EnterMappingDialog d = new EnterMappingDialog(TableOutputDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
    mappings = d.open();
    // 
    if (mappings != null) {
        // Clear and re-populate!
        // 
        wFields.table.removeAll();
        wFields.table.setItemCount(mappings.size());
        for (int i = 0; i < mappings.size(); i++) {
            SourceToTargetMapping mapping = mappings.get(i);
            TableItem item = wFields.table.getItem(i);
            item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
            item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
        }
        wFields.setRowNums();
        wFields.optWidth(true);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) EnterMappingDialog(org.pentaho.di.ui.core.dialog.EnterMappingDialog) TableItem(org.eclipse.swt.widgets.TableItem) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) ArrayList(java.util.ArrayList) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) SourceToTargetMapping(org.pentaho.di.core.SourceToTargetMapping)

Aggregations

ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)796 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)327 KettleException (org.pentaho.di.core.exception.KettleException)262 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)219 RowMeta (org.pentaho.di.core.row.RowMeta)208 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)130 Test (org.junit.Test)123 KettleStepException (org.pentaho.di.core.exception.KettleStepException)117 ArrayList (java.util.ArrayList)94 TableItem (org.eclipse.swt.widgets.TableItem)77 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)76 KettleValueException (org.pentaho.di.core.exception.KettleValueException)54 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)47 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)46 StepMeta (org.pentaho.di.trans.step.StepMeta)46 Database (org.pentaho.di.core.database.Database)45 TableItemInsertListener (org.pentaho.di.ui.trans.step.TableItemInsertListener)43 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)40 FileObject (org.apache.commons.vfs2.FileObject)39 ValueMeta (org.pentaho.di.core.row.ValueMeta)39