Search in sources :

Example 1 with ColumnInfo

use of org.pentaho.di.ui.core.widget.ColumnInfo in project pentaho-kettle by pentaho.

the class BlockUntilStepsFinishDialog method open.

public String open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
    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, "BlockUntilStepsFinishDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "BlockUntilStepsFinishDialog.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);
    // Get the previous steps...
    setStepNames();
    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, "BlockUntilStepsFinishDialog.getSteps.Label"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wGet, wCancel }, margin, null);
    // Table with fields
    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "BlockUntilStepsFinishDialog.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.getStepName().length;
    ColumnInfo[] colinf = new ColumnInfo[FieldsCols];
    colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "BlockUntilStepsFinishDialog.Fieldname.Step"), ColumnInfo.COLUMN_TYPE_CCOMBO, previousSteps, false);
    colinf[1] = new ColumnInfo(BaseMessages.getString(PKG, "BlockUntilStepsFinishDialog.Fieldname.CopyNr"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[1].setUsingVariables(true);
    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);
    // 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);
    wOK.addListener(SWT.Selection, lsOK);
    wGet.addListener(SWT.Selection, lsGet);
    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 : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) ShellEvent(org.eclipse.swt.events.ShellEvent) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) Display(org.eclipse.swt.widgets.Display) TableView(org.pentaho.di.ui.core.widget.TableView)

Example 2 with ColumnInfo

use of org.pentaho.di.ui.core.widget.ColumnInfo in project pentaho-kettle by pentaho.

the class CalculatorDialog method open.

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

        @Override
        public void modifyText(ModifyEvent e) {
            currentMeta.setChanged();
        }
    };
    changed = currentMeta.hasChanged();
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "CalculatorDialog.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);
    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "CalculatorDialog.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 FieldsRows = currentMeta.getCalculation() != null ? currentMeta.getCalculation().length : 1;
    colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.NewFieldColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.CalculationColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.FieldAColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.FieldBColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.FieldCColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.ValueTypeColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames()), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.LengthColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.PrecisionColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.RemoveColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { BaseMessages.getString(PKG, "System.Combo.No"), BaseMessages.getString(PKG, "System.Combo.Yes") }), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.ConversionMask.Column"), ColumnInfo.COLUMN_TYPE_FORMAT, 6), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.DecimalSymbol.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.GroupingSymbol.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.CurrencySymbol.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false) };
    colinf[1].setSelectionAdapter(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            EnterSelectionDialog esd = new EnterSelectionDialog(shell, CalculatorMetaFunction.calcLongDesc, BaseMessages.getString(PKG, "CalculatorDialog.SelectCalculationType.Title"), BaseMessages.getString(PKG, "CalculatorDialog.SelectCalculationType.Message"));
            String string = esd.open();
            if (string != null) {
                TableView tv = (TableView) e.widget;
                tv.setText(string, e.x, e.y);
                currentMeta.setChanged();
            }
        }
    });
    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() {

        @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, "CalculatorDialog.Log.UnableToFindInput"));
                }
            }
        }
    };
    new Thread(runnable).start();
    wFields.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent arg0) {
            // Now set the combo's
            shell.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    setComboBoxes();
                }
            });
        }
    });
    // Some buttons
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel }, margin, null);
    // Add listeners
    lsCancel = new Listener() {

        @Override
        public void handleEvent(Event e) {
            cancel();
        }
    };
    lsOK = new Listener() {

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

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

        @Override
        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    // Set the shell size, based upon previous time...
    setSize();
    getData();
    currentMeta.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) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) 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 3 with ColumnInfo

use of org.pentaho.di.ui.core.widget.ColumnInfo in project pentaho-kettle by pentaho.

