Search in sources :

Example 21 with StepMeta

use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.

the class NormaliserDialog 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();
        }
    };
    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, "NormaliserDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "NormaliserDialog.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);
    // Typefield line
    wlTypefield = new Label(shell, SWT.RIGHT);
    wlTypefield.setText(BaseMessages.getString(PKG, "NormaliserDialog.TypeField.Label"));
    props.setLook(wlTypefield);
    fdlTypefield = new FormData();
    fdlTypefield.left = new FormAttachment(0, 0);
    fdlTypefield.right = new FormAttachment(middle, -margin);
    fdlTypefield.top = new FormAttachment(wStepname, margin);
    wlTypefield.setLayoutData(fdlTypefield);
    wTypefield = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wTypefield.setText("");
    props.setLook(wTypefield);
    wTypefield.addModifyListener(lsMod);
    fdTypefield = new FormData();
    fdTypefield.left = new FormAttachment(middle, 0);
    fdTypefield.top = new FormAttachment(wStepname, margin);
    fdTypefield.right = new FormAttachment(100, 0);
    wTypefield.setLayoutData(fdTypefield);
    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "NormaliserDialog.Fields.Label"));
    props.setLook(wlFields);
    fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wTypefield, margin);
    wlFields.setLayoutData(fdlFields);
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "NormaliserDialog.GetFields.Button"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel, wGet }, margin, null);
    final int fieldsCols = 3;
    final int fieldsRows = input.getNormaliserFields().length;
    colinf = new ColumnInfo[fieldsCols];
    colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "NormaliserDialog.ColumnInfo.Fieldname"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    colinf[1] = new ColumnInfo(BaseMessages.getString(PKG, "NormaliserDialog.ColumnInfo.Type"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[2] = new ColumnInfo(BaseMessages.getString(PKG, "NormaliserDialog.ColumnInfo.NewField"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    wFields = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, fieldsRows, lsMod, props);
    fdFields = new FormData();
    fdFields.left = new FormAttachment(0, 0);
    fdFields.top = new FormAttachment(wlFields, margin);
    fdFields.right = new FormAttachment(100, 0);
    fdFields.bottom = new FormAttachment(wOK, -2 * margin);
    wFields.setLayoutData(fdFields);
    // 
    // 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();
    // Add listeners
    lsOK = new Listener() {

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

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

        public void handleEvent(Event e) {
            cancel();
        }
    };
    wOK.addListener(SWT.Selection, lsOK);
    wGet.addListener(SWT.Selection, lsGet);
    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();
    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) 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) 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 22 with StepMeta

use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.

the class NullIfDialog 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();
        }
    };
    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, "NullIfDialog.Shell.Label"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "NullIfDialog.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);
    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "NullIfDialog.Fields.Label"));
    props.setLook(wlFields);
    fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wStepname, margin);
    wlFields.setLayoutData(fdlFields);
    final int FieldsCols = 2;
    final int fieldsRows = input.getFields().length;
    colinf = new ColumnInfo[FieldsCols];
    colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "NullIfDialog.ColumnInfo.Name"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    colinf[1] = new ColumnInfo(BaseMessages.getString(PKG, "NullIfDialog.ColumnInfo.ValueToNull"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    wFields = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, fieldsRows, lsMod, props);
    fdFields = new FormData();
    fdFields.left = new FormAttachment(0, 0);
    fdFields.top = new FormAttachment(wlFields, margin);
    fdFields.right = new FormAttachment(100, 0);
    fdFields.bottom = new FormAttachment(100, -50);
    wFields.setLayoutData(fdFields);
    // 
    // 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();
    // Some buttons
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "System.Button.GetFields"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel, wGet }, margin, wFields);
    // Add listeners
    lsCancel = new Listener() {

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

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

        public void handleEvent(Event e) {
            ok();
        }
    };
    wCancel.addListener(SWT.Selection, lsCancel);
    wGet.addListener(SWT.Selection, lsGet);
    wOK.addListener(SWT.Selection, lsOK);
    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(changed);
    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) 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) 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 23 with StepMeta

use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.

