Search in sources :

Example 41 with TableView

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

the class UniqueRowsDialog 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, "UniqueRowsDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.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);
    // ///////////////////////////////
    // START OF Settings GROUP //
    // ///////////////////////////////
    wSettings = new Group(shell, SWT.SHADOW_NONE);
    props.setLook(wSettings);
    wSettings.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.Settings.Label"));
    FormLayout SettingsgroupLayout = new FormLayout();
    SettingsgroupLayout.marginWidth = 10;
    SettingsgroupLayout.marginHeight = 10;
    wSettings.setLayout(SettingsgroupLayout);
    wlCount = new Label(wSettings, SWT.RIGHT);
    wlCount.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.Count.Label"));
    props.setLook(wlCount);
    fdlCount = new FormData();
    fdlCount.left = new FormAttachment(0, 0);
    fdlCount.top = new FormAttachment(wStepname, margin);
    fdlCount.right = new FormAttachment(middle, -margin);
    wlCount.setLayoutData(fdlCount);
    wCount = new Button(wSettings, SWT.CHECK);
    props.setLook(wCount);
    wCount.setToolTipText(BaseMessages.getString(PKG, "UniqueRowsDialog.Count.ToolTip", Const.CR));
    fdCount = new FormData();
    fdCount.left = new FormAttachment(middle, 0);
    fdCount.top = new FormAttachment(wStepname, margin);
    wCount.setLayoutData(fdCount);
    wCount.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
            setFlags();
        }
    });
    wlCountField = new Label(wSettings, SWT.LEFT);
    wlCountField.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.CounterField.Label"));
    props.setLook(wlCountField);
    fdlCountField = new FormData();
    fdlCountField.left = new FormAttachment(wCount, margin);
    fdlCountField.top = new FormAttachment(wStepname, margin);
    wlCountField.setLayoutData(fdlCountField);
    wCountField = new Text(wSettings, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wCountField);
    wCountField.addModifyListener(lsMod);
    fdCountField = new FormData();
    fdCountField.left = new FormAttachment(wlCountField, margin);
    fdCountField.top = new FormAttachment(wStepname, margin);
    fdCountField.right = new FormAttachment(100, 0);
    wCountField.setLayoutData(fdCountField);
    wlRejectDuplicateRow = new Label(wSettings, SWT.RIGHT);
    wlRejectDuplicateRow.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.RejectDuplicateRow.Label"));
    props.setLook(wlRejectDuplicateRow);
    fdlRejectDuplicateRow = new FormData();
    fdlRejectDuplicateRow.left = new FormAttachment(0, 0);
    fdlRejectDuplicateRow.top = new FormAttachment(wCountField, margin);
    fdlRejectDuplicateRow.right = new FormAttachment(middle, -margin);
    wlRejectDuplicateRow.setLayoutData(fdlRejectDuplicateRow);
    wRejectDuplicateRow = new Button(wSettings, SWT.CHECK);
    props.setLook(wRejectDuplicateRow);
    wRejectDuplicateRow.setToolTipText(BaseMessages.getString(PKG, "UniqueRowsDialog.RejectDuplicateRow.ToolTip", Const.CR));
    fdRejectDuplicateRow = new FormData();
    fdRejectDuplicateRow.left = new FormAttachment(middle, margin);
    fdRejectDuplicateRow.top = new FormAttachment(wCountField, margin);
    wRejectDuplicateRow.setLayoutData(fdRejectDuplicateRow);
    wRejectDuplicateRow.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
            setErrorDesc();
        }
    });
    wlErrorDesc = new Label(wSettings, SWT.LEFT);
    wlErrorDesc.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.ErrorDescription.Label"));
    props.setLook(wlErrorDesc);
    fdlErrorDesc = new FormData();
    fdlErrorDesc.left = new FormAttachment(wRejectDuplicateRow, margin);
    fdlErrorDesc.top = new FormAttachment(wCountField, margin);
    wlErrorDesc.setLayoutData(fdlErrorDesc);
    wErrorDesc = new TextVar(transMeta, wSettings, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wErrorDesc);
    wErrorDesc.addModifyListener(lsMod);
    fdErrorDesc = new FormData();
    fdErrorDesc.left = new FormAttachment(wlErrorDesc, margin);
    fdErrorDesc.top = new FormAttachment(wCountField, margin);
    fdErrorDesc.right = new FormAttachment(100, 0);
    wErrorDesc.setLayoutData(fdErrorDesc);
    fdSettings = new FormData();
    fdSettings.left = new FormAttachment(0, margin);
    fdSettings.top = new FormAttachment(wStepname, margin);
    fdSettings.right = new FormAttachment(100, -margin);
    wSettings.setLayoutData(fdSettings);
    // ///////////////////////////////////////////////////////////
    // / END OF Settings GROUP
    // ///////////////////////////////////////////////////////////
    // 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, "UniqueRowsDialog.Get.Button"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    fdOK = new FormData();
    setButtonPositions(new Button[] { wOK, wCancel, wGet }, margin, null);
    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.Fields.Label"));
    props.setLook(wlFields);
    fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wSettings, margin);
    wlFields.setLayoutData(fdlFields);
    final int FieldsRows = input.getCompareFields() == null ? 0 : input.getCompareFields().length;
    colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "UniqueRowsDialog.ColumnInfo.Fieldname"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false), new ColumnInfo(BaseMessages.getString(PKG, "UniqueRowsDialog.ColumnInfo.IgnoreCase"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "Y", "N" }, 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);
    // 
    // 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
    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);
    wCountField.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 : Group(org.eclipse.swt.widgets.Group) 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) 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)

