public String open()

in plugins/transforms/tableoutput/src/main/java/org/apache/hop/pipeline/transforms/tableoutput/TableOutputDialog.java [159:850]


  public String open() {
    Shell parent = getParent();

    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
    PropsUi.setLook(shell);
    setShellImage(shell, input);

    ModifyListener lsMod = e -> input.setChanged();

    ModifyListener lsTableMod =
        arg0 -> {
          input.setChanged();
          setTableFieldCombo();
        };
    SelectionListener lsSelection =
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            input.setChanged();
            setTableFieldCombo();
            validateSelection();
          }
        };
    backupChanged = input.hasChanged();

    int middle = props.getMiddlePct();
    int margin = PropsUi.getMargin();

    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = PropsUi.getFormMargin();
    formLayout.marginHeight = PropsUi.getFormMargin();

    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "TableOutputDialog.DialogTitle"));

    // TransformName line
    wlTransformName = new Label(shell, SWT.RIGHT);
    wlTransformName.setText(BaseMessages.getString(PKG, "System.TransformName.Label"));
    wlTransformName.setToolTipText(BaseMessages.getString(PKG, "System.TransformName.Tooltip"));
    PropsUi.setLook(wlTransformName);
    fdlTransformName = new FormData();
    fdlTransformName.left = new FormAttachment(0, 0);
    fdlTransformName.right = new FormAttachment(middle, -margin);
    fdlTransformName.top = new FormAttachment(0, margin);
    wlTransformName.setLayoutData(fdlTransformName);
    wTransformName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wTransformName.setText(transformName);
    PropsUi.setLook(wTransformName);
    fdTransformName = new FormData();
    fdTransformName.left = new FormAttachment(middle, 0);
    fdTransformName.top = new FormAttachment(0, margin);
    fdTransformName.right = new FormAttachment(100, 0);
    wTransformName.setLayoutData(fdTransformName);

    // Connection line
    wConnection = addConnectionLine(shell, wTransformName, input.getConnection(), lsMod);
    wConnection.addModifyListener(e -> setFlags());
    wConnection.addSelectionListener(lsSelection);

    // Schema line...
    Label wlSchema = new Label(shell, SWT.RIGHT);
    wlSchema.setText(BaseMessages.getString(PKG, "TableOutputDialog.TargetSchema.Label"));
    PropsUi.setLook(wlSchema);
    FormData fdlSchema = new FormData();
    fdlSchema.left = new FormAttachment(0, 0);
    fdlSchema.right = new FormAttachment(middle, -margin);
    fdlSchema.top = new FormAttachment(wConnection, margin * 2);
    wlSchema.setLayoutData(fdlSchema);

    Button wbSchema = new Button(shell, SWT.PUSH | SWT.CENTER);
    PropsUi.setLook(wbSchema);
    wbSchema.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
    FormData fdbSchema = new FormData();
    fdbSchema.top = new FormAttachment(wConnection, 2 * margin);
    fdbSchema.right = new FormAttachment(100, 0);
    wbSchema.setLayoutData(fdbSchema);

    wSchema = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    PropsUi.setLook(wSchema);
    wSchema.addModifyListener(lsTableMod);
    FormData fdSchema = new FormData();
    fdSchema.left = new FormAttachment(middle, 0);
    fdSchema.top = new FormAttachment(wConnection, margin * 2);
    fdSchema.right = new FormAttachment(wbSchema, -margin);
    wSchema.setLayoutData(fdSchema);

    // Table line...
    wlTable = new Label(shell, SWT.RIGHT);
    wlTable.setText(BaseMessages.getString(PKG, "TableOutputDialog.TargetTable.Label"));
    PropsUi.setLook(wlTable);
    FormData fdlTable = new FormData();
    fdlTable.left = new FormAttachment(0, 0);
    fdlTable.right = new FormAttachment(middle, -margin);
    fdlTable.top = new FormAttachment(wbSchema, margin);
    wlTable.setLayoutData(fdlTable);

    Button wbTable = new Button(shell, SWT.PUSH | SWT.CENTER);
    PropsUi.setLook(wbTable);
    wbTable.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
    FormData fdbTable = new FormData();
    fdbTable.right = new FormAttachment(100, 0);
    fdbTable.top = new FormAttachment(wbSchema, margin);
    wbTable.setLayoutData(fdbTable);

    wTable = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    PropsUi.setLook(wTable);
    wTable.addModifyListener(lsTableMod);
    FormData fdTable = new FormData();
    fdTable.top = new FormAttachment(wbSchema, margin);
    fdTable.left = new FormAttachment(middle, 0);
    fdTable.right = new FormAttachment(wbTable, -margin);
    wTable.setLayoutData(fdTable);

    // Commit size ...
    Label wlCommit = new Label(shell, SWT.RIGHT);
    wlCommit.setText(BaseMessages.getString(PKG, "TableOutputDialog.CommitSize.Label"));
    PropsUi.setLook(wlCommit);
    FormData fdlCommit = new FormData();
    fdlCommit.left = new FormAttachment(0, 0);
    fdlCommit.right = new FormAttachment(middle, -margin);
    fdlCommit.top = new FormAttachment(wbTable, margin);
    wlCommit.setLayoutData(fdlCommit);
    wCommit = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    PropsUi.setLook(wCommit);
    FormData fdCommit = new FormData();
    fdCommit.left = new FormAttachment(middle, 0);
    fdCommit.top = new FormAttachment(wlCommit, 0, SWT.CENTER);
    fdCommit.right = new FormAttachment(100, 0);
    wCommit.setLayoutData(fdCommit);

    // Truncate table
    wlTruncate = new Label(shell, SWT.RIGHT);
    wlTruncate.setText(BaseMessages.getString(PKG, "TableOutputDialog.TruncateTable.Label"));
    PropsUi.setLook(wlTruncate);
    FormData fdlTruncate = new FormData();
    fdlTruncate.left = new FormAttachment(0, 0);
    fdlTruncate.top = new FormAttachment(wCommit, margin);
    fdlTruncate.right = new FormAttachment(middle, -margin);
    wlTruncate.setLayoutData(fdlTruncate);
    wTruncate = new Button(shell, SWT.CHECK);
    PropsUi.setLook(wTruncate);
    FormData fdTruncate = new FormData();
    fdTruncate.left = new FormAttachment(middle, 0);
    fdTruncate.top = new FormAttachment(wlTruncate, 0, SWT.CENTER);
    fdTruncate.right = new FormAttachment(100, 0);
    wTruncate.setLayoutData(fdTruncate);
    SelectionAdapter lsSelMod =
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            input.setChanged();
          }
        };
    wTruncate.addSelectionListener(lsSelMod);
    wTruncate.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            setFlags();
          }
        });

    // Truncate only when have rows
    Label wlOnlyWhenHaveRows = new Label(shell, SWT.RIGHT);
    wlOnlyWhenHaveRows.setText(
        BaseMessages.getString(PKG, "TableOutputDialog.OnlyWhenHaveRows.Label"));
    PropsUi.setLook(wlOnlyWhenHaveRows);
    FormData fdlOnlyWhenHaveRows = new FormData();
    fdlOnlyWhenHaveRows.left = new FormAttachment(0, 0);
    fdlOnlyWhenHaveRows.top = new FormAttachment(wlTruncate, margin);
    fdlOnlyWhenHaveRows.right = new FormAttachment(middle, -margin);
    wlOnlyWhenHaveRows.setLayoutData(fdlOnlyWhenHaveRows);
    wOnlyWhenHaveRows = new Button(shell, SWT.CHECK);
    wOnlyWhenHaveRows.setToolTipText(
        BaseMessages.getString(PKG, "TableOutputDialog.OnlyWhenHaveRows.Tooltip"));
    PropsUi.setLook(wOnlyWhenHaveRows);
    FormData fdTruncateWhenHaveRows = new FormData();
    fdTruncateWhenHaveRows.left = new FormAttachment(middle, 0);
    fdTruncateWhenHaveRows.top = new FormAttachment(wlOnlyWhenHaveRows, 0, SWT.CENTER);
    fdTruncateWhenHaveRows.right = new FormAttachment(100, 0);
    wOnlyWhenHaveRows.setLayoutData(fdTruncateWhenHaveRows);
    wOnlyWhenHaveRows.addSelectionListener(lsSelMod);

    // Ignore errors
    wlIgnore = new Label(shell, SWT.RIGHT);
    wlIgnore.setText(BaseMessages.getString(PKG, "TableOutputDialog.IgnoreInsertErrors.Label"));
    PropsUi.setLook(wlIgnore);
    FormData fdlIgnore = new FormData();
    fdlIgnore.left = new FormAttachment(0, 0);
    fdlIgnore.top = new FormAttachment(wOnlyWhenHaveRows, margin);
    fdlIgnore.right = new FormAttachment(middle, -margin);
    wlIgnore.setLayoutData(fdlIgnore);
    wIgnore = new Button(shell, SWT.CHECK);
    PropsUi.setLook(wIgnore);
    FormData fdIgnore = new FormData();
    fdIgnore.left = new FormAttachment(middle, 0);
    fdIgnore.top = new FormAttachment(wlIgnore, 0, SWT.CENTER);
    fdIgnore.right = new FormAttachment(100, 0);
    wIgnore.setLayoutData(fdIgnore);
    wIgnore.addSelectionListener(lsSelMod);

    // Specify fields
    Label wlSpecifyFields = new Label(shell, SWT.RIGHT);
    wlSpecifyFields.setText(BaseMessages.getString(PKG, "TableOutputDialog.SpecifyFields.Label"));
    PropsUi.setLook(wlSpecifyFields);
    FormData fdlSpecifyFields = new FormData();
    fdlSpecifyFields.left = new FormAttachment(0, 0);
    fdlSpecifyFields.top = new FormAttachment(wIgnore, margin);
    fdlSpecifyFields.right = new FormAttachment(middle, -margin);
    wlSpecifyFields.setLayoutData(fdlSpecifyFields);
    wSpecifyFields = new Button(shell, SWT.CHECK);
    PropsUi.setLook(wSpecifyFields);
    FormData fdSpecifyFields = new FormData();
    fdSpecifyFields.left = new FormAttachment(middle, 0);
    fdSpecifyFields.top = new FormAttachment(wlSpecifyFields, 0, SWT.CENTER);
    fdSpecifyFields.right = new FormAttachment(100, 0);
    wSpecifyFields.setLayoutData(fdSpecifyFields);
    wSpecifyFields.addSelectionListener(lsSelMod);

    // If the flag is off, gray out the fields tab e.g.
    wSpecifyFields.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            setFlags();
          }
        });

    CTabFolder wTabFolder = new CTabFolder(shell, SWT.BORDER);
    PropsUi.setLook(wTabFolder, Props.WIDGET_STYLE_TAB);

    // ////////////////////////
    // START OF KEY TAB ///
    // /
    CTabItem wMainTab = new CTabItem(wTabFolder, SWT.NONE);
    wMainTab.setFont(GuiResource.getInstance().getFontDefault());
    wMainTab.setText(BaseMessages.getString(PKG, "TableOutputDialog.MainTab.CTabItem"));

    FormLayout mainLayout = new FormLayout();
    mainLayout.marginWidth = 3;
    mainLayout.marginHeight = 3;

    Composite wMainComp = new Composite(wTabFolder, SWT.NONE);
    PropsUi.setLook(wMainComp);
    wMainComp.setLayout(mainLayout);

    // Partitioning support

    // Use partitioning?
    Label wlUsePart = new Label(wMainComp, SWT.RIGHT);
    wlUsePart.setText(BaseMessages.getString(PKG, "TableOutputDialog.UsePart.Label"));
    wlUsePart.setToolTipText(BaseMessages.getString(PKG, "TableOutputDialog.UsePart.Tooltip"));
    PropsUi.setLook(wlUsePart);
    FormData fdlUsePart = new FormData();
    fdlUsePart.left = new FormAttachment(0, 0);
    fdlUsePart.top = new FormAttachment(0, margin);
    fdlUsePart.right = new FormAttachment(middle, -margin);
    wlUsePart.setLayoutData(fdlUsePart);
    wUsePart = new Button(wMainComp, SWT.CHECK);
    PropsUi.setLook(wUsePart);
    FormData fdUsePart = new FormData();
    fdUsePart.left = new FormAttachment(middle, 0);
    fdUsePart.top = new FormAttachment(wlUsePart, 0, SWT.CENTER);
    fdUsePart.right = new FormAttachment(100, 0);
    wUsePart.setLayoutData(fdUsePart);
    wUsePart.addSelectionListener(lsSelMod);

    wUsePart.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            if (wUsePart.getSelection()) {
              wNameInField.setSelection(false);
            }
            setFlags();
          }
        });

    // Partitioning field
    wlPartField = new Label(wMainComp, SWT.RIGHT);
    wlPartField.setText(BaseMessages.getString(PKG, "TableOutputDialog.PartField.Label"));
    PropsUi.setLook(wlPartField);
    FormData fdlPartField = new FormData();
    fdlPartField.top = new FormAttachment(wUsePart, margin);
    fdlPartField.left = new FormAttachment(0, 0);
    fdlPartField.right = new FormAttachment(middle, -margin);
    wlPartField.setLayoutData(fdlPartField);
    wPartField = new ComboVar(variables, wMainComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    PropsUi.setLook(wPartField);
    FormData fdPartField = new FormData();
    fdPartField.top = new FormAttachment(wlPartField, 0, SWT.CENTER);
    fdPartField.left = new FormAttachment(middle, 0);
    fdPartField.right = new FormAttachment(100, 0);
    wPartField.setLayoutData(fdPartField);
    wPartField.addFocusListener(
        new FocusListener() {
          @Override
          public void focusLost(FocusEvent e) {
            // Do nothing on focuslost
          }

          @Override
          public void focusGained(FocusEvent e) {
            Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
            shell.setCursor(busy);
            getFields();
            shell.setCursor(null);
            busy.dispose();
          }
        });

    // Partition per month
    wlPartMonthly = new Label(wMainComp, SWT.RIGHT);
    wlPartMonthly.setText(BaseMessages.getString(PKG, "TableOutputDialog.PartMonthly.Label"));
    wlPartMonthly.setToolTipText(
        BaseMessages.getString(PKG, "TableOutputDialog.PartMonthly.Tooltip"));
    PropsUi.setLook(wlPartMonthly);
    FormData fdlPartMonthly = new FormData();
    fdlPartMonthly.left = new FormAttachment(0, 0);
    fdlPartMonthly.top = new FormAttachment(wPartField, margin);
    fdlPartMonthly.right = new FormAttachment(middle, -margin);
    wlPartMonthly.setLayoutData(fdlPartMonthly);
    wPartMonthly = new Button(wMainComp, SWT.RADIO);
    PropsUi.setLook(wPartMonthly);
    FormData fdPartMonthly = new FormData();
    fdPartMonthly.left = new FormAttachment(middle, 0);
    fdPartMonthly.top = new FormAttachment(wlPartMonthly, 0, SWT.CENTER);
    fdPartMonthly.right = new FormAttachment(100, 0);
    wPartMonthly.setLayoutData(fdPartMonthly);
    wPartMonthly.addSelectionListener(lsSelMod);

    wPartMonthly.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            wPartMonthly.setSelection(true);
            wPartDaily.setSelection(false);
          }
        });

    // Partition per month
    wlPartDaily = new Label(wMainComp, SWT.RIGHT);
    wlPartDaily.setText(BaseMessages.getString(PKG, "TableOutputDialog.PartDaily.Label"));
    wlPartDaily.setToolTipText(BaseMessages.getString(PKG, "TableOutputDialog.PartDaily.Tooltip"));
    PropsUi.setLook(wlPartDaily);
    FormData fdlPartDaily = new FormData();
    fdlPartDaily.left = new FormAttachment(0, 0);
    fdlPartDaily.top = new FormAttachment(wPartMonthly, margin);
    fdlPartDaily.right = new FormAttachment(middle, -margin);
    wlPartDaily.setLayoutData(fdlPartDaily);
    wPartDaily = new Button(wMainComp, SWT.RADIO);
    PropsUi.setLook(wPartDaily);
    FormData fdPartDaily = new FormData();
    fdPartDaily.left = new FormAttachment(middle, 0);
    fdPartDaily.top = new FormAttachment(wlPartDaily, 0, SWT.CENTER);
    fdPartDaily.right = new FormAttachment(100, 0);
    wPartDaily.setLayoutData(fdPartDaily);
    wPartDaily.addSelectionListener(lsSelMod);

    wPartDaily.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            wPartDaily.setSelection(true);
            wPartMonthly.setSelection(false);
          }
        });

    // Batch update
    wlBatch = new Label(wMainComp, SWT.RIGHT);
    wlBatch.setText(BaseMessages.getString(PKG, "TableOutputDialog.Batch.Label"));
    PropsUi.setLook(wlBatch);
    FormData fdlBatch = new FormData();
    fdlBatch.left = new FormAttachment(0, 0);
    fdlBatch.top = new FormAttachment(wPartDaily, 5 * margin);
    fdlBatch.right = new FormAttachment(middle, -margin);
    wlBatch.setLayoutData(fdlBatch);
    wBatch = new Button(wMainComp, SWT.CHECK);
    PropsUi.setLook(wBatch);
    FormData fdBatch = new FormData();
    fdBatch.left = new FormAttachment(middle, 0);
    fdBatch.top = new FormAttachment(wlBatch, 0, SWT.CENTER);
    fdBatch.right = new FormAttachment(100, 0);
    wBatch.setLayoutData(fdBatch);
    wBatch.addSelectionListener(lsSelMod);
    wBatch.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            setFlags();
          }
        });

    // NameInField
    Label wlNameInField = new Label(wMainComp, SWT.RIGHT);
    wlNameInField.setText(BaseMessages.getString(PKG, "TableOutputDialog.NameInField.Label"));
    PropsUi.setLook(wlNameInField);
    FormData fdlNameInField = new FormData();
    fdlNameInField.left = new FormAttachment(0, 0);
    fdlNameInField.top = new FormAttachment(wBatch, margin * 5);
    fdlNameInField.right = new FormAttachment(middle, -margin);
    wlNameInField.setLayoutData(fdlNameInField);
    wNameInField = new Button(wMainComp, SWT.CHECK);
    PropsUi.setLook(wNameInField);
    FormData fdNameInField = new FormData();
    fdNameInField.left = new FormAttachment(middle, 0);
    fdNameInField.top = new FormAttachment(wlNameInField, 0, SWT.CENTER);
    fdNameInField.right = new FormAttachment(100, 0);
    wNameInField.setLayoutData(fdNameInField);
    wNameInField.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent se) {
            if (wNameInField.getSelection()) {
              wUsePart.setSelection(false);
            }
            setFlags();
          }
        });
    wNameInField.addSelectionListener(lsSelMod);

    // NameField size ...
    wlNameField = new Label(wMainComp, SWT.RIGHT);
    wlNameField.setText(BaseMessages.getString(PKG, "TableOutputDialog.NameField.Label"));
    PropsUi.setLook(wlNameField);
    FormData fdlNameField = new FormData();
    fdlNameField.left = new FormAttachment(0, 0);
    fdlNameField.top = new FormAttachment(wNameInField, margin);
    fdlNameField.right = new FormAttachment(middle, -margin);
    wlNameField.setLayoutData(fdlNameField);
    wNameField = new ComboVar(variables, wMainComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    PropsUi.setLook(wNameField);
    FormData fdNameField = new FormData();
    fdNameField.left = new FormAttachment(middle, 0);
    fdNameField.top = new FormAttachment(wlNameField, 0, SWT.CENTER);
    fdNameField.right = new FormAttachment(100, 0);
    wNameField.setLayoutData(fdNameField);
    wNameField.addFocusListener(
        new FocusListener() {
          @Override
          public void focusLost(FocusEvent e) {
            // Do nothing on focuslost
          }

          @Override
          public void focusGained(FocusEvent e) {
            Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
            shell.setCursor(busy);
            getFields();
            shell.setCursor(null);
            busy.dispose();
          }
        });

    // NameInTable
    wlNameInTable = new Label(wMainComp, SWT.RIGHT);
    wlNameInTable.setText(BaseMessages.getString(PKG, "TableOutputDialog.NameInTable.Label"));
    PropsUi.setLook(wlNameInTable);
    FormData fdlNameInTable = new FormData();
    fdlNameInTable.left = new FormAttachment(0, 0);
    fdlNameInTable.top = new FormAttachment(wNameField, margin);
    fdlNameInTable.right = new FormAttachment(middle, -margin);
    wlNameInTable.setLayoutData(fdlNameInTable);
    wNameInTable = new Button(wMainComp, SWT.CHECK);
    PropsUi.setLook(wNameInTable);
    FormData fdNameInTable = new FormData();
    fdNameInTable.left = new FormAttachment(middle, 0);
    fdNameInTable.top = new FormAttachment(wlNameInTable, 0, SWT.CENTER);
    fdNameInTable.right = new FormAttachment(100, 0);
    wNameInTable.setLayoutData(fdNameInTable);
    wNameInTable.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            setFlags();
          }
        });
    wNameInTable.addSelectionListener(lsSelMod);

    // Return generated keys?
    Label wlReturnKeys = new Label(wMainComp, SWT.RIGHT);
    wlReturnKeys.setText(BaseMessages.getString(PKG, "TableOutputDialog.ReturnKeys.Label"));
    wlReturnKeys.setToolTipText(
        BaseMessages.getString(PKG, "TableOutputDialog.ReturnKeys.Tooltip"));
    PropsUi.setLook(wlReturnKeys);
    FormData fdlReturnKeys = new FormData();
    fdlReturnKeys.left = new FormAttachment(0, 0);
    fdlReturnKeys.top = new FormAttachment(wNameInTable, margin * 5);
    fdlReturnKeys.right = new FormAttachment(middle, -margin);
    wlReturnKeys.setLayoutData(fdlReturnKeys);
    wReturnKeys = new Button(wMainComp, SWT.CHECK);
    PropsUi.setLook(wReturnKeys);
    FormData fdReturnKeys = new FormData();
    fdReturnKeys.left = new FormAttachment(middle, 0);
    fdReturnKeys.top = new FormAttachment(wlReturnKeys, 0, SWT.CENTER);
    fdReturnKeys.right = new FormAttachment(100, 0);
    wReturnKeys.setLayoutData(fdReturnKeys);
    wReturnKeys.addSelectionListener(lsSelMod);
    wReturnKeys.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            setFlags();
          }
        });

    // ReturnField size ...
    wlReturnField = new Label(wMainComp, SWT.RIGHT);
    wlReturnField.setText(BaseMessages.getString(PKG, "TableOutputDialog.ReturnField.Label"));
    PropsUi.setLook(wlReturnField);
    FormData fdlReturnField = new FormData();
    fdlReturnField.left = new FormAttachment(0, 0);
    fdlReturnField.right = new FormAttachment(middle, -margin);
    fdlReturnField.top = new FormAttachment(wReturnKeys, margin);
    wlReturnField.setLayoutData(fdlReturnField);
    wReturnField = new TextVar(variables, wMainComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    PropsUi.setLook(wReturnField);
    FormData fdReturnField = new FormData();
    fdReturnField.left = new FormAttachment(middle, 0);
    fdReturnField.top = new FormAttachment(wlReturnField, 0, SWT.CENTER);
    fdReturnField.right = new FormAttachment(100, 0);
    wReturnField.setLayoutData(fdReturnField);

    FormData fdMainComp = new FormData();
    fdMainComp.left = new FormAttachment(0, 0);
    fdMainComp.top = new FormAttachment(0, 0);
    fdMainComp.right = new FormAttachment(100, 0);
    fdMainComp.bottom = new FormAttachment(100, 0);
    wMainComp.setLayoutData(fdMainComp);

    wMainComp.layout();
    wMainTab.setControl(wMainComp);

    //
    // Fields tab...
    //
    CTabItem wFieldsTab = new CTabItem(wTabFolder, SWT.NONE);
    wFieldsTab.setFont(GuiResource.getInstance().getFontDefault());
    wFieldsTab.setText(BaseMessages.getString(PKG, "TableOutputDialog.FieldsTab.CTabItem.Title"));

    Composite wFieldsComp = new Composite(wTabFolder, SWT.NONE);
    PropsUi.setLook(wFieldsComp);

    FormLayout fieldsCompLayout = new FormLayout();
    fieldsCompLayout.marginWidth = PropsUi.getFormMargin();
    fieldsCompLayout.marginHeight = PropsUi.getFormMargin();
    wFieldsComp.setLayout(fieldsCompLayout);

    // The fields table
    Label wlFields = new Label(wFieldsComp, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "TableOutputDialog.InsertFields.Label"));
    PropsUi.setLook(wlFields);
    FormData fdlUpIns = new FormData();
    fdlUpIns.left = new FormAttachment(0, 0);
    fdlUpIns.top = new FormAttachment(0, margin);
    wlFields.setLayoutData(fdlUpIns);

    int tableCols = 2;
    int upInsRows =
        (input.getFields() != null && !input.getFields().equals(Collections.emptyList())
            ? input.getFields().size()
            : 1);

    ciFields = new ColumnInfo[tableCols];
    ciFields[0] =
        new ColumnInfo(
            BaseMessages.getString(PKG, "TableOutputDialog.ColumnInfo.TableField"),
            ColumnInfo.COLUMN_TYPE_CCOMBO,
            new String[] {""},
            false);
    ciFields[1] =
        new ColumnInfo(
            BaseMessages.getString(PKG, "TableOutputDialog.ColumnInfo.StreamField"),
            ColumnInfo.COLUMN_TYPE_CCOMBO,
            new String[] {""},
            false);
    tableFieldColumns.add(ciFields[0]);
    wFields =
        new TableView(
            variables,
            wFieldsComp,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL,
            ciFields,
            upInsRows,
            lsMod,
            props);

    wGetFields = new Button(wFieldsComp, SWT.PUSH);
    wGetFields.setText(BaseMessages.getString(PKG, "TableOutputDialog.GetFields.Button"));
    FormData fdGetFields = new FormData();
    fdGetFields.top = new FormAttachment(wlFields, margin);
    fdGetFields.right = new FormAttachment(100, 0);
    wGetFields.setLayoutData(fdGetFields);

    wDoMapping = new Button(wFieldsComp, SWT.PUSH);
    wDoMapping.setText(BaseMessages.getString(PKG, "TableOutputDialog.DoMapping.Button"));
    FormData fdDoMapping = new FormData();
    fdDoMapping.top = new FormAttachment(wGetFields, margin);
    fdDoMapping.right = new FormAttachment(100, 0);
    wDoMapping.setLayoutData(fdDoMapping);

    wDoMapping.addListener(SWT.Selection, arg0 -> generateMappings());

    FormData fdFields = new FormData();
    fdFields.left = new FormAttachment(0, 0);
    fdFields.top = new FormAttachment(wlFields, margin);
    fdFields.right = new FormAttachment(wDoMapping, -margin);
    fdFields.bottom = new FormAttachment(100, -2 * margin);
    wFields.setLayoutData(fdFields);

    FormData fdFieldsComp = new FormData();
    fdFieldsComp.left = new FormAttachment(0, 0);
    fdFieldsComp.top = new FormAttachment(0, 0);
    fdFieldsComp.right = new FormAttachment(100, 0);
    fdFieldsComp.bottom = new FormAttachment(100, 0);
    wFieldsComp.setLayoutData(fdFieldsComp);

    wFieldsComp.layout();
    wFieldsTab.setControl(wFieldsComp);

    //
    // Search the fields in the background
    //

    final Runnable runnable =
        () -> {
          TransformMeta transformMeta = pipelineMeta.findTransform(transformName);
          if (transformMeta != null) {
            try {
              IRowMeta row = pipelineMeta.getPrevTransformFields(variables, transformMeta);

              // Remember these fields...
              for (int i = 0; i < row.size(); i++) {
                inputFields.add(row.getValueMeta(i).getName());
              }

              setComboBoxes();
            } catch (HopException e) {
              logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
            }
          }
        };
    new Thread(runnable).start();

    // Some buttons
    wOk = new Button(shell, SWT.PUSH);
    wOk.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wCreate = new Button(shell, SWT.PUSH);
    wCreate.setText(BaseMessages.getString(PKG, "System.Button.SQL"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));

    setButtonPositions(new Button[] {wOk, wCancel, wCreate}, margin, null);

    FormData fdTabFolder = new FormData();
    fdTabFolder.left = new FormAttachment(0, 0);
    fdTabFolder.top = new FormAttachment(wSpecifyFields, 3 * margin);
    fdTabFolder.right = new FormAttachment(100, 0);
    fdTabFolder.bottom = new FormAttachment(wOk, -margin);
    wTabFolder.setLayoutData(fdTabFolder);

    // Add listeners
    wOk.addListener(SWT.Selection, e -> ok());
    wCreate.addListener(SWT.Selection, e -> sql());
    wCancel.addListener(SWT.Selection, e -> cancel());
    wGetFields.addListener(SWT.Selection, e -> get());

    wbTable.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            getTableName();
          }
        });
    wbSchema.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            getSchemaNames();
          }
        });

    wTabFolder.setSelection(0);

    getData();
    setTableFieldCombo();
    input.setChanged(backupChanged);

    BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel());

    return transformName;
  }