the class ConstantDialog 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, "ConstantDialog.DialogTitle"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Filename 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);
    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "ConstantDialog.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 = 10;
    final int FieldsRows = input.getFieldName().length;
    ColumnInfo[] colinf = new ColumnInfo[FieldsCols];
    colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "ConstantDialog.Name.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[1] = new ColumnInfo(BaseMessages.getString(PKG, "ConstantDialog.Type.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames());
    colinf[2] = new ColumnInfo(BaseMessages.getString(PKG, "ConstantDialog.Format.Column"), ColumnInfo.COLUMN_TYPE_FORMAT, 2);
    colinf[3] = new ColumnInfo(BaseMessages.getString(PKG, "ConstantDialog.Length.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[4] = new ColumnInfo(BaseMessages.getString(PKG, "ConstantDialog.Precision.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[5] = new ColumnInfo(BaseMessages.getString(PKG, "ConstantDialog.Currency.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[6] = new ColumnInfo(BaseMessages.getString(PKG, "ConstantDialog.Decimal.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[7] = new ColumnInfo(BaseMessages.getString(PKG, "ConstantDialog.Group.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[8] = new ColumnInfo(BaseMessages.getString(PKG, "ConstantDialog.Value.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[9] = new ColumnInfo(BaseMessages.getString(PKG, "ConstantDialog.Value.SetEmptyString"), 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(100, -50);
    wFields.setLayoutData(fdFields);
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel }, margin, wFields);
    // Add listeners
    lsOK = new Listener() {

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

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

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.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 : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) ShellEvent(org.eclipse.swt.events.ShellEvent) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) Display(org.eclipse.swt.widgets.Display) TableView(org.pentaho.di.ui.core.widget.TableView)

Example 4 with ColumnInfo

use of org.pentaho.di.ui.core.widget.ColumnInfo in project pentaho-kettle by pentaho.

the class CsvInputDialog method open.

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

        public void modifyText(ModifyEvent e) {
            inputMeta.setChanged();
        }
    };
    changed = inputMeta.hasChanged();
    ModifyListener lsContent = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent arg0) {
        // asyncUpdatePreview();
        }
    };
    initializing = true;
    previewBusy = new AtomicBoolean(false);
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "CsvInputDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Step name line
    // 
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "CsvInputDialog.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);
    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);
    Control lastControl = wStepname;
    // See if the step receives input. If so, we don't ask for the filename, but
    // for the filename field.
    // 
    isReceivingInput = transMeta.findNrPrevSteps(stepMeta) > 0;
    if (isReceivingInput) {
        RowMetaInterface previousFields;
        try {
            previousFields = transMeta.getPrevStepFields(stepMeta);
        } catch (KettleStepException e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "CsvInputDialog.ErrorDialog.UnableToGetInputFields.Title"), BaseMessages.getString(PKG, "CsvInputDialog.ErrorDialog.UnableToGetInputFields.Message"), e);
            previousFields = new RowMeta();
        }
        // The filename field ...
        // 
        Label wlFilename = new Label(shell, SWT.RIGHT);
        wlFilename.setText(BaseMessages.getString(PKG, inputMeta.getDescription("FILENAME_FIELD")));
        props.setLook(wlFilename);
        FormData fdlFilename = new FormData();
        fdlFilename.top = new FormAttachment(lastControl, margin);
        fdlFilename.left = new FormAttachment(0, 0);
        fdlFilename.right = new FormAttachment(middle, -margin);
        wlFilename.setLayoutData(fdlFilename);
        wFilenameField = new CCombo(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
        wFilenameField.setItems(previousFields.getFieldNames());
        props.setLook(wFilenameField);
        wFilenameField.addModifyListener(lsMod);
        FormData fdFilename = new FormData();
        fdFilename.top = new FormAttachment(lastControl, margin);
        fdFilename.left = new FormAttachment(middle, 0);
        fdFilename.right = new FormAttachment(100, 0);
        wFilenameField.setLayoutData(fdFilename);
        lastControl = wFilenameField;
        // Checkbox to include the filename in the output...
        // 
        Label wlIncludeFilename = new Label(shell, SWT.RIGHT);
        wlIncludeFilename.setText(BaseMessages.getString(PKG, inputMeta.getDescription("INCLUDE_FILENAME")));
        props.setLook(wlIncludeFilename);
        FormData fdlIncludeFilename = new FormData();
        fdlIncludeFilename.top = new FormAttachment(lastControl, margin);
        fdlIncludeFilename.left = new FormAttachment(0, 0);
        fdlIncludeFilename.right = new FormAttachment(middle, -margin);
        wlIncludeFilename.setLayoutData(fdlIncludeFilename);
        wIncludeFilename = new Button(shell, SWT.CHECK);
        props.setLook(wIncludeFilename);
        wFilenameField.addModifyListener(lsMod);
        FormData fdIncludeFilename = new FormData();
        fdIncludeFilename.top = new FormAttachment(lastControl, margin);
        fdIncludeFilename.left = new FormAttachment(middle, 0);
        fdIncludeFilename.right = new FormAttachment(100, 0);
        wIncludeFilename.setLayoutData(fdIncludeFilename);
        lastControl = wIncludeFilename;
    } else {
        // Filename...
        // 
        // The filename browse button
        // 
        wbbFilename = new Button(shell, SWT.PUSH | SWT.CENTER);
        props.setLook(wbbFilename);
        wbbFilename.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
        wbbFilename.setToolTipText(BaseMessages.getString(PKG, "System.Tooltip.BrowseForFileOrDirAndAdd"));
        FormData fdbFilename = new FormData();
        fdbFilename.top = new FormAttachment(lastControl, margin);
        fdbFilename.right = new FormAttachment(100, 0);
        wbbFilename.setLayoutData(fdbFilename);
        // The field itself...
        // 
        Label wlFilename = new Label(shell, SWT.RIGHT);
        wlFilename.setText(BaseMessages.getString(PKG, inputMeta.getDescription("FILENAME")));
        props.setLook(wlFilename);
        FormData fdlFilename = new FormData();
        fdlFilename.top = new FormAttachment(lastControl, margin);
        fdlFilename.left = new FormAttachment(0, 0);
        fdlFilename.right = new FormAttachment(middle, -margin);
        wlFilename.setLayoutData(fdlFilename);
        wFilename = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
        props.setLook(wFilename);
        wFilename.addModifyListener(lsMod);
        FormData fdFilename = new FormData();
        fdFilename.top = new FormAttachment(lastControl, margin);
        fdFilename.left = new FormAttachment(middle, 0);
        fdFilename.right = new FormAttachment(wbbFilename, -margin);
        wFilename.setLayoutData(fdFilename);
        /*
       * wFilename.addFocusListener(new FocusAdapter() {
       *
       * @Override public void focusLost(FocusEvent arg0) { asyncUpdatePreview(); } });
       */
        lastControl = wFilename;
    }
    // delimiter
    Label wlDelimiter = new Label(shell, SWT.RIGHT);
    wlDelimiter.setText(BaseMessages.getString(PKG, inputMeta.getDescription("DELIMITER")));
    props.setLook(wlDelimiter);
    FormData fdlDelimiter = new FormData();
    fdlDelimiter.top = new FormAttachment(lastControl, margin);
    fdlDelimiter.left = new FormAttachment(0, 0);
    fdlDelimiter.right = new FormAttachment(middle, -margin);
    wlDelimiter.setLayoutData(fdlDelimiter);
    wbDelimiter = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbDelimiter);
    wbDelimiter.setText(BaseMessages.getString(PKG, "CsvInputDialog.Delimiter.Button"));
    FormData fdbDelimiter = new FormData();
    fdbDelimiter.top = new FormAttachment(lastControl, 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);
    FormData fdDelimiter = new FormData();
    fdDelimiter.top = new FormAttachment(lastControl, margin);
    fdDelimiter.left = new FormAttachment(middle, 0);
    fdDelimiter.right = new FormAttachment(wbDelimiter, -margin);
    wDelimiter.setLayoutData(fdDelimiter);
    wDelimiter.addModifyListener(lsContent);
    lastControl = wDelimiter;
    // enclosure
    Label wlEnclosure = new Label(shell, SWT.RIGHT);
    wlEnclosure.setText(BaseMessages.getString(PKG, inputMeta.getDescription("ENCLOSURE")));
    props.setLook(wlEnclosure);
    FormData fdlEnclosure = new FormData();
    fdlEnclosure.top = new FormAttachment(lastControl, margin);
    fdlEnclosure.left = new FormAttachment(0, 0);
    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);
    FormData fdEnclosure = new FormData();
    fdEnclosure.top = new FormAttachment(lastControl, margin);
    fdEnclosure.left = new FormAttachment(middle, 0);
    fdEnclosure.right = new FormAttachment(100, 0);
    wEnclosure.setLayoutData(fdEnclosure);
    wEnclosure.addModifyListener(lsContent);
    lastControl = wEnclosure;
    // bufferSize
    // 
    Label wlBufferSize = new Label(shell, SWT.RIGHT);
    wlBufferSize.setText(BaseMessages.getString(PKG, inputMeta.getDescription("BUFFERSIZE")));
    props.setLook(wlBufferSize);
    FormData fdlBufferSize = new FormData();
    fdlBufferSize.top = new FormAttachment(lastControl, margin);
    fdlBufferSize.left = new FormAttachment(0, 0);
    fdlBufferSize.right = new FormAttachment(middle, -margin);
    wlBufferSize.setLayoutData(fdlBufferSize);
    wBufferSize = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wBufferSize);
    wBufferSize.addModifyListener(lsMod);
    FormData fdBufferSize = new FormData();
    fdBufferSize.top = new FormAttachment(lastControl, margin);
    fdBufferSize.left = new FormAttachment(middle, 0);
    fdBufferSize.right = new FormAttachment(100, 0);
    wBufferSize.setLayoutData(fdBufferSize);
    lastControl = wBufferSize;
    // performingLazyConversion?
    // 
    Label wlLazyConversion = new Label(shell, SWT.RIGHT);
    wlLazyConversion.setText(BaseMessages.getString(PKG, inputMeta.getDescription("LAZY_CONVERSION")));
    props.setLook(wlLazyConversion);
    FormData fdlLazyConversion = new FormData();
    fdlLazyConversion.top = new FormAttachment(lastControl, margin);
    fdlLazyConversion.left = new FormAttachment(0, 0);
    fdlLazyConversion.right = new FormAttachment(middle, -margin);
    wlLazyConversion.setLayoutData(fdlLazyConversion);
    wLazyConversion = new Button(shell, SWT.CHECK);
    props.setLook(wLazyConversion);
    FormData fdLazyConversion = new FormData();
    fdLazyConversion.top = new FormAttachment(lastControl, margin);
    fdLazyConversion.left = new FormAttachment(middle, 0);
    fdLazyConversion.right = new FormAttachment(100, 0);
    wLazyConversion.setLayoutData(fdLazyConversion);
    lastControl = wLazyConversion;
    // header row?
    // 
    Label wlHeaderPresent = new Label(shell, SWT.RIGHT);
    wlHeaderPresent.setText(BaseMessages.getString(PKG, inputMeta.getDescription("HEADER_PRESENT")));
    props.setLook(wlHeaderPresent);
    FormData fdlHeaderPresent = new FormData();
    fdlHeaderPresent.top = new FormAttachment(lastControl, margin);
    fdlHeaderPresent.left = new FormAttachment(0, 0);
    fdlHeaderPresent.right = new FormAttachment(middle, -margin);
    wlHeaderPresent.setLayoutData(fdlHeaderPresent);
    wHeaderPresent = new Button(shell, SWT.CHECK);
    props.setLook(wHeaderPresent);
    FormData fdHeaderPresent = new FormData();
    fdHeaderPresent.top = new FormAttachment(lastControl, margin);
    fdHeaderPresent.left = new FormAttachment(middle, 0);
    fdHeaderPresent.right = new FormAttachment(100, 0);
    wHeaderPresent.setLayoutData(fdHeaderPresent);
    /*
     * wHeaderPresent.addSelectionListener(new SelectionAdapter() {
     *
     * @Override public void widgetSelected(SelectionEvent arg0) { asyncUpdatePreview(); } });
     */
    lastControl = wHeaderPresent;
    wlAddResult = new Label(shell, SWT.RIGHT);
    wlAddResult.setText(BaseMessages.getString(PKG, inputMeta.getDescription("ADD_FILENAME_RESULT")));
    props.setLook(wlAddResult);
    fdlAddResult = new FormData();
    fdlAddResult.left = new FormAttachment(0, 0);
    fdlAddResult.top = new FormAttachment(wHeaderPresent, margin);
    fdlAddResult.right = new FormAttachment(middle, -margin);
    wlAddResult.setLayoutData(fdlAddResult);
    wAddResult = new Button(shell, SWT.CHECK);
    props.setLook(wAddResult);
    wAddResult.setToolTipText(BaseMessages.getString(PKG, inputMeta.getTooltip("ADD_FILENAME_RESULT")));
    fdAddResult = new FormData();
    fdAddResult.left = new FormAttachment(middle, 0);
    fdAddResult.top = new FormAttachment(wHeaderPresent, margin);
    wAddResult.setLayoutData(fdAddResult);
    lastControl = wAddResult;
    // The field itself...
    // 
    Label wlRowNumField = new Label(shell, SWT.RIGHT);
    wlRowNumField.setText(BaseMessages.getString(PKG, inputMeta.getDescription("ROW_NUM_FIELD")));
    props.setLook(wlRowNumField);
    FormData fdlRowNumField = new FormData();
    fdlRowNumField.top = new FormAttachment(lastControl, margin);
    fdlRowNumField.left = new FormAttachment(0, 0);
    fdlRowNumField.right = new FormAttachment(middle, -margin);
    wlRowNumField.setLayoutData(fdlRowNumField);
    wRowNumField = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wRowNumField);
    wRowNumField.addModifyListener(lsMod);
    FormData fdRowNumField = new FormData();
    fdRowNumField.top = new FormAttachment(lastControl, margin);
    fdRowNumField.left = new FormAttachment(middle, 0);
    fdRowNumField.right = new FormAttachment(100, 0);
    wRowNumField.setLayoutData(fdRowNumField);
    lastControl = wRowNumField;
    // running in parallel?
    // 
    wlRunningInParallel = new Label(shell, SWT.RIGHT);
    wlRunningInParallel.setText(BaseMessages.getString(PKG, inputMeta.getDescription("PARALLEL")));
    props.setLook(wlRunningInParallel);
    FormData fdlRunningInParallel = new FormData();
    fdlRunningInParallel.top = new FormAttachment(lastControl, margin);
    fdlRunningInParallel.left = new FormAttachment(0, 0);
    fdlRunningInParallel.right = new FormAttachment(middle, -margin);
    wlRunningInParallel.setLayoutData(fdlRunningInParallel);
    wRunningInParallel = new Button(shell, SWT.CHECK);
    props.setLook(wRunningInParallel);
    FormData fdRunningInParallel = new FormData();
    fdRunningInParallel.top = new FormAttachment(lastControl, margin);
    fdRunningInParallel.left = new FormAttachment(middle, 0);
    wRunningInParallel.setLayoutData(fdRunningInParallel);
    lastControl = wRunningInParallel;
    // Is a new line possible in a field?
    // 
    Label wlNewlinePossible = new Label(shell, SWT.RIGHT);
    wlNewlinePossible.setText(BaseMessages.getString(PKG, inputMeta.getDescription("NEWLINE_POSSIBLE")));
    props.setLook(wlNewlinePossible);
    FormData fdlNewlinePossible = new FormData();
    fdlNewlinePossible.top = new FormAttachment(lastControl, margin);
    fdlNewlinePossible.left = new FormAttachment(0, 0);
    fdlNewlinePossible.right = new FormAttachment(middle, -margin);
    wlNewlinePossible.setLayoutData(fdlNewlinePossible);
    wNewlinePossible = new Button(shell, SWT.CHECK);
    props.setLook(wNewlinePossible);
    FormData fdNewlinePossible = new FormData();
    fdNewlinePossible.top = new FormAttachment(lastControl, margin);
    fdNewlinePossible.left = new FormAttachment(middle, 0);
    wNewlinePossible.setLayoutData(fdNewlinePossible);
    wNewlinePossible.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            setFlags();
        }
    });
    wNewlinePossible.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            asyncUpdatePreview();
        }
    });
    lastControl = wNewlinePossible;
    // Encoding
    Label wlEncoding = new Label(shell, SWT.RIGHT);
    wlEncoding.setText(BaseMessages.getString(PKG, inputMeta.getDescription("ENCODING")));
    props.setLook(wlEncoding);
    FormData fdlEncoding = new FormData();
    fdlEncoding.top = new FormAttachment(lastControl, margin);
    fdlEncoding.left = new FormAttachment(0, 0);
    fdlEncoding.right = new FormAttachment(middle, -margin);
    wlEncoding.setLayoutData(fdlEncoding);
    wEncoding = new ComboVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wEncoding);
    wEncoding.addModifyListener(lsMod);
    FormData fdEncoding = new FormData();
    fdEncoding.top = new FormAttachment(lastControl, margin);
    fdEncoding.left = new FormAttachment(middle, 0);
    fdEncoding.right = new FormAttachment(100, 0);
    wEncoding.setLayoutData(fdEncoding);
    wEncoding.addModifyListener(lsContent);
    lastControl = wEncoding;
    wEncoding.addFocusListener(new FocusListener() {

        public void focusLost(org.eclipse.swt.events.FocusEvent e) {
        }

        public void focusGained(org.eclipse.swt.events.FocusEvent e) {
            Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
            shell.setCursor(busy);
            setEncodings();
            shell.setCursor(null);
            busy.dispose();
        }
    });
    // Some buttons first, so that the dialog scales nicely...
    // 
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    wPreview = new Button(shell, SWT.PUSH);
    wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview"));
    wPreview.setEnabled(!isReceivingInput);
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "System.Button.GetFields"));
    wGet.setEnabled(!isReceivingInput);
    setButtonPositions(new Button[] { wOK, wGet, wPreview, wCancel }, margin, null);
    // Fields
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_NAME")), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_TYPE")), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames(), true), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_FORMAT")), ColumnInfo.COLUMN_TYPE_FORMAT, 2), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_LENGTH")), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_PRECISION")), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_CURRENCY")), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_DECIMAL")), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_GROUP")), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_TRIM_TYPE")), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaString.trimTypeDesc) };
    colinf[2].setComboValuesSelectionListener(new ComboValuesSelectionListener() {

        public String[] getComboValues(TableItem tableItem, int rowNr, int colNr) {
            String[] comboValues = new String[] {};
            int type = ValueMetaFactory.getIdForValueMeta(tableItem.getText(colNr - 1));
            switch(type) {
                case ValueMetaInterface.TYPE_DATE:
                    comboValues = Const.getDateFormats();
                    break;
                case ValueMetaInterface.TYPE_INTEGER:
                case ValueMetaInterface.TYPE_BIGNUMBER:
                case ValueMetaInterface.TYPE_NUMBER:
                    comboValues = Const.getNumberFormats();
                    break;
                default:
                    break;
            }
            return comboValues;
        }
    });
    wFields = new TableView(transMeta, shell, SWT.FULL_SELECTION | SWT.MULTI, colinf, 1, lsMod, props);
    FormData fdFields = new FormData();
    fdFields.top = new FormAttachment(lastControl, margin * 2);
    fdFields.bottom = new FormAttachment(wOK, -margin * 2);
    fdFields.left = new FormAttachment(0, 0);
    fdFields.right = new FormAttachment(100, 0);
    wFields.setLayoutData(fdFields);
    wFields.setContentListener(lsContent);
    // Add listeners
    lsCancel = new Listener() {

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

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

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

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

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);
    if (wFilename != null) {
        wFilename.addSelectionListener(lsDef);
    }
    if (wFilenameField != null) {
        wFilenameField.addSelectionListener(lsDef);
    }
    wDelimiter.addSelectionListener(lsDef);
    wEnclosure.addSelectionListener(lsDef);
    wBufferSize.addSelectionListener(lsDef);
    wRowNumField.addSelectionListener(lsDef);
    // 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");
            }
        }
    });
    if (wbbFilename != null) {
        // Listen to the browse button next to the file name
        wbbFilename.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                FileDialog dialog = new FileDialog(shell, SWT.OPEN);
                dialog.setFilterExtensions(new String[] { "*.txt;*.csv", "*.csv", "*.txt", "*" });
                if (wFilename.getText() != null) {
                    String fname = transMeta.environmentSubstitute(wFilename.getText());
                    dialog.setFileName(fname);
                }
                dialog.setFilterNames(new String[] { BaseMessages.getString(PKG, "System.FileType.CSVFiles") + ", " + BaseMessages.getString(PKG, "System.FileType.TextFiles"), BaseMessages.getString(PKG, "System.FileType.CSVFiles"), BaseMessages.getString(PKG, "System.FileType.TextFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") });
                if (dialog.open() != null) {
                    String str = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName();
                    wFilename.setText(str);
                }
            }
        });
    }
    // 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();
    inputMeta.setChanged(changed);
    initializing = false;
    // Update the preview window.
    // 
    // asyncUpdatePreview();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : ComboVar(org.pentaho.di.ui.core.widget.ComboVar) KettleStepException(org.pentaho.di.core.exception.KettleStepException) FocusListener(org.eclipse.swt.events.FocusListener) Listener(org.eclipse.swt.widgets.Listener) ComboValuesSelectionListener(org.pentaho.di.ui.core.widget.ComboValuesSelectionListener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) RowMeta(org.pentaho.di.core.row.RowMeta) TableItem(org.eclipse.swt.widgets.TableItem) 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) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Cursor(org.eclipse.swt.graphics.Cursor) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Control(org.eclipse.swt.widgets.Control) 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) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) Text(org.eclipse.swt.widgets.Text) TextVar(org.pentaho.di.ui.core.widget.TextVar) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ComboValuesSelectionListener(org.pentaho.di.ui.core.widget.ComboValuesSelectionListener) CCombo(org.eclipse.swt.custom.CCombo) 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) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display)

