コード例 #1
0
  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);

    if (!SAPLibraryTester.isJCoLibAvailable()) {
      int style = SWT.ICON_ERROR;
      MessageBox messageBox = new MessageBox(shell, style);
      messageBox.setMessage(BaseMessages.getString(PKG, "SapInputDialog.JCoLibNotFound"));
      messageBox.open();
      // dispose();
      // return stepname;
    }

    if (!SAPLibraryTester.isJCoImplAvailable()) {
      int style = SWT.ICON_ERROR;
      MessageBox messageBox = new MessageBox(shell, style);
      messageBox.setMessage(BaseMessages.getString(PKG, "SapInputDialog.JCoImplNotFound"));
      messageBox.open();
      // dispose();
      // return stepname;
    }

    ModifyListener lsMod =
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            input.setChanged();
          }
        };

    ModifyListener lsConnectionMod =
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            input.setChanged();
          }
        };
    backupChanged = input.hasChanged();

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

    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "SapInputDialog.shell.Title"));

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

    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "SapInputDialog.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);
    Control lastControl = wStepname;

    // Connection line
    //
    wConnection = addConnectionLine(shell, lastControl, middle, margin);
    List<String> items = new ArrayList<String>();
    for (DatabaseMeta dbMeta : transMeta.getDatabases()) {
      if (dbMeta.getDatabaseInterface() instanceof SAPR3DatabaseMeta) {
        items.add(dbMeta.getName());
      }
    }
    wConnection.setItems(items.toArray(new String[items.size()]));
    if (input.getDatabaseMeta() == null && transMeta.nrDatabases() == 1) {
      wConnection.select(0);
    }
    wConnection.addModifyListener(lsConnectionMod);
    lastControl = wConnection;

    // Function
    //
    wlFunction = new Label(shell, SWT.RIGHT);
    wlFunction.setText(BaseMessages.getString(PKG, "SapInputDialog.Function.Label"));
    props.setLook(wlFunction);
    FormData fdlFunction = new FormData();
    fdlFunction.left = new FormAttachment(0, 0);
    fdlFunction.right = new FormAttachment(middle, -margin);
    fdlFunction.top = new FormAttachment(lastControl, margin);
    wlFunction.setLayoutData(fdlFunction);
    wbFunction = new Button(shell, SWT.PUSH);
    props.setLook(wbFunction);

    wbFunction.setText(BaseMessages.getString(PKG, "SapInputDialog.FindFunctionButton.Label"));
    FormData fdbFunction = new FormData();
    fdbFunction.right = new FormAttachment(100, 0);
    fdbFunction.top = new FormAttachment(lastControl, margin);
    wbFunction.setLayoutData(fdbFunction);
    wbFunction.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            getFunction();
          }
        });

    wFunction = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFunction);
    wFunction.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            function = new SAPFunction(((Text) e.widget).getText());
            input.setChanged();
          }
        });
    FormData fdFunction = new FormData();
    fdFunction.left = new FormAttachment(middle, 0);
    fdFunction.right = new FormAttachment(wbFunction, -margin);
    fdFunction.top = new FormAttachment(lastControl, margin);
    wFunction.setLayoutData(fdFunction);
    lastControl = wFunction;

    // The parameter input fields...
    //
    wlInput = new Label(shell, SWT.NONE);
    wlInput.setText(BaseMessages.getString(PKG, "SapInputDialog.Input.Label"));
    props.setLook(wlInput);
    FormData fdlInput = new FormData();
    fdlInput.left = new FormAttachment(0, 0);
    fdlInput.top = new FormAttachment(lastControl, margin);
    wlInput.setLayoutData(fdlInput);

    ColumnInfo[] ciKey =
        new ColumnInfo[] {
          new ColumnInfo(
              BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.Field"),
              ColumnInfo.COLUMN_TYPE_CCOMBO,
              new String[] {""},
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.SAPType"),
              ColumnInfo.COLUMN_TYPE_CCOMBO,
              SapType.getDescriptions()),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.TableOrStruct"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.SAPParameterName"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.TargetType"),
              ColumnInfo.COLUMN_TYPE_CCOMBO,
              ValueMeta.getTypes()),
        };
    inputFieldColumns.add(ciKey[0]);

    wInput =
        new TableView(
            transMeta,
            shell,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL,
            ciKey,
            input.getParameters().size(),
            lsMod,
            props);

    FormData fdInput = new FormData();
    fdInput.left = new FormAttachment(0, 0);
    fdInput.top = new FormAttachment(wlInput, margin);
    fdInput.right = new FormAttachment(100, 0);
    fdInput.bottom = new FormAttachment(40, 0);
    wInput.setLayoutData(fdInput);
    lastControl = wInput;

    // THE BUTTONS
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    // wPreview = new Button(shell, SWT.PUSH);
    // wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview"));
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "SapInputDialog.GetFields.Button"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    wAbout = new Button(shell, SWT.PUSH);
    wAbout.setText(BaseMessages.getString(PKG, "SapInputDialog.About.Button"));
    // Preview not possible without inputRowSets in BaseStep.getRow()
    // setButtonPositions(new Button[] { wOK, wPreview, wAbout , wGet, wCancel}, margin, null);
    setButtonPositions(new Button[] {wOK, wAbout, wGet, wCancel}, margin, null);

    // The output fields...
    //
    wlOutput = new Label(shell, SWT.NONE);
    wlOutput.setText(BaseMessages.getString(PKG, "SapInputDialog.Output.Label"));
    props.setLook(wlOutput);
    FormData fdlOutput = new FormData();
    fdlOutput.left = new FormAttachment(0, 0);
    fdlOutput.top = new FormAttachment(wInput, margin);
    wlOutput.setLayoutData(fdlOutput);

    ColumnInfo[] ciReturn =
        new ColumnInfo[] {
          new ColumnInfo(
              BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.SAPField"),
              ColumnInfo.COLUMN_TYPE_CCOMBO,
              new String[] {},
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.SAPType"),
              ColumnInfo.COLUMN_TYPE_CCOMBO,
              SapType.getDescriptions(),
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.TableOrStruct"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.NewName"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.TargetType"),
              ColumnInfo.COLUMN_TYPE_CCOMBO,
              ValueMeta.getTypes()),
        };
    outputFieldColumns.add(ciReturn[0]);

    wOutput =
        new TableView(
            transMeta,
            shell,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL,
            ciReturn,
            input.getOutputFields().size(),
            lsMod,
            props);

    FormData fdOutput = new FormData();
    fdOutput.left = new FormAttachment(0, 0);
    fdOutput.top = new FormAttachment(wlOutput, margin);
    fdOutput.right = new FormAttachment(100, 0);
    fdOutput.bottom = new FormAttachment(wOK, -8 * margin);
    wOutput.setLayoutData(fdOutput);
    lastControl = wOutput;

    this.wAscLink = new Link(this.shell, SWT.NONE);
    FormData fdAscLink = new FormData();
    fdAscLink.left = new FormAttachment(0, 0);
    fdAscLink.top = new FormAttachment(wOutput, margin);
    wAscLink.setLayoutData(fdAscLink);
    this.wAscLink.setText(BaseMessages.getString(PKG, "SapInputDialog.Provided.Info"));
    lastControl = wAscLink;

    // Add listeners
    lsOK =
        new Listener() {
          public void handleEvent(Event e) {
            ok();
          }
        };
    lsPreview =
        new Listener() {
          public void handleEvent(Event e) {
            preview();
          }
        };
    lsGet =
        new Listener() {
          public void handleEvent(Event e) {
            get();
          }
        };
    lsCancel =
        new Listener() {
          public void handleEvent(Event e) {
            cancel();
          }
        };
    Listener lsAbout =
        new Listener() {
          public void handleEvent(Event e) {
            about();
          }
        };

    wOK.addListener(SWT.Selection, lsOK);
    // wPreview.addListener(SWT.Selection, lsPreview);
    wGet.addListener(SWT.Selection, lsGet);
    wCancel.addListener(SWT.Selection, lsCancel);
    this.wAbout.addListener(SWT.Selection, lsAbout);

    this.wAscLink.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(final Event event) {
            Program.launch(event.text);
          }
        });

    lsDef =
        new SelectionAdapter() {
          public void widgetDefaultSelected(SelectionEvent e) {
            ok();
          }
        };

    wStepname.addSelectionListener(lsDef);
    wFunction.addSelectionListener(lsDef);

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

    getData();

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

    input.setChanged(backupChanged);

    setComboValues();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    return stepname;
  }
