/** Copy information from the meta-data input to the dialog fields. */
  public void getData() {
    String[] inputStepNames = joinMeta.getInputSteps();
    if (inputStepNames != null) {
      String inputStepName;
      String[] keyFields = joinMeta.getKeyFields();
      String keyField;
      for (int i = 0; i < inputStepNames.length; i++) {
        inputStepName = Const.NVL(inputStepNames[i], "");
        wInputStepArray[i].setText(inputStepName);

        keyField = Const.NVL(keyFields[i], "");
        keyValTextBox[i].setText(keyField);
      }

      String joinType = joinMeta.getJoinType();
      if (joinType != null && joinType.length() > 0) {
        joinTypeCombo.setText(joinType);
      } else {
        joinTypeCombo.setText(MultiMergeJoinMeta.join_types[0]);
      }
    }
    wStepname.selectAll();
    wStepname.setFocus();
  }
  private String[] getInputStepNames() {
    String[] inputStepNames = joinMeta.getInputSteps();
    ArrayList<String> nameList = new ArrayList<String>();
    if (inputStepNames != null) {
      Collections.addAll(nameList, inputStepNames);
    }

    String[] prevStepNames = transMeta.getPrevStepNames(stepname);
    if (prevStepNames != null) {
      String prevStepName;
      for (int i = 0; i < prevStepNames.length; i++) {
        prevStepName = prevStepNames[i];
        if (nameList.contains(prevStepName)) {
          continue;
        }
        nameList.add(prevStepName);
      }
    }

    return nameList.toArray(new String[nameList.size()]);
  }
  /**
   * Get the meta data
   *
   * @param meta
   */
  private void getMeta(MultiMergeJoinMeta meta) {
    StepIOMetaInterface stepIOMeta = meta.getStepIOMeta();
    List<StreamInterface> infoStreams = stepIOMeta.getInfoStreams();
    StreamInterface stream;
    String streamDescription;
    ArrayList<String> inputStepNameList = new ArrayList<String>();
    ArrayList<String> keyList = new ArrayList<String>();
    CCombo wInputStep;
    String inputStepName;
    for (int i = 0; i < wInputStepArray.length; i++) {
      wInputStep = wInputStepArray[i];
      inputStepName = wInputStep.getText();

      if (Const.isEmpty(inputStepName)) {
        continue;
      }

      inputStepNameList.add(inputStepName);
      keyList.add(keyValTextBox[i].getText());

      if (infoStreams.size() < inputStepNameList.size()) {
        streamDescription = BaseMessages.getString(PKG, "MultiMergeJoin.InfoStream.Description");
        stream = new Stream(StreamType.INFO, null, streamDescription, StreamIcon.INFO, null);
        stepIOMeta.addStream(stream);
      }
    }

    int inputStepCount = inputStepNameList.size();
    meta.allocateInputSteps(inputStepCount);
    meta.allocateKeys(inputStepCount);

    String[] inputSteps = meta.getInputSteps();
    String[] keyFields = meta.getKeyFields();
    infoStreams = stepIOMeta.getInfoStreams();
    for (int i = 0; i < inputStepCount; i++) {
      inputStepName = inputStepNameList.get(i);
      inputSteps[i] = inputStepName;
      stream = infoStreams.get(i);
      stream.setStepMeta(transMeta.findStep(inputStepName));
      keyFields[i] = keyList.get(i);
    }

    meta.setJoinType(joinTypeCombo.getText());
  }
 private void cancel() {
   stepname = null;
   joinMeta.setChanged(backupChanged);
   dispose();
 }
  /*
   * (non-Javadoc)
   *
   * @see org.pentaho.di.trans.step.StepDialogInterface#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, joinMeta);

    final ModifyListener lsMod =
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            joinMeta.setChanged();
          }
        };
    backupChanged = joinMeta.hasChanged();

    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;

    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "MultiMergeJoinDialog.Shell.Label"));

    // int middle = props.getMiddlePct();

    wlStepname = new Label(shell, SWT.LEFT);
    wlStepname.setText(BaseMessages.getString(PKG, "MultiMergeJoinDialog.Stepname.Label"));
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.right = new FormAttachment(15, -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(15, 0);
    fdStepname.top = new FormAttachment(0, margin);
    fdStepname.right = new FormAttachment(35, 0);
    wStepname.setLayoutData(fdStepname);

    // create widgets for input stream and join key selections
    createInputStreamWidgets(lsMod);

    // create widgets for Join type
    createJoinTypeWidget(lsMod);

    // 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() {
          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);

    /*
     * 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();

    // get the data
    getData();
    joinMeta.setChanged(backupChanged);

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