Search in sources :

Example 41 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class TeraFastDialog 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.
 */
public void generateMappings() {
    // Determine the source and target fields...
    // 
    RowMetaInterface sourceFields;
    RowMetaInterface targetFields;
    try {
        sourceFields = this.transMeta.getPrevStepFields(this.stepMeta);
    } catch (KettleException e) {
        new ErrorDialog(this.shell, BaseMessages.getString(PKG, "TeraFastDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "TeraFastDialog.DoMapping.UnableToFindSourceFields.Message"), e);
        return;
    }
    // refresh fields
    this.meta.getTargetTable().setValue(this.wTable.getText());
    try {
        targetFields = this.meta.getRequiredFields(this.transMeta);
    } catch (KettleException e) {
        new ErrorDialog(this.shell, BaseMessages.getString(PKG, "TeraFastDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "TeraFastDialog.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 = this.wReturn.nrNonEmpty();
    for (int i = 0; i < nrFields; i++) {
        TableItem item = this.wReturn.getNonEmpty(i);
        String source = item.getText(2);
        String target = item.getText(1);
        int sourceIndex = sourceFields.indexOfValue(source);
        if (sourceIndex < 0) {
            missingSourceFields.append(Const.CR + "   " + source + " --> " + target);
        }
        int targetIndex = targetFields.indexOfValue(target);
        if (targetIndex < 0) {
            missingTargetFields.append(Const.CR + "   " + source + " --> " + target);
        }
        if (sourceIndex < 0 || targetIndex < 0) {
            continue;
        }
        SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
        mappings.add(mapping);
    }
    EnterMappingDialog d = new EnterMappingDialog(TeraFastDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
    mappings = d.open();
    // 
    if (mappings != null) {
        // Clear and re-populate!
        // 
        this.wReturn.table.removeAll();
        this.wReturn.table.setItemCount(mappings.size());
        for (int i = 0; i < mappings.size(); i++) {
            SourceToTargetMapping mapping = mappings.get(i);
            TableItem item = this.wReturn.table.getItem(i);
            item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
            item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
        }
        this.wReturn.setRowNums();
        this.wReturn.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) 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)

Example 42 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class TeraFastDialog method open.

/**
 * {@inheritDoc}
 *
 * @see org.pentaho.di.trans.step.StepDialogInterface#open()
 */
public String open() {
    this.changed = this.meta.hasChanged();
    final Shell parent = getParent();
    final Display display = parent.getDisplay();
    this.shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
    this.props.setLook(this.shell);
    setShellImage(this.shell, this.meta);
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    this.shell.setLayout(formLayout);
    this.shell.setText(BaseMessages.getString(PKG, "TeraFastDialog.Shell.Title"));
    buildUi();
    assignChangeListener();
    listeners();
    // 
    // Search the fields in the background
    // 
    final Runnable runnable = new Runnable() {

        public void run() {
            final StepMeta stepMetaSearchFields = TeraFastDialog.this.transMeta.findStep(TeraFastDialog.this.stepname);
            if (stepMetaSearchFields == null) {
                return;
            }
            try {
                final RowMetaInterface row = TeraFastDialog.this.transMeta.getPrevStepFields(stepMetaSearchFields);
                // Remember these fields...
                for (int i = 0; i < row.size(); i++) {
                    TeraFastDialog.this.inputFields.put(row.getValueMeta(i).getName(), Integer.valueOf(i));
                }
                setComboBoxes();
            } catch (KettleException e) {
                TeraFastDialog.this.logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
            }
        }
    };
    new Thread(runnable).start();
    // 
    // // Set the shell size, based upon previous time...
    setSize();
    getData();
    this.meta.setChanged(this.changed);
    disableInputs();
    this.shell.open();
    while (!this.shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return this.stepname;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) KettleException(org.pentaho.di.core.exception.KettleException) Shell(org.eclipse.swt.widgets.Shell) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Display(org.eclipse.swt.widgets.Display)

Example 43 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class TeraFastDialog method getUpdate.

/**
 * ...
 */
public void getUpdate() {
    try {
        final RowMetaInterface row = this.transMeta.getPrevStepFields(this.stepname);
        if (row != null) {
            TableItemInsertListener listener = new TableItemInsertListener() {

                public boolean tableItemInserted(final TableItem tableItem, final ValueMetaInterface value) {
                    // possible to check format of input fields
                    return true;
                }
            };
            BaseStepDialog.getFieldsFromPrevious(row, this.wReturn, 1, new int[] { 1, 2 }, new int[] {}, -1, -1, listener);
        }
    } catch (KettleException ke) {
        new ErrorDialog(this.shell, BaseMessages.getString(PKG, "TeraFastDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "TeraFastDialog.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 44 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class MonetDBBulkLoaderDialog method getUpdate.

/*
   * Runs when the "Get Fields" button is pressed on the Output Fields dialog tab.
   */
private void getUpdate() {
    try {
        RowMetaInterface r = transMeta.getPrevStepFields(stepname);
        if (r != null) {
            TableItemInsertListener listener = new TableItemInsertListener() {

                public boolean tableItemInserted(TableItem tableItem, ValueMetaInterface v) {
                    if (v.getType() == ValueMetaInterface.TYPE_DATE) {
                        // The default is : format is OK for dates, see if this sticks later on...
                        // 
                        tableItem.setText(3, "Y");
                    } else {
                        // default is OK too...
                        tableItem.setText(3, "Y");
                    }
                    return true;
                }
            };
            BaseStepDialog.getFieldsFromPrevious(r, wReturn, 1, new int[] { 1, 2 }, new int[] {}, -1, -1, listener);
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "MonetDBBulkLoaderDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "MonetDBBulkLoaderDialog.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 45 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class MySQLBulkLoaderDialog 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();
        }
    };
    FocusListener lsFocusLost = new FocusAdapter() {

        public void focusLost(FocusEvent arg0) {
            setTableFieldCombo();
        }
    };
    changed = input.hasChanged();
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.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);
    // Connection line
    wConnection = addConnectionLine(shell, wStepname, middle, margin);
    if (input.getDatabaseMeta() == null && transMeta.nrDatabases() == 1) {
        wConnection.select(0);
    }
    wConnection.addModifyListener(lsMod);
    // Schema line...
    wlSchema = new Label(shell, SWT.RIGHT);
    wlSchema.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.TargetSchema.Label"));
    props.setLook(wlSchema);
    fdlSchema = new FormData();
    fdlSchema.left = new FormAttachment(0, 0);
    fdlSchema.right = new FormAttachment(middle, -margin);
    fdlSchema.top = new FormAttachment(wConnection, margin * 2);
    wlSchema.setLayoutData(fdlSchema);
    wSchema = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wSchema);
    wSchema.addModifyListener(lsMod);
    wSchema.addFocusListener(lsFocusLost);
    fdSchema = new FormData();
    fdSchema.left = new FormAttachment(middle, 0);
    fdSchema.top = new FormAttachment(wConnection, margin * 2);
    fdSchema.right = new FormAttachment(100, 0);
    wSchema.setLayoutData(fdSchema);
    // Table line...
    wlTable = new Label(shell, SWT.RIGHT);
    wlTable.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.TargetTable.Label"));
    props.setLook(wlTable);
    fdlTable = new FormData();
    fdlTable.left = new FormAttachment(0, 0);
    fdlTable.right = new FormAttachment(middle, -margin);
    fdlTable.top = new FormAttachment(wSchema, margin);
    wlTable.setLayoutData(fdlTable);
    wbTable = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbTable);
    wbTable.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Browse.Button"));
    fdbTable = new FormData();
    fdbTable.right = new FormAttachment(100, 0);
    fdbTable.top = new FormAttachment(wSchema, margin);
    wbTable.setLayoutData(fdbTable);
    wTable = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wTable);
    wTable.addModifyListener(lsMod);
    wTable.addFocusListener(lsFocusLost);
    fdTable = new FormData();
    fdTable.left = new FormAttachment(middle, 0);
    fdTable.top = new FormAttachment(wSchema, margin);
    fdTable.right = new FormAttachment(wbTable, -margin);
    wTable.setLayoutData(fdTable);
    // FifoFile line...
    wlFifoFile = new Label(shell, SWT.RIGHT);
    wlFifoFile.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.FifoFile.Label"));
    props.setLook(wlFifoFile);
    fdlFifoFile = new FormData();
    fdlFifoFile.left = new FormAttachment(0, 0);
    fdlFifoFile.right = new FormAttachment(middle, -margin);
    fdlFifoFile.top = new FormAttachment(wTable, margin);
    wlFifoFile.setLayoutData(fdlFifoFile);
    wFifoFile = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFifoFile);
    wFifoFile.addModifyListener(lsMod);
    fdFifoFile = new FormData();
    fdFifoFile.left = new FormAttachment(middle, 0);
    fdFifoFile.top = new FormAttachment(wTable, margin);
    fdFifoFile.right = new FormAttachment(100, 0);
    wFifoFile.setLayoutData(fdFifoFile);
    // Delimiter line...
    wlDelimiter = new Label(shell, SWT.RIGHT);
    wlDelimiter.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Delimiter.Label"));
    props.setLook(wlDelimiter);
    fdlDelimiter = new FormData();
    fdlDelimiter.left = new FormAttachment(0, 0);
    fdlDelimiter.right = new FormAttachment(middle, -margin);
    fdlDelimiter.top = new FormAttachment(wFifoFile, margin);
    wlDelimiter.setLayoutData(fdlDelimiter);
    wbDelimiter = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbDelimiter);
    wbDelimiter.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Delimiter.Button"));
    FormData fdbDelimiter = new FormData();
    fdbDelimiter.top = new FormAttachment(wFifoFile, margin);
    fdbDelimiter.right = new FormAttachment(100, 0);
    wbDelimiter.setLayoutData(fdbDelimiter);
    wDelimiter = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDelimiter);
    wDelimiter.addModifyListener(lsMod);
    fdDelimiter = new FormData();
    fdDelimiter.left = new FormAttachment(middle, 0);
    fdDelimiter.top = new FormAttachment(wFifoFile, margin);
    fdDelimiter.right = new FormAttachment(wbDelimiter, -margin);
    wDelimiter.setLayoutData(fdDelimiter);
    // Allow the insertion of tabs as separator...
    wbDelimiter.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent se) {
            Text t = wDelimiter.getTextWidget();
            if (t != null) {
                t.insert("\t");
            }
        }
    });
    // Enclosure line...
    wlEnclosure = new Label(shell, SWT.RIGHT);
    wlEnclosure.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Enclosure.Label"));
    props.setLook(wlEnclosure);
    fdlEnclosure = new FormData();
    fdlEnclosure.left = new FormAttachment(0, 0);
    fdlEnclosure.right = new FormAttachment(middle, -margin);
    fdlEnclosure.top = new FormAttachment(wDelimiter, margin);
    wlEnclosure.setLayoutData(fdlEnclosure);
    wEnclosure = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wEnclosure);
    wEnclosure.addModifyListener(lsMod);
    fdEnclosure = new FormData();
    fdEnclosure.left = new FormAttachment(middle, 0);
    fdEnclosure.top = new FormAttachment(wDelimiter, margin);
    fdEnclosure.right = new FormAttachment(100, 0);
    wEnclosure.setLayoutData(fdEnclosure);
    // EscapeChar line...
    wlEscapeChar = new Label(shell, SWT.RIGHT);
    wlEscapeChar.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.EscapeChar.Label"));
    props.setLook(wlEscapeChar);
    fdlEscapeChar = new FormData();
    fdlEscapeChar.left = new FormAttachment(0, 0);
    fdlEscapeChar.right = new FormAttachment(middle, -margin);
    fdlEscapeChar.top = new FormAttachment(wEnclosure, margin);
    wlEscapeChar.setLayoutData(fdlEscapeChar);
    wEscapeChar = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wEscapeChar);
    wEscapeChar.addModifyListener(lsMod);
    fdEscapeChar = new FormData();
    fdEscapeChar.left = new FormAttachment(middle, 0);
    fdEscapeChar.top = new FormAttachment(wEnclosure, margin);
    fdEscapeChar.right = new FormAttachment(100, 0);
    wEscapeChar.setLayoutData(fdEscapeChar);
    // CharSet line...
    wlCharSet = new Label(shell, SWT.RIGHT);
    wlCharSet.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.CharSet.Label"));
    props.setLook(wlCharSet);
    fdlCharSet = new FormData();
    fdlCharSet.left = new FormAttachment(0, 0);
    fdlCharSet.right = new FormAttachment(middle, -margin);
    fdlCharSet.top = new FormAttachment(wEscapeChar, margin);
    wlCharSet.setLayoutData(fdlCharSet);
    wCharSet = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wCharSet);
    wCharSet.addModifyListener(lsMod);
    fdCharSet = new FormData();
    fdCharSet.left = new FormAttachment(middle, 0);
    fdCharSet.top = new FormAttachment(wEscapeChar, margin);
    fdCharSet.right = new FormAttachment(100, 0);
    wCharSet.setLayoutData(fdCharSet);
    // BulkSize line...
    wlBulkSize = new Label(shell, SWT.RIGHT);
    wlBulkSize.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.BulkSize.Label"));
    props.setLook(wlBulkSize);
    fdlBulkSize = new FormData();
    fdlBulkSize.left = new FormAttachment(0, 0);
    fdlBulkSize.right = new FormAttachment(middle, -margin);
    fdlBulkSize.top = new FormAttachment(wCharSet, margin);
    wlBulkSize.setLayoutData(fdlBulkSize);
    wBulkSize = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wBulkSize);
    wBulkSize.addModifyListener(lsMod);
    fdBulkSize = new FormData();
    fdBulkSize.left = new FormAttachment(middle, 0);
    fdBulkSize.top = new FormAttachment(wCharSet, margin);
    fdBulkSize.right = new FormAttachment(100, 0);
    wBulkSize.setLayoutData(fdBulkSize);
    // Replace line...
    wlReplace = new Label(shell, SWT.RIGHT);
    wlReplace.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Replace.Label"));
    props.setLook(wlReplace);
    fdlReplace = new FormData();
    fdlReplace.left = new FormAttachment(0, 0);
    fdlReplace.right = new FormAttachment(middle, -margin);
    fdlReplace.top = new FormAttachment(wBulkSize, margin * 2);
    wlReplace.setLayoutData(fdlReplace);
    wReplace = new Button(shell, SWT.CHECK | SWT.LEFT);
    props.setLook(wReplace);
    fdReplace = new FormData();
    fdReplace.left = new FormAttachment(middle, 0);
    fdReplace.top = new FormAttachment(wBulkSize, margin * 2);
    fdReplace.right = new FormAttachment(100, 0);
    wReplace.setLayoutData(fdReplace);
    wReplace.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            if (wReplace.getSelection()) {
                wIgnore.setSelection(false);
            }
            input.setChanged();
        }
    });
    // Ignore line...
    wlIgnore = new Label(shell, SWT.RIGHT);
    wlIgnore.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Ignore.Label"));
    props.setLook(wlIgnore);
    fdlIgnore = new FormData();
    fdlIgnore.left = new FormAttachment(0, 0);
    fdlIgnore.right = new FormAttachment(middle, -margin);
    fdlIgnore.top = new FormAttachment(wReplace, margin * 2);
    wlIgnore.setLayoutData(fdlIgnore);
    wIgnore = new Button(shell, SWT.CHECK | SWT.LEFT);
    props.setLook(wIgnore);
    fdIgnore = new FormData();
    fdIgnore.left = new FormAttachment(middle, 0);
    fdIgnore.top = new FormAttachment(wReplace, margin * 2);
    fdIgnore.right = new FormAttachment(100, 0);
    wIgnore.setLayoutData(fdIgnore);
    wIgnore.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            if (wIgnore.getSelection()) {
                wReplace.setSelection(false);
            }
            input.setChanged();
        }
    });
    // Local line...
    wlLocal = new Label(shell, SWT.RIGHT);
    wlLocal.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Local.Label"));
    props.setLook(wlLocal);
    fdlLocal = new FormData();
    fdlLocal.left = new FormAttachment(0, 0);
    fdlLocal.right = new FormAttachment(middle, -margin);
    fdlLocal.top = new FormAttachment(wIgnore, margin * 2);
    wlLocal.setLayoutData(fdlLocal);
    wLocal = new Button(shell, SWT.CHECK | SWT.LEFT);
    props.setLook(wLocal);
    fdLocal = new FormData();
    fdLocal.left = new FormAttachment(middle, 0);
    fdLocal.top = new FormAttachment(wIgnore, margin * 2);
    fdLocal.right = new FormAttachment(100, 0);
    wLocal.setLayoutData(fdLocal);
    wLocal.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            input.setChanged();
        }
    });
    // THE BUTTONS
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wSQL = new Button(shell, SWT.PUSH);
    wSQL.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.SQL.Button"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel, wSQL }, margin, null);
    // The field Table
    wlReturn = new Label(shell, SWT.NONE);
    wlReturn.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Fields.Label"));
    props.setLook(wlReturn);
    fdlReturn = new FormData();
    fdlReturn.left = new FormAttachment(0, 0);
    fdlReturn.top = new FormAttachment(wLocal, margin);
    wlReturn.setLayoutData(fdlReturn);
    int UpInsCols = 3;
    int UpInsRows = (input.getFieldTable() != null ? input.getFieldTable().length : 1);
    ciReturn = new ColumnInfo[UpInsCols];
    ciReturn[0] = new ColumnInfo(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.ColumnInfo.TableField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    ciReturn[1] = new ColumnInfo(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.ColumnInfo.StreamField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    ciReturn[2] = new ColumnInfo(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.ColumnInfo.FormatOK"), ColumnInfo.COLUMN_TYPE_CCOMBO, MySQLBulkLoaderMeta.getFieldFormatTypeDescriptions(), true);
    tableFieldColumns.add(ciReturn[0]);
    wReturn = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, ciReturn, UpInsRows, lsMod, props);
    wGetLU = new Button(shell, SWT.PUSH);
    wGetLU.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.GetFields.Label"));
    fdGetLU = new FormData();
    fdGetLU.top = new FormAttachment(wlReturn, margin);
    fdGetLU.right = new FormAttachment(100, 0);
    wGetLU.setLayoutData(fdGetLU);
    wDoMapping = new Button(shell, SWT.PUSH);
    wDoMapping.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.EditMapping.Label"));
    fdDoMapping = new FormData();
    fdDoMapping.top = new FormAttachment(wGetLU, margin);
    fdDoMapping.right = new FormAttachment(100, 0);
    wDoMapping.setLayoutData(fdDoMapping);
    wDoMapping.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event arg0) {
            generateMappings();
        }
    });
    fdReturn = new FormData();
    fdReturn.left = new FormAttachment(0, 0);
    fdReturn.top = new FormAttachment(wlReturn, margin);
    fdReturn.right = new FormAttachment(wDoMapping, -margin);
    fdReturn.bottom = new FormAttachment(wOK, -2 * margin);
    wReturn.setLayoutData(fdReturn);
    // 
    // 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(), i);
                    }
                    setComboBoxes();
                } catch (KettleException e) {
                    logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
                }
            }
        }
    };
    new Thread(runnable).start();
    // Add listeners
    lsOK = new Listener() {

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

        public void handleEvent(Event e) {
            getUpdate();
        }
    };
    lsSQL = new Listener() {

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

        public void handleEvent(Event e) {
            cancel();
        }
    };
    wOK.addListener(SWT.Selection, lsOK);
    wGetLU.addListener(SWT.Selection, lsGetLU);
    wSQL.addListener(SWT.Selection, lsSQL);
    wCancel.addListener(SWT.Selection, lsCancel);
    lsDef = new SelectionAdapter() {

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

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    wbTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            getTableName();
        }
    });
    // Set the shell size, based upon previous time...
    setSize();
    getData();
    setTableFieldCombo();
    input.setChanged(changed);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) KettleException(org.pentaho.di.core.exception.KettleException) TableItemInsertListener(org.pentaho.di.ui.trans.step.TableItemInsertListener) FocusListener(org.eclipse.swt.events.FocusListener) 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) FocusEvent(org.eclipse.swt.events.FocusEvent) 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) 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) FocusEvent(org.eclipse.swt.events.FocusEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusListener(org.eclipse.swt.events.FocusListener) Display(org.eclipse.swt.widgets.Display)

Aggregations

KettleException (org.pentaho.di.core.exception.KettleException)1977 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)449 KettleStepException (org.pentaho.di.core.exception.KettleStepException)438 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)317 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)316 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)233 IOException (java.io.IOException)208 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)195 FileObject (org.apache.commons.vfs2.FileObject)150 StepMeta (org.pentaho.di.trans.step.StepMeta)150 ArrayList (java.util.ArrayList)149 KettleFileException (org.pentaho.di.core.exception.KettleFileException)124 TransMeta (org.pentaho.di.trans.TransMeta)119 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)113 Test (org.junit.Test)111 KettleValueException (org.pentaho.di.core.exception.KettleValueException)100 Database (org.pentaho.di.core.database.Database)97 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)95 ObjectId (org.pentaho.di.repository.ObjectId)91 Shell (org.eclipse.swt.widgets.Shell)90