the class PGBulkLoaderDialog 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, "PGBulkLoaderDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "PGBulkLoaderDialog.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, "PGBulkLoaderDialog.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, "PGBulkLoaderDialog.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, "PGBulkLoaderDialog.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);
    // Load Action line
    wlLoadAction = new Label(shell, SWT.RIGHT);
    wlLoadAction.setText(BaseMessages.getString(PKG, "PGBulkLoaderDialog.LoadAction.Label"));
    props.setLook(wlLoadAction);
    fdlLoadAction = new FormData();
    fdlLoadAction.left = new FormAttachment(0, 0);
    fdlLoadAction.right = new FormAttachment(middle, -margin);
    fdlLoadAction.top = new FormAttachment(wTable, margin);
    wlLoadAction.setLayoutData(fdlLoadAction);
    wLoadAction = new CCombo(shell, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
    wLoadAction.add(BaseMessages.getString(PKG, "PGBulkLoaderDialog.InsertLoadAction.Label"));
    wLoadAction.add(BaseMessages.getString(PKG, "PGBulkLoaderDialog.TruncateLoadAction.Label"));
    // +1: starts at -1
    wLoadAction.select(0);
    wLoadAction.addModifyListener(lsMod);
    props.setLook(wLoadAction);
    fdLoadAction = new FormData();
    fdLoadAction.left = new FormAttachment(middle, 0);
    fdLoadAction.top = new FormAttachment(wTable, margin);
    fdLoadAction.right = new FormAttachment(100, 0);
    wLoadAction.setLayoutData(fdLoadAction);
    fdLoadAction = new FormData();
    fdLoadAction.left = new FormAttachment(middle, 0);
    fdLoadAction.top = new FormAttachment(wTable, margin);
    fdLoadAction.right = new FormAttachment(100, 0);
    wLoadAction.setLayoutData(fdLoadAction);
    // Db Name Override line
    wlDbNameOverride = new Label(shell, SWT.RIGHT);
    wlDbNameOverride.setText(BaseMessages.getString(PKG, "PGBulkLoaderDialog.DbNameOverride.Label"));
    props.setLook(wlDbNameOverride);
    fdlDbNameOverride = new FormData();
    fdlDbNameOverride.left = new FormAttachment(0, 0);
    fdlDbNameOverride.top = new FormAttachment(wLoadAction, margin);
    fdlDbNameOverride.right = new FormAttachment(middle, -margin);
    wlDbNameOverride.setLayoutData(fdlDbNameOverride);
    wDbNameOverride = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDbNameOverride);
    wDbNameOverride.addModifyListener(lsMod);
    fdDbNameOverride = new FormData();
    fdDbNameOverride.left = new FormAttachment(middle, 0);
    fdDbNameOverride.top = new FormAttachment(wLoadAction, margin);
    fdDbNameOverride.right = new FormAttachment(100, 0);
    wDbNameOverride.setLayoutData(fdDbNameOverride);
    // Enclosure line
    wlEnclosure = new Label(shell, SWT.RIGHT);
    wlEnclosure.setText(BaseMessages.getString(PKG, "PGBulkLoaderDialog.Enclosure.Label"));
    props.setLook(wlEnclosure);
    fdlEnclosure = new FormData();
    fdlEnclosure.left = new FormAttachment(0, 0);
    fdlEnclosure.top = new FormAttachment(wDbNameOverride, margin);
    fdlEnclosure.right = new FormAttachment(middle, -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(wDbNameOverride, margin);
    fdEnclosure.right = new FormAttachment(100, 0);
    wEnclosure.setLayoutData(fdEnclosure);
    // Delimiter
    wlDelimiter = new Label(shell, SWT.RIGHT);
    wlDelimiter.setText(BaseMessages.getString(PKG, "PGBulkLoaderDialog.Delimiter.Label"));
    props.setLook(wlDelimiter);
    fdlDelimiter = new FormData();
    fdlDelimiter.left = new FormAttachment(0, 0);
    fdlDelimiter.top = new FormAttachment(wEnclosure, margin);
    fdlDelimiter.right = new FormAttachment(middle, -margin);
    wlDelimiter.setLayoutData(fdlDelimiter);
    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(wEnclosure, margin);
    fdDelimiter.right = new FormAttachment(100, 0);
    wDelimiter.setLayoutData(fdDelimiter);
    // Stop on Error line
    wlStopOnError = new Label(shell, SWT.RIGHT);
    wlStopOnError.setText(BaseMessages.getString(PKG, "PGBulkLoaderDialog.StopOnError.Label"));
    props.setLook(wlStopOnError);
    fdlStopOnError = new FormData();
    fdlStopOnError.left = new FormAttachment(0, 0);
    fdlStopOnError.top = new FormAttachment(wDelimiter, margin);
    fdlStopOnError.right = new FormAttachment(middle, -margin);
    wlStopOnError.setLayoutData(fdlStopOnError);
    wStopOnError = new Button(shell, SWT.CHECK);
    props.setLook(wStopOnError);
    fdStopOnError = new FormData();
    fdStopOnError.left = new FormAttachment(middle, 0);
    fdStopOnError.top = new FormAttachment(wDelimiter, margin);
    fdStopOnError.right = new FormAttachment(100, 0);
    wStopOnError.setLayoutData(fdStopOnError);
    wStopOnError.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            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, "PGBulkLoaderDialog.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, "PGBulkLoaderDialog.Fields.Label"));
    props.setLook(wlReturn);
    fdlReturn = new FormData();
    fdlReturn.left = new FormAttachment(0, 0);
    fdlReturn.top = new FormAttachment(wStopOnError, 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, "PGBulkLoaderDialog.ColumnInfo.TableField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    ciReturn[1] = new ColumnInfo(BaseMessages.getString(PKG, "PGBulkLoaderDialog.ColumnInfo.StreamField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    ciReturn[2] = new ColumnInfo(BaseMessages.getString(PKG, "PGBulkLoaderDialog.ColumnInfo.DateMask"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "", BaseMessages.getString(PKG, "PGBulkLoaderDialog.PassThrough.Label"), BaseMessages.getString(PKG, "PGBulkLoaderDialog.DateMask.Label"), BaseMessages.getString(PKG, "PGBulkLoaderDialog.DateTimeMask.Label") }, 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, "PGBulkLoaderDialog.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, "PGBulkLoaderDialog.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);
    // fix margin error
    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);
    wTable.addSelectionListener(lsDef);
    wDbNameOverride.addSelectionListener(lsDef);
    wEnclosure.addSelectionListener(lsDef);
    wDelimiter.addSelectionListener(lsDef);
    wStopOnError.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) CCombo(org.eclipse.swt.custom.CCombo) 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)