Example 42 with TableView

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

the class StreamLookupDialog 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();
        }
    };
    SelectionListener lsSelection = new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
            setComboBoxesLookup();
        }
    };
    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, "StreamLookupDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "StreamLookupDialog.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);
    // Lookup step line...
    wlStep = new Label(shell, SWT.RIGHT);
    wlStep.setText(BaseMessages.getString(PKG, "StreamLookupDialog.LookupStep.Label"));
    props.setLook(wlStep);
    fdlStep = new FormData();
    fdlStep.left = new FormAttachment(0, 0);
    fdlStep.right = new FormAttachment(middle, -margin);
    fdlStep.top = new FormAttachment(wStepname, margin * 2);
    wlStep.setLayoutData(fdlStep);
    wStep = new CCombo(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wStep);
    List<StepMeta> previousSteps = transMeta.findPreviousSteps(stepMeta, true);
    for (StepMeta previousStep : previousSteps) {
        wStep.add(previousStep.getName());
    }
    // transMeta.getInfoStep()
    wStep.addModifyListener(lsMod);
    wStep.addSelectionListener(lsSelection);
    fdStep = new FormData();
    fdStep.left = new FormAttachment(middle, 0);
    fdStep.top = new FormAttachment(wStepname, margin * 2);
    fdStep.right = new FormAttachment(100, 0);
    wStep.setLayoutData(fdStep);
    wlKey = new Label(shell, SWT.NONE);
    wlKey.setText(BaseMessages.getString(PKG, "StreamLookupDialog.Key.Label"));
    props.setLook(wlKey);
    fdlKey = new FormData();
    fdlKey.left = new FormAttachment(0, 0);
    fdlKey.top = new FormAttachment(wStep, margin);
    wlKey.setLayoutData(fdlKey);
    int nrKeyCols = 2;
    int nrKeyRows = (input.getKeystream() != null ? input.getKeystream().length : 1);
    ciKey = new ColumnInfo[nrKeyCols];
    ciKey[0] = new ColumnInfo(BaseMessages.getString(PKG, "StreamLookupDialog.ColumnInfo.Field"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    ciKey[1] = new ColumnInfo(BaseMessages.getString(PKG, "StreamLookupDialog.ColumnInfo.LookupField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    wKey = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, ciKey, nrKeyRows, lsMod, props);
    fdKey = new FormData();
    fdKey.left = new FormAttachment(0, 0);
    fdKey.top = new FormAttachment(wlKey, margin);
    fdKey.right = new FormAttachment(100, 0);
    fdKey.bottom = new FormAttachment(wlKey, 180);
    wKey.setLayoutData(fdKey);
    // THE UPDATE/INSERT TABLE
    wlReturn = new Label(shell, SWT.NONE);
    wlReturn.setText(BaseMessages.getString(PKG, "StreamLookupDialog.ReturnFields.Label"));
    props.setLook(wlReturn);
    fdlReturn = new FormData();
    fdlReturn.left = new FormAttachment(0, 0);
    fdlReturn.top = new FormAttachment(wKey, margin);
    wlReturn.setLayoutData(fdlReturn);
    int UpInsCols = 4;
    int UpInsRows = (input.getValue() != null ? input.getValue().length : 1);
    ciReturn = new ColumnInfo[UpInsCols];
    ciReturn[0] = new ColumnInfo(BaseMessages.getString(PKG, "StreamLookupDialog.ColumnInfo.FieldReturn"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    ciReturn[1] = new ColumnInfo(BaseMessages.getString(PKG, "StreamLookupDialog.ColumnInfo.NewName"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    ciReturn[2] = new ColumnInfo(BaseMessages.getString(PKG, "StreamLookupDialog.ColumnInfo.Default"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    ciReturn[3] = new ColumnInfo(BaseMessages.getString(PKG, "StreamLookupDialog.ColumnInfo.Type"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames());
    wReturn = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, ciReturn, UpInsRows, lsMod, props);
    // START MEMORY PRESERVE GROUP
    fdReturn = new FormData();
    fdReturn.left = new FormAttachment(0, 0);
    fdReturn.top = new FormAttachment(wlReturn, margin);
    fdReturn.right = new FormAttachment(100, 0);
    fdReturn.bottom = new FormAttachment(100, -125);
    wReturn.setLayoutData(fdReturn);
    wlPreserveMemory = new Label(shell, SWT.RIGHT);
    wlPreserveMemory.setText(BaseMessages.getString(PKG, "StreamLookupDialog.PreserveMemory.Label"));
    props.setLook(wlPreserveMemory);
    fdlPreserveMemory = new FormData();
    fdlPreserveMemory.left = new FormAttachment(0, 0);
    fdlPreserveMemory.top = new FormAttachment(wReturn, margin);
    fdlPreserveMemory.right = new FormAttachment(middle, -margin);
    wlPreserveMemory.setLayoutData(fdlPreserveMemory);
    wPreserveMemory = new Button(shell, SWT.CHECK);
    props.setLook(wPreserveMemory);
    fdPreserveMemory = new FormData();
    fdPreserveMemory.left = new FormAttachment(middle, 0);
    fdPreserveMemory.top = new FormAttachment(wReturn, margin);
    fdPreserveMemory.right = new FormAttachment(100, 0);
    wPreserveMemory.setLayoutData(fdPreserveMemory);
    wPreserveMemory.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
        }
    });
    wlIntegerPair = new Label(shell, SWT.RIGHT);
    wlIntegerPair.setText(BaseMessages.getString(PKG, "StreamLookupDialog.IntegerPair.Label"));
    props.setLook(wlIntegerPair);
    fdlIntegerPair = new FormData();
    fdlIntegerPair.left = new FormAttachment(0, 0);
    fdlIntegerPair.top = new FormAttachment(wPreserveMemory, margin);
    fdlIntegerPair.right = new FormAttachment(middle, -margin);
    wlIntegerPair.setLayoutData(fdlIntegerPair);
    wIntegerPair = new Button(shell, SWT.RADIO);
    wIntegerPair.setEnabled(false);
    props.setLook(wIntegerPair);
    fdIntegerPair = new FormData();
    fdIntegerPair.left = new FormAttachment(middle, 0);
    fdIntegerPair.top = new FormAttachment(wPreserveMemory, margin);
    fdIntegerPair.right = new FormAttachment(100, 0);
    wIntegerPair.setLayoutData(fdIntegerPair);
    wIntegerPair.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
        }
    });
    wlSortedList = new Label(shell, SWT.RIGHT);
    wlSortedList.setText(BaseMessages.getString(PKG, "StreamLookupDialog.SortedList.Label"));
    props.setLook(wlSortedList);
    fdlSortedList = new FormData();
    fdlSortedList.left = new FormAttachment(0, 0);
    fdlSortedList.top = new FormAttachment(wIntegerPair, margin);
    fdlSortedList.right = new FormAttachment(middle, -margin);
    wlSortedList.setLayoutData(fdlSortedList);
    wSortedList = new Button(shell, SWT.RADIO);
    wSortedList.setEnabled(false);
    props.setLook(wSortedList);
    fdSortedList = new FormData();
    fdSortedList.left = new FormAttachment(middle, 0);
    fdSortedList.top = new FormAttachment(wIntegerPair, margin);
    fdSortedList.right = new FormAttachment(100, 0);
    wSortedList.setLayoutData(fdSortedList);
    wSortedList.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
        }
    });
    // PDI-2107 preserve memory should be enabled to have this options on.
    wPreserveMemory.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            boolean selection = wPreserveMemory.getSelection();
            wSortedList.setEnabled(selection);
            wIntegerPair.setEnabled(selection);
        }
    });
    // END MEMORY PRESERVE
    // THE 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, "StreamLookupDialog.GetFields.Button"));
    wGetLU = new Button(shell, SWT.PUSH);
    wGetLU.setText(BaseMessages.getString(PKG, "StreamLookupDialog.GetLookupFields.Button"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel, wGet, wGetLU }, margin, null);
    // Add listeners
    lsOK = new Listener() {

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

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

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

        public void handleEvent(Event e) {
            cancel();
        }
    };
    wOK.addListener(SWT.Selection, lsOK);
    wGet.addListener(SWT.Selection, lsGet);
    wGetLU.addListener(SWT.Selection, lsGetLU);
    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();
    setComboBoxes();
    setComboBoxesLookup();
    input.setChanged(changed);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionListener(org.eclipse.swt.events.SelectionListener) 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) 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) CCombo(org.eclipse.swt.custom.CCombo) 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) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 43 with TableView

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