コード例 #2
0
ファイル: DBProcDialog.java プロジェクト: hoverzheng/kettle
  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();
          }
        };

    SelectionAdapter lsSelMod =
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            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, "DBProcDialog.Shell.Title")); // $NON-NLS-1$

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

    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "DBProcDialog.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);

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

    // ProcName line...
    // add button to get list of procedures on selected connection...
    wbProcName = new Button(shell, SWT.PUSH);
    wbProcName.setText(BaseMessages.getString(PKG, "DBProcDialog.Finding.Button")); // $NON-NLS-1$
    fdbProcName = new FormData();
    fdbProcName.right = new FormAttachment(100, 0);
    fdbProcName.top = new FormAttachment(wConnection, margin * 2);
    wbProcName.setLayoutData(fdbProcName);
    wbProcName.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            DatabaseMeta dbInfo = transMeta.findDatabase(wConnection.getText());
            if (dbInfo != null) {
              Database db = new Database(loggingObject, dbInfo);
              try {
                db.connect();
                String[] procs = db.getProcedures();
                if (procs != null && procs.length > 0) {
                  EnterSelectionDialog esd =
                      new EnterSelectionDialog(
                          shell,
                          procs,
                          BaseMessages.getString(PKG, "DBProcDialog.EnterSelection.DialogTitle"),
                          BaseMessages.getString(
                              PKG,
                              "DBProcDialog.EnterSelection.DialogMessage")); //$NON-NLS-1$
                                                                             // //$NON-NLS-2$
                  String proc = esd.open();
                  if (proc != null) {
                    wProcName.setText(proc);
                  }
                } else {
                  MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                  mb.setMessage(
                      BaseMessages.getString(
                          PKG, "DBProcDialog.NoProceduresFound.DialogMessage")); // $NON-NLS-1$
                  mb.setText(
                      BaseMessages.getString(
                          PKG, "DBProcDialog.NoProceduresFound.DialogTitle")); // $NON-NLS-1$
                  mb.open();
                }
              } catch (KettleDatabaseException dbe) {
                new ErrorDialog(
                    shell,
                    BaseMessages.getString(
                        PKG, "DBProcDialog.ErrorGettingProceduresList.DialogTitle"),
                    BaseMessages.getString(
                        PKG, "DBProcDialog.ErrorGettingProceduresList.DialogMessage"),
                    dbe); //$NON-NLS-1$ //$NON-NLS-2$
              } finally {
                db.disconnect();
              }
            }
          }
        });

    wlProcName = new Label(shell, SWT.RIGHT);
    wlProcName.setText(
        BaseMessages.getString(PKG, "DBProcDialog.ProcedureName.Label")); // $NON-NLS-1$
    props.setLook(wlProcName);
    fdlProcName = new FormData();
    fdlProcName.left = new FormAttachment(0, 0);
    fdlProcName.right = new FormAttachment(middle, -margin);
    fdlProcName.top = new FormAttachment(wConnection, margin * 2);
    wlProcName.setLayoutData(fdlProcName);

    wProcName = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wProcName);
    wProcName.addModifyListener(lsMod);
    fdProcName = new FormData();
    fdProcName.left = new FormAttachment(middle, 0);
    fdProcName.top = new FormAttachment(wConnection, margin * 2);
    fdProcName.right = new FormAttachment(wbProcName, -margin);
    wProcName.setLayoutData(fdProcName);

    // AutoCommit line
    wlAutoCommit = new Label(shell, SWT.RIGHT);
    wlAutoCommit.setText(BaseMessages.getString(PKG, "DBProcDialog.AutoCommit.Label"));
    wlAutoCommit.setToolTipText(BaseMessages.getString(PKG, "DBProcDialog.AutoCommit.Tooltip"));
    props.setLook(wlAutoCommit);
    fdlAutoCommit = new FormData();
    fdlAutoCommit.left = new FormAttachment(0, 0);
    fdlAutoCommit.top = new FormAttachment(wProcName, margin);
    fdlAutoCommit.right = new FormAttachment(middle, -margin);
    wlAutoCommit.setLayoutData(fdlAutoCommit);
    wAutoCommit = new Button(shell, SWT.CHECK);
    wAutoCommit.setToolTipText(BaseMessages.getString(PKG, "DBProcDialog.AutoCommit.Tooltip"));
    props.setLook(wAutoCommit);
    fdAutoCommit = new FormData();
    fdAutoCommit.left = new FormAttachment(middle, 0);
    fdAutoCommit.top = new FormAttachment(wProcName, margin);
    fdAutoCommit.right = new FormAttachment(100, 0);
    wAutoCommit.setLayoutData(fdAutoCommit);
    wAutoCommit.addSelectionListener(lsSelMod);

    // Result line...
    wlResult = new Label(shell, SWT.RIGHT);
    wlResult.setText(BaseMessages.getString(PKG, "DBProcDialog.Result.Label")); // $NON-NLS-1$
    props.setLook(wlResult);
    fdlResult = new FormData();
    fdlResult.left = new FormAttachment(0, 0);
    fdlResult.right = new FormAttachment(middle, -margin);
    fdlResult.top = new FormAttachment(wAutoCommit, margin * 2);
    wlResult.setLayoutData(fdlResult);
    wResult = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wResult);
    wResult.addModifyListener(lsMod);
    fdResult = new FormData();
    fdResult.left = new FormAttachment(middle, 0);
    fdResult.top = new FormAttachment(wAutoCommit, margin * 2);
    fdResult.right = new FormAttachment(100, 0);
    wResult.setLayoutData(fdResult);

    // ResultType line
    wlResultType = new Label(shell, SWT.RIGHT);
    wlResultType.setText(
        BaseMessages.getString(PKG, "DBProcDialog.ResultType.Label")); // $NON-NLS-1$
    props.setLook(wlResultType);
    fdlResultType = new FormData();
    fdlResultType.left = new FormAttachment(0, 0);
    fdlResultType.right = new FormAttachment(middle, -margin);
    fdlResultType.top = new FormAttachment(wResult, margin);
    wlResultType.setLayoutData(fdlResultType);
    wResultType = new CCombo(shell, SWT.BORDER | SWT.READ_ONLY);
    props.setLook(wResultType);
    String types[] = ValueMeta.getTypes();
    for (int x = 0; x < types.length; x++) wResultType.add(types[x]);
    wResultType.select(0);
    wResultType.addModifyListener(lsMod);
    fdResultType = new FormData();
    fdResultType.left = new FormAttachment(middle, 0);
    fdResultType.top = new FormAttachment(wResult, margin);
    fdResultType.right = new FormAttachment(100, 0);
    wResultType.setLayoutData(fdResultType);

    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "DBProcDialog.Parameters.Label")); // $NON-NLS-1$
    props.setLook(wlFields);
    fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wResultType, margin);
    wlFields.setLayoutData(fdlFields);

    final int FieldsCols = 3;
    final int FieldsRows = input.getArgument().length;

    colinf = new ColumnInfo[FieldsCols];
    colinf[0] =
        new ColumnInfo(
            BaseMessages.getString(PKG, "DBProcDialog.ColumnInfo.Name"),
            ColumnInfo.COLUMN_TYPE_CCOMBO,
            new String[] {""},
            false);
    colinf[1] =
        new ColumnInfo(
            BaseMessages.getString(PKG, "DBProcDialog.ColumnInfo.Direction"),
            ColumnInfo.COLUMN_TYPE_CCOMBO,
            new String[] {
              "IN", "OUT", "INOUT"
            }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    colinf[2] =
        new ColumnInfo(
            BaseMessages.getString(PKG, "DBProcDialog.ColumnInfo.Type"),
            ColumnInfo.COLUMN_TYPE_CCOMBO,
            ValueMeta.getTypes()); // $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(100, -50);
    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();

    // THE BUTTONS
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); // $NON-NLS-1$
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "DBProcDialog.GetFields.Button")); // $NON-NLS-1$
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); // $NON-NLS-1$

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

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

    lsResize =
        new Listener() {
          public void handleEvent(Event event) {
            Point size = shell.getSize();
            wFields.setSize(size.x - 10, size.y - 50);
            wFields.table.setSize(size.x - 10, size.y - 50);
            wFields.redraw();
          }
        };
    shell.addListener(SWT.Resize, lsResize);

    // 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;
  }