Example 5 with ColumnInfo

use of org.pentaho.di.ui.core.widget.ColumnInfo in project pentaho-kettle by pentaho.

the class ScriptDialog 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);
    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, "ScriptDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Filename line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "ScriptDialog.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);
    wSash = new SashForm(shell, SWT.VERTICAL);
    // Top sash form
    // 
    wTop = new Composite(wSash, SWT.NONE);
    props.setLook(wTop);
    FormLayout topLayout = new FormLayout();
    topLayout.marginWidth = Const.FORM_MARGIN;
    topLayout.marginHeight = Const.FORM_MARGIN;
    wTop.setLayout(topLayout);
    // Script line
    wlScriptFunctions = new Label(wTop, SWT.NONE);
    wlScriptFunctions.setText(BaseMessages.getString(PKG, "ScriptDialog.JavascriptFunctions.Label"));
    props.setLook(wlScriptFunctions);
    fdlScriptFunctions = new FormData();
    fdlScriptFunctions.left = new FormAttachment(0, 0);
    fdlScriptFunctions.top = new FormAttachment(0, 0);
    wlScriptFunctions.setLayoutData(fdlScriptFunctions);
    // Tree View Test
    wTree = new Tree(wTop, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    props.setLook(wTree);
    fdlTree = new FormData();
    fdlTree.left = new FormAttachment(0, 0);
    fdlTree.top = new FormAttachment(wlScriptFunctions, margin);
    fdlTree.right = new FormAttachment(20, 0);
    fdlTree.bottom = new FormAttachment(100, -margin);
    wTree.setLayoutData(fdlTree);
    // Script line
    wlScript = new Label(wTop, SWT.NONE);
    wlScript.setText(BaseMessages.getString(PKG, "ScriptDialog.Javascript.Label"));
    props.setLook(wlScript);
    fdlScript = new FormData();
    fdlScript.left = new FormAttachment(wTree, margin);
    fdlScript.top = new FormAttachment(0, 0);
    wlScript.setLayoutData(fdlScript);
    folder = new CTabFolder(wTop, SWT.BORDER | SWT.RESIZE);
    folder.setSimple(false);
    folder.setUnselectedImageVisible(true);
    folder.setUnselectedCloseVisible(true);
    fdScript = new FormData();
    fdScript.left = new FormAttachment(wTree, margin);
    fdScript.top = new FormAttachment(wlScript, margin);
    fdScript.right = new FormAttachment(100, -5);
    fdScript.bottom = new FormAttachment(100, -50);
    folder.setLayoutData(fdScript);
    wlPosition = new Label(wTop, SWT.NONE);
    wlPosition.setText(BaseMessages.getString(PKG, "ScriptDialog.Position.Label"));
    props.setLook(wlPosition);
    fdlPosition = new FormData();
    fdlPosition.left = new FormAttachment(wTree, margin);
    fdlPosition.right = new FormAttachment(30, 0);
    fdlPosition.top = new FormAttachment(folder, margin);
    wlPosition.setLayoutData(fdlPosition);
    wlHelpLabel = new Text(wTop, SWT.V_SCROLL | SWT.LEFT);
    wlHelpLabel.setEditable(false);
    wlHelpLabel.setText("Hallo");
    props.setLook(wlHelpLabel);
    fdHelpLabel = new FormData();
    fdHelpLabel.left = new FormAttachment(wlPosition, margin);
    fdHelpLabel.top = new FormAttachment(folder, margin);
    fdHelpLabel.right = new FormAttachment(100, -5);
    fdHelpLabel.bottom = new FormAttachment(100, 0);
    wlHelpLabel.setLayoutData(fdHelpLabel);
    wlHelpLabel.setVisible(false);
    fdTop = new FormData();
    fdTop.left = new FormAttachment(0, 0);
    fdTop.top = new FormAttachment(0, 0);
    fdTop.right = new FormAttachment(100, 0);
    fdTop.bottom = new FormAttachment(100, 0);
    wTop.setLayoutData(fdTop);
    wBottom = new Composite(wSash, SWT.NONE);
    props.setLook(wBottom);
    FormLayout bottomLayout = new FormLayout();
    bottomLayout.marginWidth = Const.FORM_MARGIN;
    bottomLayout.marginHeight = Const.FORM_MARGIN;
    wBottom.setLayout(bottomLayout);
    wSeparator = new Label(wBottom, SWT.SEPARATOR | SWT.HORIZONTAL);
    fdSeparator = new FormData();
    fdSeparator.left = new FormAttachment(0, 0);
    fdSeparator.right = new FormAttachment(100, 0);
    fdSeparator.top = new FormAttachment(0, -margin + 2);
    wSeparator.setLayoutData(fdSeparator);
    wlFields = new Label(wBottom, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "ScriptDialog.Fields.Label"));
    props.setLook(wlFields);
    fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wSeparator, 0);
    wlFields.setLayoutData(fdlFields);
    final int FieldsRows = input.getFieldname().length;
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Filename"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.RenameTo"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Type"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames()), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Length"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Precision"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Replace"), ColumnInfo.COLUMN_TYPE_CCOMBO, YES_NO_COMBO) };
    wFields = new TableView(transMeta, wBottom, 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, 0);
    wFields.setLayoutData(fdFields);
    fdBottom = new FormData();
    fdBottom.left = new FormAttachment(0, 0);
    fdBottom.top = new FormAttachment(0, 0);
    fdBottom.right = new FormAttachment(100, 0);
    fdBottom.bottom = new FormAttachment(100, 0);
    wBottom.setLayoutData(fdBottom);
    fdSash = new FormData();
    fdSash.left = new FormAttachment(0, 0);
    fdSash.top = new FormAttachment(wStepname, 0);
    fdSash.right = new FormAttachment(100, 0);
    fdSash.bottom = new FormAttachment(100, -50);
    wSash.setLayoutData(fdSash);
    wSash.setWeights(new int[] { 75, 25 });
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wVars = new Button(shell, SWT.PUSH);
    wVars.setText(BaseMessages.getString(PKG, "ScriptDialog.GetVariables.Button"));
    wTest = new Button(shell, SWT.PUSH);
    wTest.setText(BaseMessages.getString(PKG, "ScriptDialog.TestScript.Button"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel, wVars, wTest }, margin, null);
    // Add listeners
    lsCancel = new Listener() {

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

        public void handleEvent(Event e) {
            newTest();
        }
    };
    lsVars = new Listener() {

        public void handleEvent(Event e) {
            test(true, true);
        }
    };
    lsOK = new Listener() {

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

        public void handleEvent(Event e) {
            treeDblClick(e);
        }
    };
    // lsHelp = new Listener(){public void handleEvent(Event e){ wlHelpLabel.setVisible(true); }};
    wCancel.addListener(SWT.Selection, lsCancel);
    // wGet.addListener (SWT.Selection, lsGet );
    wTest.addListener(SWT.Selection, lsTest);
    wVars.addListener(SWT.Selection, lsVars);
    wOK.addListener(SWT.Selection, lsOK);
    wTree.addListener(SWT.MouseDoubleClick, lsTree);
    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) {
            if (!cancel()) {
                e.doit = false;
            }
        }
    });
    folder.addCTabFolder2Listener(new CTabFolder2Adapter() {

        public void close(CTabFolderEvent event) {
            CTabItem cItem = (CTabItem) event.item;
            event.doit = false;
            if (cItem != null && folder.getItemCount() > 1) {
                MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.NO | SWT.YES);
                messageBox.setText(BaseMessages.getString(PKG, "ScriptDialog.DeleteItem.Label"));
                messageBox.setMessage(BaseMessages.getString(PKG, "ScriptDialog.ConfirmDeleteItem.Label", cItem.getText()));
                switch(messageBox.open()) {
                    case SWT.YES:
                        modifyScriptTree(cItem, DELETE_ITEM);
                        event.doit = true;
                        break;
                    default:
                        break;
                }
            }
        }
    });
    cMenu = new Menu(shell, SWT.POP_UP);
    buildingFolderMenu();
    tMenu = new Menu(shell, SWT.POP_UP);
    buildingTreeMenu();
    // Adding the Default Transform Scripts Item to the Tree
    wTreeScriptsItem = new TreeItem(wTree, SWT.NULL);
    wTreeScriptsItem.setImage(guiresource.getImageBol());
    wTreeScriptsItem.setText(BaseMessages.getString(PKG, "ScriptDialog.TransformScript.Label"));
    // Set the shell size, based upon previous time...
    setSize();
    getData();
    // Adding the Rest (Functions, InputItems, etc.) to the Tree
    buildSpecialFunctionsTree();
    // Input Fields
    iteminput = new TreeItem(wTree, SWT.NULL);
    iteminput.setImage(imageInputFields);
    iteminput.setText(BaseMessages.getString(PKG, "ScriptDialog.InputFields.Label"));
    // Output Fields
    itemoutput = new TreeItem(wTree, SWT.NULL);
    itemoutput.setImage(imageOutputFields);
    itemoutput.setText(BaseMessages.getString(PKG, "ScriptDialog.OutputFields.Label"));
    // Display waiting message for input
    itemWaitFieldsIn = new TreeItem(iteminput, SWT.NULL);
    itemWaitFieldsIn.setText(BaseMessages.getString(PKG, "ScriptDialog.GettingFields.Label"));
    itemWaitFieldsIn.setForeground(guiresource.getColorDirectory());
    iteminput.setExpanded(true);
    // Display waiting message for output
    itemWaitFieldsOut = new TreeItem(itemoutput, SWT.NULL);
    itemWaitFieldsOut.setText(BaseMessages.getString(PKG, "ScriptDialog.GettingFields.Label"));
    itemWaitFieldsOut.setForeground(guiresource.getColorDirectory());
    itemoutput.setExpanded(true);
    // 
    // Search the fields in the background
    // 
    final Runnable runnable = new Runnable() {

        public void run() {
            StepMeta stepMeta = transMeta.findStep(stepname);
            if (stepMeta != null) {
                try {
                    rowPrevStepFields = transMeta.getPrevStepFields(stepMeta);
                    if (rowPrevStepFields != null) {
                        setInputOutputFields();
                    } else {
                        // Can not get fields...end of wait message
                        iteminput.removeAll();
                        itemoutput.removeAll();
                    }
                } catch (KettleException e) {
                    logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
                }
            }
        }
    };
    new Thread(runnable).start();
    // rebuildInputFieldsTree();
    // buildOutputFieldsTree();
    buildAddClassesListTree();
    addRenameTowTreeScriptItems();
    input.setChanged(changed);
    // Create the drag source on the tree
    DragSource ds = new DragSource(wTree, DND.DROP_MOVE);
    ds.setTransfer(new Transfer[] { TextTransfer.getInstance() });
    ds.addDragListener(new DragSourceAdapter() {

        public void dragStart(DragSourceEvent event) {
            TreeItem item = wTree.getSelection()[0];
            // Qualifikation where the Drag Request Comes from
            if (item != null && item.getParentItem() != null) {
                if (item.getParentItem().equals(wTreeScriptsItem)) {
                    event.doit = false;
                } else if (!item.getData().equals("Function")) {
                    String strInsert = (String) item.getData();
                    if (strInsert.equals("jsFunction")) {
                        event.doit = true;
                    } else {
                        event.doit = false;
                    }
                } else {
                    event.doit = false;
                }
            } else {
                event.doit = false;
            }
        }

        public void dragSetData(DragSourceEvent event) {
            // Set the data to be the first selected item's text
            event.data = wTree.getSelection()[0].getText();
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) CTabFolder(org.eclipse.swt.custom.CTabFolder) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeItem(org.eclipse.swt.widgets.TreeItem) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) ShellEvent(org.eclipse.swt.events.ShellEvent) CTabItem(org.eclipse.swt.custom.CTabItem) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) Menu(org.eclipse.swt.widgets.Menu) 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) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) ShellAdapter(org.eclipse.swt.events.ShellAdapter) CTabFolder2Adapter(org.eclipse.swt.custom.CTabFolder2Adapter) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) CTabFolderEvent(org.eclipse.swt.custom.CTabFolderEvent) DragSource(org.eclipse.swt.dnd.DragSource) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Point(org.eclipse.swt.graphics.Point) MessageBox(org.eclipse.swt.widgets.MessageBox) SashForm(org.eclipse.swt.custom.SashForm) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CTabFolderEvent(org.eclipse.swt.custom.CTabFolderEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Display(org.eclipse.swt.widgets.Display)

Aggregations

ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)258 FormAttachment (org.eclipse.swt.layout.FormAttachment)220 FormData (org.eclipse.swt.layout.FormData)220 TableView (org.pentaho.di.ui.core.widget.TableView)216 FormLayout (org.eclipse.swt.layout.FormLayout)200 Label (org.eclipse.swt.widgets.Label)190 Button (org.eclipse.swt.widgets.Button)183 SelectionEvent (org.eclipse.swt.events.SelectionEvent)173 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)168 ShellEvent (org.eclipse.swt.events.ShellEvent)155 Event (org.eclipse.swt.widgets.Event)155 Listener (org.eclipse.swt.widgets.Listener)154 Shell (org.eclipse.swt.widgets.Shell)154 Display (org.eclipse.swt.widgets.Display)152 Text (org.eclipse.swt.widgets.Text)152 ModifyEvent (org.eclipse.swt.events.ModifyEvent)151 ModifyListener (org.eclipse.swt.events.ModifyListener)151 ShellAdapter (org.eclipse.swt.events.ShellAdapter)150 Composite (org.eclipse.swt.widgets.Composite)105 CTabItem (org.eclipse.swt.custom.CTabItem)100