the class StringOperationsDialog 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, "StringOperationsDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "StringOperationsDialog.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);
    wlKey = new Label(shell, SWT.NONE);
    wlKey.setText(BaseMessages.getString(PKG, "StringOperationsDialog.Fields.Label"));
    props.setLook(wlKey);
    fdlKey = new FormData();
    fdlKey.left = new FormAttachment(0, 0);
    fdlKey.top = new FormAttachment(wStepname, 2 * margin);
    wlKey.setLayoutData(fdlKey);
    int nrFieldCols = 11;
    int nrFieldRows = (input.getFieldInStream() != null ? input.getFieldInStream().length : 1);
    ciKey = new ColumnInfo[nrFieldCols];
    ciKey[0] = new ColumnInfo(BaseMessages.getString(PKG, "StringOperationsDialog.ColumnInfo.InStreamField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    ciKey[1] = new ColumnInfo(BaseMessages.getString(PKG, "StringOperationsDialog.ColumnInfo.OutStreamField"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    ciKey[2] = new ColumnInfo(BaseMessages.getString(PKG, "StringOperationsDialog.ColumnInfo.Trim"), ColumnInfo.COLUMN_TYPE_CCOMBO, StringOperationsMeta.trimTypeDesc, true);
    ciKey[3] = new ColumnInfo(BaseMessages.getString(PKG, "StringOperationsDialog.ColumnInfo.LowerUpper"), ColumnInfo.COLUMN_TYPE_CCOMBO, StringOperationsMeta.lowerUpperDesc, true);
    ciKey[4] = new ColumnInfo(BaseMessages.getString(PKG, "StringOperationsDialog.ColumnInfo.Padding"), ColumnInfo.COLUMN_TYPE_CCOMBO, StringOperationsMeta.paddingDesc, true);
    ciKey[5] = new ColumnInfo(BaseMessages.getString(PKG, "StringOperationsDialog.ColumnInfo.CharPad"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    ciKey[6] = new ColumnInfo(BaseMessages.getString(PKG, "StringOperationsDialog.ColumnInfo.LenPad"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    ciKey[7] = new ColumnInfo(BaseMessages.getString(PKG, "StringOperationsDialog.ColumnInfo.InitCap"), ColumnInfo.COLUMN_TYPE_CCOMBO, StringOperationsMeta.initCapDesc);
    ciKey[8] = new ColumnInfo(BaseMessages.getString(PKG, "StringOperationsDialog.ColumnInfo.MaskXML"), ColumnInfo.COLUMN_TYPE_CCOMBO, StringOperationsMeta.maskXMLDesc);
    ciKey[9] = new ColumnInfo(BaseMessages.getString(PKG, "StringOperationsDialog.ColumnInfo.Digits"), ColumnInfo.COLUMN_TYPE_CCOMBO, StringOperationsMeta.digitsDesc);
    ciKey[10] = new ColumnInfo(BaseMessages.getString(PKG, "StringOperationsDialog.ColumnInfo.RemoveSpecialCharacters"), ColumnInfo.COLUMN_TYPE_CCOMBO, StringOperationsMeta.removeSpecialCharactersDesc);
    ciKey[1].setToolTip(BaseMessages.getString(PKG, "StringOperationsDialog.ColumnInfo.OutStreamField.Tooltip"));
    ciKey[1].setUsingVariables(true);
    ciKey[4].setUsingVariables(true);
    ciKey[5].setUsingVariables(true);
    ciKey[6].setUsingVariables(true);
    ciKey[7].setUsingVariables(true);
    wFields = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, ciKey, nrFieldRows, lsMod, props);
    fdKey = new FormData();
    fdKey.left = new FormAttachment(0, 0);
    fdKey.top = new FormAttachment(wlKey, margin);
    fdKey.right = new FormAttachment(100, -margin);
    fdKey.bottom = new FormAttachment(100, -30);
    wFields.setLayoutData(fdKey);
    // THE 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"));
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "StringOperationsDialog.GetFields.Button"));
    fdGet = new FormData();
    fdGet.right = new FormAttachment(100, 0);
    fdGet.top = new FormAttachment(wStepname, 3 * middle);
    wGet.setLayoutData(fdGet);
    setButtonPositions(new Button[] { wOK, wGet, wCancel }, margin, null);
    // 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();
    // 
    // 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);
                    if (row != null) {
                        // Remember these fields...
                        for (int i = 0; i < row.size(); i++) {
                            inputFields.put(row.getValueMeta(i).getName(), new Integer(i));
                        }
                        setComboBoxes();
                    }
                    // Dislay in red missing field names
                    Runnable asyncExecRunnable = new Runnable() {

                        public void run() {
                            if (!wFields.isDisposed()) {
                                for (int i = 0; i < wFields.table.getItemCount(); i++) {
                                    TableItem it = wFields.table.getItem(i);
                                    if (!Utils.isEmpty(it.getText(1))) {
                                        if (!inputFields.containsKey(it.getText(1))) {
                                            it.setBackground(GUIResource.getInstance().getColorRed());
                                        }
                                    }
                                }
                            }
                        }
                    };
                    if (Const.isRunningOnWebspoonMode()) {
                        display.asyncExec(asyncExecRunnable);
                    } else {
                        Display.getDefault().asyncExec(asyncExecRunnable);
                    }
                } catch (KettleException e) {
                    logError("Error getting fields from incoming stream!", e);
                }
            }
        }
    };
    new Thread(runnable).start();
    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) ModifyListener(org.eclipse.swt.events.ModifyListener) 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) 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 44 with TableView

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