コード例 #3
0
  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();
          }
        };
    backupChanged = input.hasChanged();

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

    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "SASInputDialog.Dialog.Title"));

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

    // 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);
    Control lastControl = wStepname;

    // Which field do we read from?
    //
    Label wlAccField = new Label(shell, SWT.RIGHT);
    wlAccField.setText(BaseMessages.getString(PKG, "SASInputDialog.AcceptField.Label"));
    props.setLook(wlAccField);
    FormData fdlAccField = new FormData();
    fdlAccField.top = new FormAttachment(lastControl, margin);
    fdlAccField.left = new FormAttachment(0, 0);
    fdlAccField.right = new FormAttachment(middle, -margin);
    wlAccField.setLayoutData(fdlAccField);
    wAccField = new CCombo(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wAccField.setToolTipText(BaseMessages.getString(PKG, "SASInputDialog.AcceptField.Tooltip"));
    props.setLook(wAccField);
    FormData fdAccField = new FormData();
    fdAccField.top = new FormAttachment(lastControl, margin);
    fdAccField.left = new FormAttachment(middle, 0);
    fdAccField.right = new FormAttachment(100, 0);
    wAccField.setLayoutData(fdAccField);
    lastControl = wAccField;

    // Fill in the source fields...
    //
    try {
      RowMetaInterface fields = transMeta.getPrevStepFields(stepMeta);
      wAccField.setItems(fields.getFieldNames());
    } catch (Exception e) {
      LogChannel.GENERAL.logError("Couldn't get input fields for step '" + stepMeta + "'", e);
    }

    // Some buttons
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wOK.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            ok();
          }
        });
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "System.Button.GetFields"));
    wGet.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            get();
          }
        });
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    wCancel.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            cancel();
          }
        });

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

    Label wlFields = new Label(shell, SWT.LEFT);
    wlFields.setText(BaseMessages.getString(PKG, "SASInputDialog.Fields.Label"));
    props.setLook(wlFields);
    FormData fdlFields = new FormData();
    fdlFields.top = new FormAttachment(lastControl, margin);
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.right = new FormAttachment(100, 0);
    wlFields.setLayoutData(fdlFields);
    lastControl = wlFields;

    // Fields
    ColumnInfo[] colinf =
        new ColumnInfo[] {
          new ColumnInfo(
              BaseMessages.getString(PKG, "SASInputDialog.OutputFieldColumn.Name"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SASInputDialog.OutputFieldColumn.Rename"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SASInputDialog.OutputFieldColumn.Type"),
              ColumnInfo.COLUMN_TYPE_CCOMBO,
              ValueMeta.getTypes(),
              true),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SASInputDialog.OutputFieldColumn.Mask"),
              ColumnInfo.COLUMN_TYPE_FORMAT,
              2),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SASInputDialog.OutputFieldColumn.Length"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SASInputDialog.OutputFieldColumn.Precision"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SASInputDialog.OutputFieldColumn.Decimal"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SASInputDialog.OutputFieldColumn.Group"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "SASInputDialog.OutputFieldColumn.TrimType"),
              ColumnInfo.COLUMN_TYPE_CCOMBO,
              ValueMeta.trimTypeDesc),
        };

    colinf[3].setComboValuesSelectionListener(
        new ComboValuesSelectionListener() {

          public String[] getComboValues(TableItem tableItem, int rowNr, int colNr) {
            String[] comboValues = new String[] {};
            int type = ValueMeta.getType(tableItem.getText(colNr - 1));
            switch (type) {
              case ValueMetaInterface.TYPE_DATE:
                comboValues = Const.getDateFormats();
                break;
              case ValueMetaInterface.TYPE_INTEGER:
              case ValueMetaInterface.TYPE_BIGNUMBER:
              case ValueMetaInterface.TYPE_NUMBER:
                comboValues = Const.getNumberFormats();
                break;
              default:
                break;
            }
            return comboValues;
          }
        });

    wFields =
        new TableView(transMeta, shell, SWT.FULL_SELECTION | SWT.MULTI, colinf, 1, lsMod, props);

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

    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();
          }
        });

    getData();
    input.setChanged(changed);

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

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