/** Copy information from the meta-data input to the dialog fields. */
  public void getData() {
    wStoreValues.setSelection(input.getStoreValues());

    for (int i = 0; i < input.getCompareFields().length; i++) {
      TableItem item = wFields.table.getItem(i);
      if (input.getCompareFields()[i] != null) item.setText(1, input.getCompareFields()[i]);
    }
    wFields.setRowNums();
    wFields.optWidth(true);

    wStepname.selectAll();
  }
  private void ok() {
    if (Const.isEmpty(wStepname.getText())) return;

    int nrfields = wFields.nrNonEmpty();
    input.allocate(nrfields);

    for (int i = 0; i < nrfields; i++) {
      TableItem item = wFields.getNonEmpty(i);
      input.getCompareFields()[i] = item.getText(1);
    }

    stepname = wStepname.getText(); // return value
    input.setStoreValues(wStoreValues.getSelection());

    dispose();
  }
  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(Messages.getString("UniqueRowsByHashSetDialog.Shell.Title")); // $NON-NLS-1$

    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;

    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(
        Messages.getString("UniqueRowsByHashSetDialog.Stepname.Label")); // $NON-NLS-1$
    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);

    wlStoreValues = new Label(shell, SWT.RIGHT);
    wlStoreValues.setText(
        Messages.getString("UniqueRowsByHashSetDialog.StoreValues.Label")); // $NON-NLS-1$
    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(shell, SWT.CHECK);
    props.setLook(wStoreValues);
    wStoreValues.setToolTipText(
        Messages.getString(
            "UniqueRowsByHashSetDialog.StoreValues.ToolTip",
            Const.CR)); // $NON-NLS-1$ //$NON-NLS-2$
    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();
          }
        });

    // Some buttons
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(Messages.getString("System.Button.OK")); // $NON-NLS-1$
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(Messages.getString("UniqueRowsByHashSetDialog.Get.Button")); // $NON-NLS-1$
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(Messages.getString("System.Button.Cancel")); // $NON-NLS-1$
    fdOK = new FormData();

    setButtonPositions(new Button[] {wOK, wCancel, wGet}, margin, null);

    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(Messages.getString("UniqueRowsByHashSetDialog.Fields.Label")); // $NON-NLS-1$
    props.setLook(wlFields);
    fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wStoreValues, margin);
    wlFields.setLayoutData(fdlFields);

    final int FieldsRows = input.getCompareFields() == null ? 0 : input.getCompareFields().length;

    colinf =
        new ColumnInfo[] {
          new ColumnInfo(
              Messages.getString("UniqueRowsByHashSetDialog.ColumnInfo.Fieldname"),
              ColumnInfo.COLUMN_TYPE_CCOMBO,
              new String[] {""},
              false), //$NON-NLS-1$
        };

    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) {
                log.logError(
                    toString(), Messages.getString("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();
    input.setChanged(changed);

    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    return stepname;
  }