the class SecretKeyGeneratorDialog 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, "SecretKeyGeneratorDialog.DialogTitle"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // See if the step receives input.
    // 
    isReceivingInput = transMeta.findNrPrevSteps(stepMeta) > 0;
    // 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);
    // ///////////////////////////////
    // START OF OutputFields GROUP //
    // ///////////////////////////////
    wOutputFields = new Group(shell, SWT.SHADOW_NONE);
    props.setLook(wOutputFields);
    wOutputFields.setText(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.wOutputFields.Label"));
    FormLayout OutputFieldsgroupLayout = new FormLayout();
    OutputFieldsgroupLayout.marginWidth = 10;
    OutputFieldsgroupLayout.marginHeight = 10;
    wOutputFields.setLayout(OutputFieldsgroupLayout);
    // SecretKeyField fieldname ...
    wlSecretKeyField = new Label(wOutputFields, SWT.RIGHT);
    wlSecretKeyField.setText(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.SecretKeyFieldName.Label"));
    props.setLook(wlSecretKeyField);
    fdlSecretKeyField = new FormData();
    fdlSecretKeyField.left = new FormAttachment(0, 0);
    fdlSecretKeyField.right = new FormAttachment(middle, -margin);
    fdlSecretKeyField.top = new FormAttachment(wStepname, margin * 2);
    wlSecretKeyField.setLayoutData(fdlSecretKeyField);
    wSecretKeyField = new Text(wOutputFields, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wSecretKeyField.setToolTipText(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.SecretKeyFieldName.Tooltip"));
    props.setLook(wSecretKeyField);
    wSecretKeyField.addModifyListener(lsMod);
    fdSecretKeyField = new FormData();
    fdSecretKeyField.left = new FormAttachment(middle, 0);
    fdSecretKeyField.top = new FormAttachment(wStepname, margin * 2);
    fdSecretKeyField.right = new FormAttachment(100, 0);
    wSecretKeyField.setLayoutData(fdSecretKeyField);
    // AlgorithmField fieldname ...
    wlAlgorithmField = new Label(wOutputFields, SWT.RIGHT);
    wlAlgorithmField.setText(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.Algorithm.Label"));
    props.setLook(wlAlgorithmField);
    fdlAlgorithmField = new FormData();
    fdlAlgorithmField.left = new FormAttachment(0, 0);
    fdlAlgorithmField.right = new FormAttachment(middle, -margin);
    fdlAlgorithmField.top = new FormAttachment(wSecretKeyField, margin);
    wlAlgorithmField.setLayoutData(fdlAlgorithmField);
    wAlgorithmField = new Text(wOutputFields, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wAlgorithmField.setToolTipText(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.Algorithm.Tooltip"));
    props.setLook(wAlgorithmField);
    wAlgorithmField.addModifyListener(lsMod);
    fdAlgorithmField = new FormData();
    fdAlgorithmField.left = new FormAttachment(middle, 0);
    fdAlgorithmField.top = new FormAttachment(wSecretKeyField, margin);
    fdAlgorithmField.right = new FormAttachment(100, 0);
    wAlgorithmField.setLayoutData(fdAlgorithmField);
    // SecretKeyLengthField fieldname ...
    wlSecretKeyLengthField = new Label(wOutputFields, SWT.RIGHT);
    wlSecretKeyLengthField.setText(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.SecretKeyLength.Label"));
    props.setLook(wlSecretKeyLengthField);
    fdlSecretKeyLengthField = new FormData();
    fdlSecretKeyLengthField.left = new FormAttachment(0, 0);
    fdlSecretKeyLengthField.right = new FormAttachment(middle, -margin);
    fdlSecretKeyLengthField.top = new FormAttachment(wAlgorithmField, margin);
    wlSecretKeyLengthField.setLayoutData(fdlSecretKeyLengthField);
    wSecretKeyLengthField = new Text(wOutputFields, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wSecretKeyLengthField.setToolTipText(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.SecretKeyLength.Tooltip"));
    props.setLook(wSecretKeyLengthField);
    wSecretKeyLengthField.addModifyListener(lsMod);
    fdSecretKeyLengthField = new FormData();
    fdSecretKeyLengthField.left = new FormAttachment(middle, 0);
    fdSecretKeyLengthField.top = new FormAttachment(wAlgorithmField, margin);
    fdSecretKeyLengthField.right = new FormAttachment(100, 0);
    wSecretKeyLengthField.setLayoutData(fdSecretKeyLengthField);
    wlOutputKeyAsByinary = new Label(wOutputFields, SWT.RIGHT);
    wlOutputKeyAsByinary.setText(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.OutputKeyAsByinary.Label"));
    props.setLook(wlOutputKeyAsByinary);
    fdlOutputKeyAsByinary = new FormData();
    fdlOutputKeyAsByinary.left = new FormAttachment(0, 0);
    fdlOutputKeyAsByinary.top = new FormAttachment(wSecretKeyLengthField, margin);
    fdlOutputKeyAsByinary.right = new FormAttachment(middle, -margin);
    wlOutputKeyAsByinary.setLayoutData(fdlOutputKeyAsByinary);
    wOutputKeyAsByinary = new Button(wOutputFields, SWT.CHECK);
    wOutputKeyAsByinary.setToolTipText(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.OutputKeyAsByinary.Tooltip"));
    props.setLook(wOutputKeyAsByinary);
    fdOutputKeyAsByinary = new FormData();
    fdOutputKeyAsByinary.left = new FormAttachment(middle, 0);
    fdOutputKeyAsByinary.top = new FormAttachment(wSecretKeyLengthField, margin);
    fdOutputKeyAsByinary.right = new FormAttachment(100, 0);
    wOutputKeyAsByinary.setLayoutData(fdOutputKeyAsByinary);
    wOutputKeyAsByinary.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
        }
    });
    FormData fdOutputFields = new FormData();
    fdOutputFields.left = new FormAttachment(0, margin);
    fdOutputFields.top = new FormAttachment(wStepname, 2 * margin);
    fdOutputFields.right = new FormAttachment(100, -margin);
    wOutputFields.setLayoutData(fdOutputFields);
    // ///////////////////////////////////////////////////////////
    // / END OF OutputFields GROUP
    // ///////////////////////////////////////////////////////////
    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.Fields.Label"));
    props.setLook(wlFields);
    fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wOutputFields, margin);
    wlFields.setLayoutData(fdlFields);
    final int FieldsCols = 4;
    final int FieldsRows = input.getAlgorithm().length;
    ColumnInfo[] colinf = new ColumnInfo[FieldsCols];
    colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.AlgorithmColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, SymmetricCryptoMeta.TYPE_ALGORYTHM_CODE);
    colinf[0].setReadOnly(true);
    colinf[1] = new ColumnInfo(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.SchemeColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[1].setUsingVariables(true);
    colinf[2] = new ColumnInfo(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.SecretKeyLengthColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[2].setUsingVariables(true);
    colinf[3] = new ColumnInfo(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.HowMany.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[3].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(100, -50);
    wFields.setLayoutData(fdFields);
    // 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"));
    wPreview = new Button(shell, SWT.PUSH);
    wPreview.setText(BaseMessages.getString(PKG, "SecretKeyGeneratorDialog.Button.PreviewRows"));
    wPreview.setEnabled(!isReceivingInput);
    setButtonPositions(new Button[] { wOK, wPreview, wCancel }, margin, wFields);
    // Add listeners
    lsCancel = new Listener() {

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

        public void handleEvent(Event e) {
            ok();
        }
    };
    wCancel.addListener(SWT.Selection, lsCancel);
    wOK.addListener(SWT.Selection, lsOK);
    lsPreview = new Listener() {

        public void handleEvent(Event e) {
            preview();
        }
    };
    lsDef = new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wPreview.addListener(SWT.Selection, lsPreview);
    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) Group(org.eclipse.swt.widgets.Group) 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 45 with TableView

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

the class UniqueRowsByHashSetDialog 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, "UniqueRowsByHashSetDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "UniqueRowsByHashSetDialog.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);
    // ///////////////////////////////
    // START OF Settings GROUP //
    // ///////////////////////////////
    wSettings = new Group(shell, SWT.SHADOW_NONE);
    props.setLook(wSettings);
    wSettings.setText(BaseMessages.getString(PKG, "UniqueRowsByHashSetDialog.Settings.Label"));
    FormLayout SettingsgroupLayout = new FormLayout();
    SettingsgroupLayout.marginWidth = 10;
    SettingsgroupLayout.marginHeight = 10;
    wSettings.setLayout(SettingsgroupLayout);
    wlStoreValues = new Label(wSettings, SWT.RIGHT);
    wlStoreValues.setText(BaseMessages.getString(PKG, "UniqueRowsByHashSetDialog.StoreValues.Label"));
    props.setLook(wlStoreValues);
    fdlStoreValues = new FormData();
    fdlStoreValues.left = new FormAttachment(0, 0);
    fdlStoreValues.top = new FormAttachment(wStepname, margin);
    fdlStoreValues.right = new FormAttachment(middle, -margin);
    wlStoreValues.setLayoutData(fdlStoreValues);
    wStoreValues = new Button(wSettings, SWT.CHECK);
    props.setLook(wStoreValues);
    wStoreValues.setToolTipText(BaseMessages.getString(PKG, "UniqueRowsByHashSetDialog.StoreValues.ToolTip", Const.CR));
    fdStoreValues = new FormData();
    fdStoreValues.left = new FormAttachment(middle, 0);
    fdStoreValues.top = new FormAttachment(wStepname, margin);
    wStoreValues.setLayoutData(fdStoreValues);
    wStoreValues.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
        }
    });
    wlRejectDuplicateRow = new Label(wSettings, SWT.RIGHT);
    wlRejectDuplicateRow.setText(BaseMessages.getString(PKG, "UniqueRowsByHashSetDialog.RejectDuplicateRow.Label"));
    props.setLook(wlRejectDuplicateRow);
    fdlRejectDuplicateRow = new FormData();
    fdlRejectDuplicateRow.left = new FormAttachment(0, 0);
    fdlRejectDuplicateRow.top = new FormAttachment(wStoreValues, margin);
    fdlRejectDuplicateRow.right = new FormAttachment(middle, -margin);
    wlRejectDuplicateRow.setLayoutData(fdlRejectDuplicateRow);
    wRejectDuplicateRow = new Button(wSettings, SWT.CHECK);
    props.setLook(wRejectDuplicateRow);
    wRejectDuplicateRow.setToolTipText(BaseMessages.getString(PKG, "UniqueRowsByHashSetDialog.RejectDuplicateRow.ToolTip", Const.CR));
    fdRejectDuplicateRow = new FormData();
    fdRejectDuplicateRow.left = new FormAttachment(middle, 0);
    fdRejectDuplicateRow.top = new FormAttachment(wStoreValues, margin);
    wRejectDuplicateRow.setLayoutData(fdRejectDuplicateRow);
    wRejectDuplicateRow.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
            setErrorDesc();
        }
    });
    wlErrorDesc = new Label(wSettings, SWT.LEFT);
    wlErrorDesc.setText(BaseMessages.getString(PKG, "UniqueRowsByHashSetDialog.ErrorDescription.Label"));
    props.setLook(wlErrorDesc);
    fdlErrorDesc = new FormData();
    fdlErrorDesc.left = new FormAttachment(wRejectDuplicateRow, margin);
    fdlErrorDesc.top = new FormAttachment(wStoreValues, margin);
    wlErrorDesc.setLayoutData(fdlErrorDesc);
    wErrorDesc = new TextVar(transMeta, wSettings, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wErrorDesc);
    wErrorDesc.addModifyListener(lsMod);
    fdErrorDesc = new FormData();
    fdErrorDesc.left = new FormAttachment(wlErrorDesc, margin);
    fdErrorDesc.top = new FormAttachment(wStoreValues, margin);
    fdErrorDesc.right = new FormAttachment(100, 0);
    wErrorDesc.setLayoutData(fdErrorDesc);
    fdSettings = new FormData();
    fdSettings.left = new FormAttachment(0, margin);
    fdSettings.top = new FormAttachment(wStepname, margin);
    fdSettings.right = new FormAttachment(100, -margin);
    wSettings.setLayoutData(fdSettings);
    // ///////////////////////////////////////////////////////////
    // / END OF Settings GROUP
    // ///////////////////////////////////////////////////////////
    // 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, "UniqueRowsByHashSetDialog.Get.Button"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    fdOK = new FormData();
    setButtonPositions(new Button[] { wOK, wCancel, wGet }, margin, null);
    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "UniqueRowsByHashSetDialog.Fields.Label"));
    props.setLook(wlFields);
    fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wSettings, margin);
    wlFields.setLayoutData(fdlFields);
    final int FieldsRows = input.getCompareFields() == null ? 0 : input.getCompareFields().length;
    colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "UniqueRowsByHashSetDialog.ColumnInfo.Fieldname"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, 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
    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();
    setErrorDesc();
    input.setChanged(changed);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : Group(org.eclipse.swt.widgets.Group) 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) 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

TableView (org.pentaho.di.ui.core.widget.TableView)229 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)220 FormAttachment (org.eclipse.swt.layout.FormAttachment)218 FormData (org.eclipse.swt.layout.FormData)218 FormLayout (org.eclipse.swt.layout.FormLayout)200 Label (org.eclipse.swt.widgets.Label)186 Button (org.eclipse.swt.widgets.Button)185 SelectionEvent (org.eclipse.swt.events.SelectionEvent)172 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)168 Shell (org.eclipse.swt.widgets.Shell)157 ShellEvent (org.eclipse.swt.events.ShellEvent)154 Event (org.eclipse.swt.widgets.Event)153 Listener (org.eclipse.swt.widgets.Listener)152 Text (org.eclipse.swt.widgets.Text)151 Display (org.eclipse.swt.widgets.Display)150 ModifyEvent (org.eclipse.swt.events.ModifyEvent)149 ModifyListener (org.eclipse.swt.events.ModifyListener)149 ShellAdapter (org.eclipse.swt.events.ShellAdapter)149 Composite (org.eclipse.swt.widgets.Composite)105 CTabItem (org.eclipse.swt.custom.CTabItem)100