Example 24 with StepMeta

use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.

the class PGBulkLoaderDialog method create.

// Generate code for create table...
// Conversions done by Database
private void create() {
    try {
        PGBulkLoaderMeta info = new PGBulkLoaderMeta();
        getInfo(info);
        // new name might not yet be linked to other steps!
        String name = stepname;
        StepMeta stepMeta = new StepMeta(BaseMessages.getString(PKG, "PGBulkLoaderDialog.StepMeta.Title"), name, info);
        RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
        SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, repository, metaStore);
        if (!sql.hasError()) {
            if (sql.hasSQL()) {
                SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
                sqledit.open();
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                mb.setMessage(BaseMessages.getString(PKG, "PGBulkLoaderDialog.NoSQLNeeds.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "PGBulkLoaderDialog.NoSQLNeeds.DialogTitle"));
                mb.open();
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(sql.getError());
            mb.setText(BaseMessages.getString(PKG, "PGBulkLoaderDialog.SQLError.DialogTitle"));
            mb.open();
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "PGBulkLoaderDialog.CouldNotBuildSQL.DialogTitle"), BaseMessages.getString(PKG, "PGBulkLoaderDialog.CouldNotBuildSQL.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) PGBulkLoaderMeta(org.pentaho.di.trans.steps.pgbulkloader.PGBulkLoaderMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) SQLStatement(org.pentaho.di.core.SQLStatement) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 25 with StepMeta

use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.

the class SortRowsDialog method open.

@Override
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() {

        @Override
        public void modifyText(ModifyEvent e) {
            input.setChanged();
        }
    };
    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, "SortRowsDialog.DialogTitle"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "System.Label.StepName"));
    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);
    // Temp directory for sorting
    wlSortDir = new Label(shell, SWT.RIGHT);
    wlSortDir.setText(BaseMessages.getString(PKG, "SortRowsDialog.SortDir.Label"));
    props.setLook(wlSortDir);
    fdlSortDir = new FormData();
    fdlSortDir.left = new FormAttachment(0, 0);
    fdlSortDir.right = new FormAttachment(middle, -margin);
    fdlSortDir.top = new FormAttachment(wStepname, margin);
    wlSortDir.setLayoutData(fdlSortDir);
    wbSortDir = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbSortDir);
    wbSortDir.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
    fdbSortDir = new FormData();
    fdbSortDir.right = new FormAttachment(100, 0);
    fdbSortDir.top = new FormAttachment(wStepname, margin);
    wbSortDir.setLayoutData(fdbSortDir);
    wSortDir = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wSortDir.setText("temp");
    props.setLook(wSortDir);
    wSortDir.addModifyListener(lsMod);
    fdSortDir = new FormData();
    fdSortDir.left = new FormAttachment(middle, 0);
    fdSortDir.top = new FormAttachment(wStepname, margin);
    fdSortDir.right = new FormAttachment(wbSortDir, -margin);
    wSortDir.setLayoutData(fdSortDir);
    wbSortDir.addSelectionListener(new SelectionAdapter() {

        @Override
        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() {

        @Override
        public void modifyText(ModifyEvent e) {
            wSortDir.setToolTipText(transMeta.environmentSubstitute(wSortDir.getText()));
        }
    });
    // Prefix of temporary file
    wlPrefix = new Label(shell, SWT.RIGHT);
    wlPrefix.setText(BaseMessages.getString(PKG, "SortRowsDialog.Prefix.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);
    wPrefix.setText("srt");
    // Maximum number of lines to keep in memory before using temporary files
    wlSortSize = new Label(shell, SWT.RIGHT);
    wlSortSize.setText(BaseMessages.getString(PKG, "SortRowsDialog.SortSize.Label"));
    props.setLook(wlSortSize);
    fdlSortSize = new FormData();
    fdlSortSize.left = new FormAttachment(0, 0);
    fdlSortSize.right = new FormAttachment(middle, -margin);
    fdlSortSize.top = new FormAttachment(wPrefix, margin * 2);
    wlSortSize.setLayoutData(fdlSortSize);
    wSortSize = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wSortSize);
    wSortSize.addModifyListener(lsMod);
    fdSortSize = new FormData();
    fdSortSize.left = new FormAttachment(middle, 0);
    fdSortSize.top = new FormAttachment(wPrefix, margin * 2);
    fdSortSize.right = new FormAttachment(100, 0);
    wSortSize.setLayoutData(fdSortSize);
    // Free Memory to keep
    wlFreeMemory = new Label(shell, SWT.RIGHT);
    wlFreeMemory.setText(BaseMessages.getString(PKG, "SortRowsDialog.FreeMemory.Label"));
    wlFreeMemory.setToolTipText(BaseMessages.getString(PKG, "SortRowsDialog.FreeMemory.ToolTip"));
    props.setLook(wlFreeMemory);
    fdlFreeMemory = new FormData();
    fdlFreeMemory.left = new FormAttachment(0, 0);
    fdlFreeMemory.right = new FormAttachment(middle, -margin);
    fdlFreeMemory.top = new FormAttachment(wSortSize, margin * 2);
    wlFreeMemory.setLayoutData(fdlFreeMemory);
    wFreeMemory = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wFreeMemory.setToolTipText(BaseMessages.getString(PKG, "SortRowsDialog.FreeMemory.ToolTip"));
    props.setLook(wFreeMemory);
    wFreeMemory.addModifyListener(lsMod);
    fdFreeMemory = new FormData();
    fdFreeMemory.left = new FormAttachment(middle, 0);
    fdFreeMemory.top = new FormAttachment(wSortSize, margin * 2);
    fdFreeMemory.right = new FormAttachment(100, 0);
    wFreeMemory.setLayoutData(fdFreeMemory);
    // Using compression for temporary files?
    wlCompress = new Label(shell, SWT.RIGHT);
    wlCompress.setText(BaseMessages.getString(PKG, "SortRowsDialog.Compress.Label"));
    props.setLook(wlCompress);
    fdlCompress = new FormData();
    fdlCompress.left = new FormAttachment(0, 0);
    fdlCompress.right = new FormAttachment(middle, -margin);
    fdlCompress.top = new FormAttachment(wFreeMemory, margin * 2);
    wlCompress.setLayoutData(fdlCompress);
    wCompress = new CheckBoxVar(transMeta, shell, SWT.CHECK, "");
    props.setLook(wCompress);
    fdCompress = new FormData();
    fdCompress.left = new FormAttachment(middle, 0);
    fdCompress.top = new FormAttachment(wFreeMemory, margin * 2);
    fdCompress.right = new FormAttachment(100, 0);
    wCompress.setLayoutData(fdCompress);
    wCompress.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            log.logDetailed("SortRowsDialog", "Selection Listener for compress: " + wCompress.getSelection());
            input.setChanged();
        }
    });
    // Using compression for temporary files?
    wlUniqueRows = new Label(shell, SWT.RIGHT);
    wlUniqueRows.setText(BaseMessages.getString(PKG, "SortRowsDialog.UniqueRows.Label"));
    props.setLook(wlUniqueRows);
    fdlUniqueRows = new FormData();
    fdlUniqueRows.left = new FormAttachment(0, 0);
    fdlUniqueRows.right = new FormAttachment(middle, -margin);
    fdlUniqueRows.top = new FormAttachment(wCompress, margin);
    wlUniqueRows.setLayoutData(fdlUniqueRows);
    wUniqueRows = new Button(shell, SWT.CHECK);
    wUniqueRows.setToolTipText(BaseMessages.getString(PKG, "SortRowsDialog.UniqueRows.Tooltip"));
    props.setLook(wUniqueRows);
    fdUniqueRows = new FormData();
    fdUniqueRows.left = new FormAttachment(middle, 0);
    fdUniqueRows.top = new FormAttachment(wCompress, margin);
    fdUniqueRows.right = new FormAttachment(100, 0);
    wUniqueRows.setLayoutData(fdUniqueRows);
    wUniqueRows.addSelectionListener(new ComponentSelectionListener(input));
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "System.Button.GetFields"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel, wGet }, margin, null);
    // Table with fields to sort and sort direction
    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "SortRowsDialog.Fields.Label"));
    props.setLook(wlFields);
    fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wUniqueRows, margin);
    wlFields.setLayoutData(fdlFields);
    final int FieldsRows = input.getFieldName().length;
    colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "SortRowsDialog.Fieldname.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false), new ColumnInfo(BaseMessages.getString(PKG, "SortRowsDialog.Ascending.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { BaseMessages.getString(PKG, "System.Combo.Yes"), BaseMessages.getString(PKG, "System.Combo.No") }), new ColumnInfo(BaseMessages.getString(PKG, "SortRowsDialog.CaseInsensitive.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { BaseMessages.getString(PKG, "System.Combo.Yes"), BaseMessages.getString(PKG, "System.Combo.No") }), new ColumnInfo(BaseMessages.getString(PKG, "SortRowsDialog.CollatorDisabled.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { BaseMessages.getString(PKG, "System.Combo.Yes"), BaseMessages.getString(PKG, "System.Combo.No") }), new ColumnInfo(BaseMessages.getString(PKG, "SortRowsDialog.CollatorStrength.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { BaseMessages.getString(PKG, "System.Combo.Primary"), BaseMessages.getString(PKG, "System.Combo.Secondary"), BaseMessages.getString(PKG, "System.Combo.Tertiary"), BaseMessages.getString(PKG, "System.Combo.Identical") }, true), new ColumnInfo(BaseMessages.getString(PKG, "SortRowsDialog.PreSortedField.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { BaseMessages.getString(PKG, "System.Combo.Yes"), BaseMessages.getString(PKG, "System.Combo.No") }) };
    wFields = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, lsMod, props);
    fdFields = new FormData();
    fdFields.left = new FormAttachment(0, 0);
    fdFields.top = new FormAttachment(wlFields, margin);
    fdFields.right = new FormAttachment(100, 0);
    fdFields.bottom = new FormAttachment(wOK, -2 * margin);
    wFields.setLayoutData(fdFields);
    // 
    // Search the fields in the background
    final Runnable runnable = new Runnable() {

        @Override
        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();
    // Add listeners
    lsOK = new Listener() {

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

        @Override
        public void handleEvent(Event e) {
            get();
        }
    };
    lsCancel = new Listener() {

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

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

        @Override
        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    lsResize = new Listener() {

        @Override
        public void handleEvent(Event event) {
            Point size = shell.getSize();
            wFields.setSize(size.x - 10, size.y - 50);
            wFields.table.setSize(size.x - 10, size.y - 50);
            wFields.redraw();
        }
    };
    shell.addListener(SWT.Resize, lsResize);
    // Set the shell size, based upon previous time...
    setSize();
    getData();
    input.setChanged(changed);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TableItemInsertListener(org.pentaho.di.ui.trans.step.TableItemInsertListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ComponentSelectionListener(org.pentaho.di.ui.trans.step.ComponentSelectionListener) 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) ComponentSelectionListener(org.pentaho.di.ui.trans.step.ComponentSelectionListener) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) CheckBoxVar(org.pentaho.di.ui.core.widget.CheckBoxVar) 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) Point(org.eclipse.swt.graphics.Point) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Point(org.eclipse.swt.graphics.Point) 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)

Aggregations

StepMeta (org.pentaho.di.trans.step.StepMeta)637 TransMeta (org.pentaho.di.trans.TransMeta)228 KettleException (org.pentaho.di.core.exception.KettleException)174 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)167 Test (org.junit.Test)162 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)147 TransHopMeta (org.pentaho.di.trans.TransHopMeta)128 Trans (org.pentaho.di.trans.Trans)119 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)113 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)107 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)106 StepInterface (org.pentaho.di.trans.step.StepInterface)92 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)79 Point (org.pentaho.di.core.gui.Point)79 FormAttachment (org.eclipse.swt.layout.FormAttachment)76 FormData (org.eclipse.swt.layout.FormData)76 FormLayout (org.eclipse.swt.layout.FormLayout)76 Label (org.eclipse.swt.widgets.Label)76 Shell (org.eclipse.swt.widgets.Shell)76 Button (org.eclipse.swt.widgets.Button)75