Search in sources :

Example 1 with MetaInjectOutputField

use of org.pentaho.di.trans.steps.metainject.MetaInjectOutputField in project pentaho-kettle by pentaho.

the class MetaInjectDialog method ok.

private void ok() {
    if (Utils.isEmpty(wStepname.getText())) {
        return;
    }
    // return value
    stepname = wStepname.getText();
    try {
        loadTransformation();
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "MetaInjectDialog.ErrorLoadingSpecifiedTransformation.Title"), BaseMessages.getString(PKG, "MetaInjectDialog.ErrorLoadingSpecifiedTransformation.Message"), e);
    }
    if (repository != null) {
        specificationMethod = ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME;
    } else {
        specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
    }
    metaInjectMeta.setSpecificationMethod(specificationMethod);
    switch(specificationMethod) {
        case FILENAME:
            metaInjectMeta.setFileName(wPath.getText());
            metaInjectMeta.setDirectoryPath(null);
            metaInjectMeta.setTransName(null);
            metaInjectMeta.setTransObjectId(null);
            break;
        case REPOSITORY_BY_NAME:
            String transPath = wPath.getText();
            String transName = transPath;
            String directory = "";
            int index = transPath.lastIndexOf("/");
            if (index != -1) {
                transName = transPath.substring(index + 1);
                directory = transPath.substring(0, index);
            }
            metaInjectMeta.setDirectoryPath(directory);
            metaInjectMeta.setTransName(transName);
            metaInjectMeta.setFileName(null);
            metaInjectMeta.setTransObjectId(null);
            break;
        default:
            break;
    }
    metaInjectMeta.setSourceStepName(wSourceStep.getText());
    metaInjectMeta.setSourceOutputFields(new ArrayList<MetaInjectOutputField>());
    for (int i = 0; i < wSourceFields.nrNonEmpty(); i++) {
        TableItem item = wSourceFields.getNonEmpty(i);
        int colIndex = 1;
        String name = item.getText(colIndex++);
        int type = ValueMetaFactory.getIdForValueMeta(item.getText(colIndex++));
        int length = Const.toInt(item.getText(colIndex++), -1);
        int precision = Const.toInt(item.getText(colIndex++), -1);
        metaInjectMeta.getSourceOutputFields().add(new MetaInjectOutputField(name, type, length, precision));
    }
    metaInjectMeta.setTargetFile(wTargetFile.getText());
    metaInjectMeta.setNoExecution(!wNoExecution.getSelection());
    final StepMeta streamSourceStep = transMeta.findStep(wStreamingSourceStep.getText());
    metaInjectMeta.setStreamSourceStep(streamSourceStep);
    // PDI-15989 Save streamSourceStepname to find streamSourceStep when loading
    metaInjectMeta.setStreamSourceStepname(streamSourceStep != null ? streamSourceStep.getName() : "");
    metaInjectMeta.setStreamTargetStepname(wStreamingTargetStep.getText());
    metaInjectMeta.setTargetSourceMapping(targetSourceMapping);
    metaInjectMeta.setChanged(true);
    dispose();
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TableItem(org.eclipse.swt.widgets.TableItem) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) MetaInjectOutputField(org.pentaho.di.trans.steps.metainject.MetaInjectOutputField) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Point(org.eclipse.swt.graphics.Point)

Example 2 with MetaInjectOutputField

use of org.pentaho.di.trans.steps.metainject.MetaInjectOutputField in project pentaho-kettle by pentaho.

the class MetaInjectDialog method getData.

/**
 * Copy information from the meta-data input to the dialog fields.
 */
public void getData() {
    specificationMethod = metaInjectMeta.getSpecificationMethod();
    switch(specificationMethod) {
        case FILENAME:
            wPath.setText(Const.NVL(metaInjectMeta.getFileName(), ""));
            break;
        case REPOSITORY_BY_NAME:
            String fullPath = Const.NVL(metaInjectMeta.getDirectoryPath(), "") + "/" + Const.NVL(metaInjectMeta.getTransName(), "");
            wPath.setText(fullPath);
            break;
        case REPOSITORY_BY_REFERENCE:
            referenceObjectId = metaInjectMeta.getTransObjectId();
            getByReferenceData(referenceObjectId);
            break;
        default:
            break;
    }
    wSourceStep.setText(Const.NVL(metaInjectMeta.getSourceStepName(), ""));
    int rownr = 0;
    for (MetaInjectOutputField field : metaInjectMeta.getSourceOutputFields()) {
        int colnr = 1;
        wSourceFields.setText(field.getName(), colnr++, rownr);
        wSourceFields.setText(field.getTypeDescription(), colnr++, rownr);
        wSourceFields.setText(field.getLength() < 0 ? "" : Integer.toString(field.getLength()), colnr++, rownr);
        wSourceFields.setText(field.getPrecision() < 0 ? "" : Integer.toString(field.getPrecision()), colnr++, rownr);
        rownr++;
    }
    wTargetFile.setText(Const.NVL(metaInjectMeta.getTargetFile(), ""));
    wNoExecution.setSelection(!metaInjectMeta.isNoExecution());
    wStreamingSourceStep.setText(Const.NVL(metaInjectMeta.getStreamSourceStep() == null ? null : metaInjectMeta.getStreamSourceStep().getName(), ""));
    wStreamingTargetStep.setText(Const.NVL(metaInjectMeta.getStreamTargetStepname(), ""));
    setActive();
    refreshTree();
    wTabFolder.setSelection(0);
    wStepname.selectAll();
    wStepname.setFocus();
}
Also used : MetaInjectOutputField(org.pentaho.di.trans.steps.metainject.MetaInjectOutputField) Point(org.eclipse.swt.graphics.Point)

Aggregations

Point (org.eclipse.swt.graphics.Point)2 MetaInjectOutputField (org.pentaho.di.trans.steps.metainject.MetaInjectOutputField)2 TableItem (org.eclipse.swt.widgets.TableItem)1 KettleException (org.pentaho.di.core.exception.KettleException)1 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1