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

    stepname = wStepname.getText(); // return value
    // copy info to TextFileInputMeta class (input)
    input.setSql(wSQL.getText());
    input.setDatabaseMeta(transMeta.findDatabase(wConnection.getText()));
    input.setExecutedEachInputRow(wEachRow.getSelection());
    input.setSingleStatement(wSingleStatement.getSelection());
    input.setVariableReplacementActive(wVariables.getSelection());
    input.setQuoteString(wQuoteString.getSelection());
    input.setParams(wSetParams.getSelection());
    input.setInsertField(wInsertField.getText());
    input.setUpdateField(wUpdateField.getText());
    input.setDeleteField(wDeleteField.getText());
    input.setReadField(wReadField.getText());

    int nrargs = wFields.nrNonEmpty();
    input.allocate(nrargs);
    if (log.isDebug())
      logDebug(BaseMessages.getString(PKG, "ExecSQLDialog.Log.FoundArguments", +nrargs + ""));
    for (int i = 0; i < nrargs; i++) {
      TableItem item = wFields.getNonEmpty(i);
      input.getArguments()[i] = item.getText(1);
    }

    if (input.getDatabaseMeta() == null) {
      MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
      mb.setMessage(BaseMessages.getString(PKG, "ExecSQLDialog.InvalidConnection.DialogMessage"));
      mb.setText(BaseMessages.getString(PKG, "ExecSQLDialog.InvalidConnection.DialogTitle"));
      mb.open();
    }

    dispose();
  }
  /** Copy information from the meta-data input to the dialog fields. */
  public void getData() {
    if (input.getSql() != null) wSQL.setText(input.getSql());
    if (input.getDatabaseMeta() != null) wConnection.setText(input.getDatabaseMeta().getName());
    wEachRow.setSelection(input.isExecutedEachInputRow());
    wSingleStatement.setSelection(input.isSingleStatement());
    wVariables.setSelection(input.isReplaceVariables());
    wQuoteString.setSelection(input.isQuoteString());

    if (input.getUpdateField() != null) wUpdateField.setText(input.getUpdateField());
    if (input.getInsertField() != null) wInsertField.setText(input.getInsertField());
    if (input.getDeleteField() != null) wDeleteField.setText(input.getDeleteField());
    if (input.getReadField() != null) wReadField.setText(input.getReadField());

    for (int i = 0; i < input.getArguments().length; i++) {
      TableItem item = wFields.table.getItem(i);
      if (input.getArguments()[i] != null) item.setText(1, input.getArguments()[i]);
    }
    wSetParams.setSelection(input.isParams());

    wStepname.selectAll();
    wStepname.setFocus();
  }
  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) {
            changedInDialog = true;
            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, "ExecSQLDialog.Shell.Label"));

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

    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "ExecSQLDialog.Stepname.Label"));
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.right = new FormAttachment(middle, -margin);
    fdlStepname.top = new FormAttachment(0, margin);
    wlStepname.setLayoutData(fdlStepname);
    wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wStepname.setText(stepname);
    props.setLook(wStepname);
    wStepname.addModifyListener(lsMod);
    fdStepname = new FormData();
    fdStepname.left = new FormAttachment(middle, 0);
    fdStepname.top = new FormAttachment(0, margin);
    fdStepname.right = new FormAttachment(100, 0);
    wStepname.setLayoutData(fdStepname);

    // Connection line
    wConnection = addConnectionLine(shell, wStepname, middle, margin);
    if (input.getDatabaseMeta() == null && transMeta.nrDatabases() == 1) wConnection.select(0);
    wConnection.addModifyListener(lsMod);

    // Table line...
    wlSQL = new Label(shell, SWT.LEFT);
    wlSQL.setText(BaseMessages.getString(PKG, "ExecSQLDialog.SQL.Label"));
    props.setLook(wlSQL);
    fdlSQL = new FormData();
    fdlSQL.left = new FormAttachment(0, 0);
    fdlSQL.top = new FormAttachment(wConnection, margin * 2);
    wlSQL.setLayoutData(fdlSQL);

    wSQL =
        new StyledTextComp(
            transMeta, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, "");
    props.setLook(wSQL, Props.WIDGET_STYLE_FIXED);
    wSQL.addModifyListener(lsMod);
    wSQL.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent arg0) {
            setPosition();
          }
        });

    wSQL.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            setPosition();
          }

          public void keyReleased(KeyEvent e) {
            setPosition();
          }
        });
    wSQL.addFocusListener(
        new FocusAdapter() {
          public void focusGained(FocusEvent e) {
            setPosition();
          }

          public void focusLost(FocusEvent e) {
            setPosition();
          }
        });
    wSQL.addMouseListener(
        new MouseAdapter() {
          public void mouseDoubleClick(MouseEvent e) {
            setPosition();
          }

          public void mouseDown(MouseEvent e) {
            setPosition();
          }

          public void mouseUp(MouseEvent e) {
            setPosition();
          }
        });

    // Text Higlighting
    wSQL.addLineStyleListener(new SQLValuesHighlight());

    // 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, "ExecSQLDialog.GetFields.Button"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] {wOK, wCancel, wGet}, margin, null);

    // Build it up from the bottom up...
    // Read field
    //
    wlReadField = new Label(shell, SWT.RIGHT);
    wlReadField.setText(BaseMessages.getString(PKG, "ExecSQLDialog.ReadField.Label"));
    props.setLook(wlReadField);
    fdlReadField = new FormData();
    fdlReadField.left = new FormAttachment(middle, margin);
    fdlReadField.right = new FormAttachment(middle * 2, -margin);
    fdlReadField.bottom = new FormAttachment(wOK, -3 * margin);
    wlReadField.setLayoutData(fdlReadField);
    wReadField = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wReadField);
    wReadField.addModifyListener(lsMod);
    fdReadField = new FormData();
    fdReadField.left = new FormAttachment(middle * 2, 0);
    fdReadField.bottom = new FormAttachment(wOK, -3 * margin);
    fdReadField.right = new FormAttachment(100, 0);
    wReadField.setLayoutData(fdReadField);

    // Delete field
    //
    wlDeleteField = new Label(shell, SWT.RIGHT);
    wlDeleteField.setText(BaseMessages.getString(PKG, "ExecSQLDialog.DeleteField.Label"));
    props.setLook(wlDeleteField);
    fdlDeleteField = new FormData();
    fdlDeleteField.left = new FormAttachment(middle, margin);
    fdlDeleteField.right = new FormAttachment(middle * 2, -margin);
    fdlDeleteField.bottom = new FormAttachment(wReadField, -margin);
    wlDeleteField.setLayoutData(fdlDeleteField);
    wDeleteField = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDeleteField);
    wDeleteField.addModifyListener(lsMod);
    fdDeleteField = new FormData();
    fdDeleteField.left = new FormAttachment(middle * 2, 0);
    fdDeleteField.bottom = new FormAttachment(wReadField, -margin);
    fdDeleteField.right = new FormAttachment(100, 0);
    wDeleteField.setLayoutData(fdDeleteField);

    // Update field
    //
    wlUpdateField = new Label(shell, SWT.RIGHT);
    wlUpdateField.setText(BaseMessages.getString(PKG, "ExecSQLDialog.UpdateField.Label"));
    props.setLook(wlUpdateField);
    fdlUpdateField = new FormData();
    fdlUpdateField.left = new FormAttachment(middle, margin);
    fdlUpdateField.right = new FormAttachment(middle * 2, -margin);
    fdlUpdateField.bottom = new FormAttachment(wDeleteField, -margin);
    wlUpdateField.setLayoutData(fdlUpdateField);
    wUpdateField = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wUpdateField);
    wUpdateField.addModifyListener(lsMod);
    fdUpdateField = new FormData();
    fdUpdateField.left = new FormAttachment(middle * 2, 0);
    fdUpdateField.bottom = new FormAttachment(wDeleteField, -margin);
    fdUpdateField.right = new FormAttachment(100, 0);
    wUpdateField.setLayoutData(fdUpdateField);

    // insert field
    //
    wlInsertField = new Label(shell, SWT.RIGHT);
    wlInsertField.setText(BaseMessages.getString(PKG, "ExecSQLDialog.InsertField.Label"));
    props.setLook(wlInsertField);
    fdlInsertField = new FormData();
    fdlInsertField.left = new FormAttachment(middle, margin);
    fdlInsertField.right = new FormAttachment(middle * 2, -margin);
    fdlInsertField.bottom = new FormAttachment(wUpdateField, -margin);
    wlInsertField.setLayoutData(fdlInsertField);
    wInsertField = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wInsertField);
    wInsertField.addModifyListener(lsMod);
    fdInsertField = new FormData();
    fdInsertField.left = new FormAttachment(middle * 2, 0);
    fdInsertField.bottom = new FormAttachment(wUpdateField, -margin);
    fdInsertField.right = new FormAttachment(100, 0);
    wInsertField.setLayoutData(fdInsertField);

    // Setup the "Parameters" label
    //
    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "ExecSQLDialog.Fields.Label"));
    props.setLook(wlFields);
    fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.right = new FormAttachment(middle, 0);
    fdlFields.bottom = new FormAttachment(wInsertField, -25);
    wlFields.setLayoutData(fdlFields);

    // Parameter fields...
    //
    final int FieldsRows = input.getArguments().length;

    colinf =
        new ColumnInfo[] {
          new ColumnInfo(
              BaseMessages.getString(PKG, "ExecSQLDialog.ColumnInfo.ArgumentFieldname"),
              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(middle, 0);
    fdFields.bottom = new FormAttachment(wOK, -3 * margin);
    wFields.setLayoutData(fdFields);

    // For the "execute for each row" and "variable substitution" labels,
    // find their maximum width
    // and use that in the alignment
    //
    wlEachRow = new Label(shell, SWT.RIGHT);
    wlEachRow.setText(BaseMessages.getString(PKG, "ExecSQLDialog.EachRow.Label"));
    wlEachRow.pack();
    wlSingleStatement = new Label(shell, SWT.RIGHT);
    wlSingleStatement.setText(BaseMessages.getString(PKG, "ExecSQLDialog.SingleStatement.Label"));
    wlSingleStatement.pack();
    wlVariables = new Label(shell, SWT.RIGHT);
    wlVariables.setText(BaseMessages.getString(PKG, "ExecSQLDialog.ReplaceVariables"));
    wlVariables.pack();
    wlQuoteString = new Label(shell, SWT.RIGHT);
    wlQuoteString.setText(BaseMessages.getString(PKG, "ExecSQLDialog.QuoteString.Label"));
    wlQuoteString.pack();
    Rectangle rEachRow = wlEachRow.getBounds();
    Rectangle rSingleStatement = wlSingleStatement.getBounds();
    Rectangle rVariables = wlVariables.getBounds();
    Rectangle rQuoteString = wlQuoteString.getBounds();
    int width =
        Math.max(
                Math.max(Math.max(rEachRow.width, rSingleStatement.width), rVariables.width),
                rQuoteString.width)
            + 30;

    // Setup the "Quote String" label and checkbox
    //
    props.setLook(wlQuoteString);
    fdlQuoteString = new FormData();
    fdlQuoteString.left = new FormAttachment(0, margin);
    fdlQuoteString.right = new FormAttachment(0, width);
    fdlQuoteString.bottom = new FormAttachment(wlFields, -2 * margin);
    wlQuoteString.setLayoutData(fdlQuoteString);
    wQuoteString = new Button(shell, SWT.CHECK);
    props.setLook(wQuoteString);
    wQuoteString.setToolTipText(BaseMessages.getString(PKG, "ExecSQLDialog.QuoteString.Tooltip"));
    fdQuoteString = new FormData();
    fdQuoteString.left = new FormAttachment(wlQuoteString, margin);
    fdQuoteString.bottom = new FormAttachment(wlFields, -2 * margin);
    fdQuoteString.right = new FormAttachment(middle, 0);
    wQuoteString.setLayoutData(fdQuoteString);

    // Setup the "Bind parameters" label and checkbox
    //
    wlSetParams = new Label(this.shell, SWT.RIGHT);
    wlSetParams.setText(BaseMessages.getString(PKG, "ExecSQLDialog.SetParams.Label"));
    props.setLook(this.wlSetParams);
    fdlSetParams = new FormData();
    fdlSetParams.left = new FormAttachment(0, margin);
    fdlSetParams.bottom = new FormAttachment(wQuoteString, -margin);
    fdlSetParams.right = new FormAttachment(0, width);
    wlSetParams.setLayoutData(this.fdlSetParams);
    wSetParams = new Button(shell, SWT.CHECK);
    props.setLook(this.wSetParams);
    wSetParams.setToolTipText(BaseMessages.getString(PKG, "ExecSQLDialog.SetParams.Tooltip"));
    fdSetParams = new FormData();
    fdSetParams.left = new FormAttachment(wlSetParams, margin);
    fdSetParams.bottom = new FormAttachment(wQuoteString, -margin);
    fdSetParams.right = new FormAttachment(middle, 0);
    wSetParams.setLayoutData(fdSetParams);
    wSetParams.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            setExecutedSetParams();
            input.setChanged();
          }
        });

    // Setup the "variable substitution" label and checkbox
    //
    props.setLook(wlVariables);
    fdlVariables = new FormData();
    fdlVariables.left = new FormAttachment(0, margin);
    fdlVariables.right = new FormAttachment(0, width);
    fdlVariables.bottom = new FormAttachment(wSetParams, -margin);
    wlVariables.setLayoutData(fdlVariables);
    wVariables = new Button(shell, SWT.CHECK);
    props.setLook(wVariables);
    fdVariables = new FormData();
    fdVariables.left = new FormAttachment(wlVariables, margin);
    fdVariables.bottom = new FormAttachment(wSetParams, -margin);
    fdVariables.right = new FormAttachment(middle, 0);
    wVariables.setLayoutData(fdVariables);
    // wVariables.addSelectionListener(new SelectionAdapter() { public void
    // widgetSelected(SelectionEvent arg0) { setSQLToolTip(); } });

    // Setup the "Single statement" label and checkbox
    //
    props.setLook(wlSingleStatement);
    FormData fdlSingleStatement = new FormData();
    fdlSingleStatement.left = new FormAttachment(0, margin);
    fdlSingleStatement.right = new FormAttachment(0, width);
    fdlSingleStatement.bottom = new FormAttachment(wVariables, -margin);
    wlSingleStatement.setLayoutData(fdlSingleStatement);
    wSingleStatement = new Button(shell, SWT.CHECK);
    props.setLook(wSingleStatement);
    FormData fdSingleStatement = new FormData();
    fdSingleStatement.left = new FormAttachment(wlEachRow, margin);
    fdSingleStatement.bottom = new FormAttachment(wVariables, -margin);
    fdSingleStatement.right = new FormAttachment(middle, 0);
    wSingleStatement.setLayoutData(fdSingleStatement);

    // Setup the "execute for each row" label and checkbox
    //
    props.setLook(wlEachRow);
    FormData fdlEachRow = new FormData();
    fdlEachRow.left = new FormAttachment(0, margin);
    fdlEachRow.right = new FormAttachment(0, width);
    fdlEachRow.bottom = new FormAttachment(wSingleStatement, -margin);
    wlEachRow.setLayoutData(fdlEachRow);
    wEachRow = new Button(shell, SWT.CHECK);
    props.setLook(wEachRow);
    FormData fdEachRow = new FormData();
    fdEachRow.left = new FormAttachment(wlEachRow, margin);
    fdEachRow.bottom = new FormAttachment(wSingleStatement, -margin);
    fdEachRow.right = new FormAttachment(middle, 0);
    wEachRow.setLayoutData(fdEachRow);

    // Position label under the SQL editor
    //
    wlPosition = new Label(shell, SWT.NONE);
    props.setLook(wlPosition);
    fdlPosition = new FormData();
    fdlPosition.left = new FormAttachment(0, 0);
    fdlPosition.right = new FormAttachment(100, 0);
    fdlPosition.bottom =
        new FormAttachment(
            wEachRow, -2 * margin); // 2 times since we deal with bottom instead of top
    wlPosition.setLayoutData(fdlPosition);

    // Finally, the SQL editor takes up all other space between the position and the SQL label
    //
    fdSQL = new FormData();
    fdSQL.left = new FormAttachment(0, 0);
    fdSQL.top = new FormAttachment(wlSQL, margin);
    fdSQL.right = new FormAttachment(100, -2 * margin);
    fdSQL.bottom = new FormAttachment(wlPosition, -margin);
    wSQL.setLayoutData(fdSQL);

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

    wEachRow.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            ExecSQLDialog.this.setExecutedEachInputRow();
            ExecSQLDialog.this.input.setChanged();
          }
        });

    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(
        new ShellAdapter() {
          public void shellClosed(ShellEvent e) {
            checkCancel(e);
          }
        });

    getData();
    setExecutedEachInputRow();
    changedInDialog = false; // for prompting if dialog is simply closed
    input.setChanged(changed);

    // Set the shell size, based upon previous time...
    setSize();

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