public PreviewRowsDialog(
      Shell parent,
      VariableSpace space,
      int style,
      String stepName,
      RowMetaInterface rowMeta,
      List<Object[]> rowBuffer,
      String loggingText) {
    this.stepname = stepName;
    this.buffer = rowBuffer;
    this.loggingText = loggingText;
    this.rowMeta = rowMeta;
    this.variables = space;
    this.parentShell = parent;
    this.style = (style != SWT.None) ? style : this.style;
    this.dialogClosedListeners = new ArrayList<DialogClosedListener>();

    props = PropsUI.getInstance();
    bounds = null;
    hscroll = -1;
    vscroll = -1;
    title = null;
    message = null;

    this.log = new LogChannel("Row Preview");
  }
  public SelectDirectoryDialog(Shell parent, int style, Repository rep) {
    super(parent, style);
    this.props = PropsUI.getInstance();
    this.rep = rep;

    selection = null;

    readOnly = rep.getSecurityProvider().isReadOnly();
  }
  public CopyTableWizardPage1(String arg, java.util.List<DatabaseMeta> databases) {
    super(arg);
    this.props = PropsUI.getInstance();
    this.databases = databases;

    setTitle(BaseMessages.getString(PKG, "CopyTableWizardPage1.Dialog.Title"));
    setDescription(BaseMessages.getString(PKG, "CopyTableWizardPage1.Dialog.Description"));

    setPageComplete(false);
  }
 public SlaveServerDialog(
     Shell par, SlaveServer slaveServer, Collection<SlaveServer> existingServers) {
   super(par, SWT.NONE);
   this.slaveServer = (SlaveServer) slaveServer.clone();
   this.slaveServer.shareVariablesWith(slaveServer);
   this.originalServer = slaveServer;
   this.existingServers = existingServers;
   props = PropsUI.getInstance();
   ok = false;
 }
 public EnterPreviewRowsDialog(
     Shell parent,
     int style,
     java.util.List<String> stepNames,
     java.util.List<RowMetaInterface> rowMetas,
     java.util.List<java.util.List<Object[]>> rowBuffers) {
   super(parent, style);
   this.stepNames = stepNames;
   this.rowDatas = rowBuffers;
   this.rowMetas = rowMetas;
   props = PropsUI.getInstance();
 }
  public StepFieldsDialog(
      Shell parent, VariableSpace space, int style, String stepname, RowMetaInterface input) {
    super(parent, style);
    this.stepname = stepname;
    this.input = input;
    this.variables = space;
    props = PropsUI.getInstance();

    shellText = BaseMessages.getString(PKG, "StepFieldsDialog.Title");
    originText = BaseMessages.getString(PKG, "StepFieldsDialog.Name.Label");
    showEditButton = true;
  }
 public SapFunctionBrowser(
     Shell parent,
     VariableSpace space,
     int style,
     DatabaseMeta sapConnection,
     String searchString) {
   super(parent, style);
   this.space = space;
   this.sapConnection = sapConnection;
   this.searchString = searchString;
   props = PropsUI.getInstance();
   functionList = new ArrayList<SAPFunction>(); // Empty by default...
 }
  /**
   * Create a new dialog allow someone to pick one value out of a list of values
   *
   * @param parent the parent shell.
   * @param choices The available list of options
   * @param shellText The shell text
   * @param message the message to display as extra information about the possible choices
   */
  public EnterSelectionDialog(Shell parent, String[] choices, String shellText, String message) {
    super(parent, SWT.NONE);

    this.choices = choices;
    this.shellText = shellText;
    this.lineText = message;

    props = PropsUI.getInstance();
    selection = null;
    viewOnly = false;
    modal = true;
    selectedNrs = new int[] {};
    multi = false;
    fixed = false;
    quickSearch = true;
  }
Example #9
0
  @Override
  public void hide() {

    if (closing
        || dialog.getMainArea().isDisposed()
        || getParentShell(getParent()).isDisposed()
        || (getParent() instanceof SwtDialog && ((SwtDialog) getParent()).isDisposing())) {
      return;
    }

    // Save the window location & size in the Kettle world...
    //
    WindowProperty windowProperty = new WindowProperty(getShell());
    PropsUI.getInstance().setScreen(windowProperty);

    super.hide();
  }
  public ConfigurationDialog(
      Shell parent, ExecutionConfiguration configuration, AbstractMeta meta) {
    super(parent);
    this.parent = parent;
    this.configuration = configuration;
    this.abstractMeta = meta;
    initCheckboxFlag();

    // Fill the parameters, maybe do this in another place?
    Map<String, String> params = configuration.getParams();
    params.clear();
    String[] paramNames = meta.listParameters();
    for (String name : paramNames) {
      params.put(name, "");
    }

    props = PropsUI.getInstance();
  }
  public void executeTransformation(
      final TransMeta transMeta,
      final boolean local,
      final boolean remote,
      final boolean cluster,
      final boolean preview,
      final boolean debug,
      final Date replayDate,
      final boolean safe)
      throws KettleException {

    if (transMeta == null) {
      return;
    }

    // See if we need to ask for debugging information...
    //
    TransDebugMeta transDebugMeta = null;
    TransExecutionConfiguration executionConfiguration = null;

    if (preview) {
      executionConfiguration = spoon.getTransPreviewExecutionConfiguration();
    } else if (debug) {
      executionConfiguration = spoon.getTransDebugExecutionConfiguration();
    } else {
      executionConfiguration = spoon.getTransExecutionConfiguration();
    }

    if (debug) {
      // See if we have debugging information stored somewhere?
      //
      transDebugMeta = transDebugMetaMap.get(transMeta);
      if (transDebugMeta == null) {
        transDebugMeta = new TransDebugMeta(transMeta);
        transDebugMetaMap.put(transMeta, transDebugMeta);
      }

      // Set the default number of rows to retrieve on all selected steps...
      //
      StepMeta[] selectedSteps = transMeta.getSelectedSteps();
      if (selectedSteps != null && selectedSteps.length > 0) {
        transDebugMeta.getStepDebugMetaMap().clear();
        for (StepMeta stepMeta : transMeta.getSelectedSteps()) {
          StepDebugMeta stepDebugMeta = new StepDebugMeta(stepMeta);
          stepDebugMeta.setRowCount(PropsUI.getInstance().getDefaultPreviewSize());
          stepDebugMeta.setPausingOnBreakPoint(true);
          stepDebugMeta.setReadingFirstRows(false);
          transDebugMeta.getStepDebugMetaMap().put(stepMeta, stepDebugMeta);
        }
      }

    } else if (preview) {
      // See if we have preview information stored somewhere?
      //
      transDebugMeta = transPreviewMetaMap.get(transMeta);
      if (transDebugMeta == null) {
        transDebugMeta = new TransDebugMeta(transMeta);

        transPreviewMetaMap.put(transMeta, transDebugMeta);
      }

      // Set the default number of preview rows on all selected steps...
      //
      StepMeta[] selectedSteps = transMeta.getSelectedSteps();
      if (selectedSteps != null && selectedSteps.length > 0) {
        transDebugMeta.getStepDebugMetaMap().clear();
        for (StepMeta stepMeta : transMeta.getSelectedSteps()) {
          StepDebugMeta stepDebugMeta = new StepDebugMeta(stepMeta);
          stepDebugMeta.setRowCount(PropsUI.getInstance().getDefaultPreviewSize());
          stepDebugMeta.setPausingOnBreakPoint(false);
          stepDebugMeta.setReadingFirstRows(true);
          transDebugMeta.getStepDebugMetaMap().put(stepMeta, stepDebugMeta);
        }
      }
    }

    executionConfiguration.setRepository(spoon.rep);
    executionConfiguration.setSafeModeEnabled(safe);

    int debugAnswer = TransDebugDialog.DEBUG_CONFIG;

    if (debug || preview) {
      transDebugMeta.getTransMeta().setRepository(spoon.rep); // pass repository for mappings
      TransDebugDialog transDebugDialog = new TransDebugDialog(spoon.getShell(), transDebugMeta);
      debugAnswer = transDebugDialog.open();
      if (debugAnswer != TransDebugDialog.DEBUG_CANCEL) {
        executionConfiguration.setExecutingLocally(true);
        executionConfiguration.setExecutingRemotely(false);
        executionConfiguration.setExecutingClustered(false);
      } else {
        // If we cancel the debug dialog, we don't go further with the execution either.
        //
        return;
      }
    } else {
      if (transMeta.findFirstUsedClusterSchema() != null) {
        executionConfiguration.setExecutingLocally(false);
        executionConfiguration.setExecutingRemotely(false);
        executionConfiguration.setExecutingClustered(true);
      } else {
        executionConfiguration.setExecutingLocally(true);
        executionConfiguration.setExecutingRemotely(false);
        executionConfiguration.setExecutingClustered(false);
      }
    }

    Object data[] = spoon.variables.getData();
    String fields[] = spoon.variables.getRowMeta().getFieldNames();
    Map<String, String> variableMap = new HashMap<String, String>();
    variableMap.putAll(executionConfiguration.getVariables()); // the default
    for (int idx = 0; idx < fields.length; idx++) {
      String value = executionConfiguration.getVariables().get(fields[idx]);
      if (Const.isEmpty(value)) value = data[idx].toString();
      variableMap.put(fields[idx], value);
    }

    executionConfiguration.setVariables(variableMap);
    executionConfiguration.getUsedVariables(transMeta);
    executionConfiguration.getUsedArguments(transMeta, spoon.getArguments());
    executionConfiguration.setReplayDate(replayDate);

    executionConfiguration.setLogLevel(spoon.getLog().getLogLevel());

    boolean execConfigAnswer = true;

    if (debugAnswer == TransDebugDialog.DEBUG_CONFIG && replayDate == null) {
      TransExecutionConfigurationDialog dialog =
          new TransExecutionConfigurationDialog(
              spoon.getShell(), executionConfiguration, transMeta);
      execConfigAnswer = dialog.open();
    }

    if (execConfigAnswer) {

      // Verify if there is at least one step specified to debug or preview...
      //
      if (debug || preview) {
        if (transDebugMeta.getNrOfUsedSteps() == 0) {
          MessageBox box = new MessageBox(spoon.getShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO);
          box.setText(Messages.getString("Spoon.Dialog.Warning.NoPreviewOrDebugSteps.Title"));
          box.setMessage(Messages.getString("Spoon.Dialog.Warning.NoPreviewOrDebugSteps.Message"));
          int answer = box.open();
          if (answer != SWT.YES) {
            return;
          }
        }
      }

      // addTransLog(transMeta, executionConfiguration.isExecutingLocally());
      // TransLog transLog = spoon.getActiveTransLog();
      TransGraph activeTransGraph = spoon.getActiveTransGraph();

      // Is this a local execution?
      //
      if (executionConfiguration.isExecutingLocally()) {
        if (debug || preview) {
          activeTransGraph.debug(executionConfiguration, transDebugMeta);
        } else {
          activeTransGraph.start(executionConfiguration);
        }

        // Are we executing remotely?
        //
      } else if (executionConfiguration.isExecutingRemotely()) {
        if (executionConfiguration.getRemoteServer() != null) {
          Trans.sendToSlaveServer(transMeta, executionConfiguration, spoon.rep);
          monitorRemoteTrans(transMeta, executionConfiguration.getRemoteServer());
          spoon.delegates.slaves.addSpoonSlave(executionConfiguration.getRemoteServer());

        } else {
          MessageBox mb = new MessageBox(spoon.getShell(), SWT.OK | SWT.ICON_INFORMATION);
          mb.setMessage(Messages.getString("Spoon.Dialog.NoRemoteServerSpecified.Message"));
          mb.setText(Messages.getString("Spoon.Dialog.NoRemoteServerSpecified.Title"));
          mb.open();
        }

        // Are we executing clustered?
        //
      } else if (executionConfiguration.isExecutingClustered()) {
        splitTrans(transMeta, executionConfiguration);
      }
    }
  }
  /**
   * Create the composite.
   *
   * @param parent
   * @param style
   */
  public ArgumentsDialog(
      final Shell parent, ExecutionConfiguration configuration, AbstractMeta abstractMeta) {
    super(parent);
    this.configuration = configuration;

    display = parent.getDisplay();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.MIN | SWT.APPLICATION_MODAL);
    props = PropsUI.getInstance();
    props.setLook(shell);
    shell.setImage(parent.getImage());
    shell.setLayout(new FormLayout());
    shell.setText(BaseMessages.getString(PKG, "ArgumentsDialog.Arguments.Label"));

    ColumnInfo[] cArguments = {
      new ColumnInfo(
          BaseMessages.getString(PKG, "ArgumentsDialog.ArgumentsColumn.Argument"),
          ColumnInfo.COLUMN_TYPE_TEXT,
          false,
          true,
          180), // Argument name
      new ColumnInfo(
          BaseMessages.getString(PKG, "ArgumentsDialog.ArgumentsColumn.Value"),
          ColumnInfo.COLUMN_TYPE_TEXT,
          false,
          false,
          172), // Actual value
    };

    int nrArguments =
        configuration.getArguments() != null ? configuration.getArguments().size() : 0;

    wArguments =
        new TableView(
            abstractMeta,
            shell,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI,
            cArguments,
            nrArguments,
            false,
            null,
            props,
            false);

    FormData fd_argumentsTable = new FormData();
    fd_argumentsTable.top = new FormAttachment(0, 15);
    fd_argumentsTable.left = new FormAttachment(0, 15);
    fd_argumentsTable.bottom = new FormAttachment(0, 221);
    fd_argumentsTable.right = new FormAttachment(0, 371);
    wArguments.setLayoutData(fd_argumentsTable);

    Label separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    FormData fd_separator = new FormData();
    fd_separator.top = new FormAttachment(wArguments, 15);
    fd_separator.right = new FormAttachment(wArguments, 0, SWT.RIGHT);
    fd_separator.left = new FormAttachment(0, 15);
    separator.setLayoutData(fd_separator);

    Button okButton = new Button(shell, SWT.NONE);
    okButton.setText("OK");
    FormData fd_okButton = new FormData();
    fd_okButton.left = new FormAttachment(0, 269);
    okButton.setLayoutData(fd_okButton);
    okButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            ok();
          }
        });

    Button cancelButton = new Button(shell, SWT.NONE);
    fd_okButton.top = new FormAttachment(cancelButton, 0, SWT.TOP);
    fd_okButton.right = new FormAttachment(cancelButton, -4);
    cancelButton.setText("Cancel");
    FormData fd_cancelButton = new FormData();
    fd_cancelButton.top = new FormAttachment(separator, 13);
    fd_cancelButton.right = new FormAttachment(wArguments, 0, SWT.RIGHT);
    cancelButton.setLayoutData(fd_cancelButton);
    cancelButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            dispose();
          }
        });

    Button btnHelp = new Button(shell, SWT.NONE);
    btnHelp.setImage(GUIResource.getInstance().getImageHelpWeb());
    btnHelp.setText(BaseMessages.getString(PKG, "System.Button.Help"));
    btnHelp.setToolTipText(BaseMessages.getString(PKG, "System.Tooltip.Help"));
    FormData fd_btnHelp = new FormData();
    fd_btnHelp.top = new FormAttachment(separator, 13);
    fd_btnHelp.left = new FormAttachment(separator, 0, SWT.LEFT);
    btnHelp.setLayoutData(fd_btnHelp);
    btnHelp.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent evt) {
            String docUrl = BaseMessages.getString(Spoon.class, "Spoon.ArgumentsDialog.Help");
            String docTitle = BaseMessages.getString(PKG, "ArgumentsDialog.docTitle");
            String docHeader = BaseMessages.getString(PKG, "ArgumentsDialog.docHeader");
            HelpUtils.openHelpDialog(parent.getShell(), docTitle, docUrl, docHeader);
          }
        });

    shell.setSize(394, 319);
    getArgumentsData();
    shell.open();

    Rectangle shellBounds = getParent().getBounds();
    Point dialogSize = shell.getSize();

    shell.setLocation(
        shellBounds.x + (shellBounds.width - dialogSize.x) / 2,
        shellBounds.y + (shellBounds.height - dialogSize.y) / 2);

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
  }
/** Label, numeric text input and drop down time unit selector */
public class LabelTimeComposite extends Composite {
  private static final PropsUI props = PropsUI.getInstance();

  private Label wLabel;
  private Text wText;
  private CCombo wTimeUnit;

  private String lastValidValue = "";

  public LabelTimeComposite(Composite composite, String labelText, String toolTipText) {
    super(composite, SWT.NONE);
    props.setLook(this);

    int middle = props.getMiddlePct();
    int threeQuarters = (middle + 100) / 2;
    int margin = Const.MARGIN;

    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = 0;
    formLayout.marginHeight = 0;
    formLayout.marginTop = 0;
    formLayout.marginBottom = 0;

    this.setLayout(formLayout);

    wText = new Text(this, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    FormData fdText = new FormData();
    fdText.left = new FormAttachment(middle, margin);
    fdText.right = new FormAttachment(threeQuarters, 0);
    wText.setLayoutData(fdText);
    wText.setToolTipText(toolTipText);

    wTimeUnit = new CCombo(this, SWT.SINGLE | SWT.DROP_DOWN | SWT.BORDER | SWT.LEFT);
    FormData fdCombo = new FormData();
    fdCombo.left = new FormAttachment(threeQuarters, margin);
    fdCombo.right = new FormAttachment(100, 0);
    wTimeUnit.setEditable(false);
    wTimeUnit.setLayoutData(fdCombo);
    wTimeUnit.setItems(getTimeUnits());
    wTimeUnit.setToolTipText(toolTipText);

    wLabel = new Label(this, SWT.RIGHT);
    props.setLook(wLabel);
    wLabel.setText(labelText);
    FormData fdLabel = new FormData();
    fdLabel.left = new FormAttachment(0, 0);
    fdLabel.right = new FormAttachment(middle, 0);
    fdLabel.top = new FormAttachment(wText, 0, SWT.CENTER);
    wLabel.setLayoutData(fdLabel);
    wLabel.setToolTipText(toolTipText);

    wText.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            if (!StringUtils.isNumeric(wText.getText())) {
              wText.setText(lastValidValue);
            } else lastValidValue = wText.getText();
          }
        });
  }

  private String[] getTimeUnits() {
    ArrayList<String> timeUnits = new ArrayList<String>();
    for (TimeUnit timeUnit : TimeUnit.values()) {
      timeUnits.add(timeUnit.toString());
    }
    return timeUnits.toArray(new String[timeUnits.size()]);
  }

  public TimeUnit getTimeUnit() {
    return TimeUnit.valueOf(wTimeUnit.getItem(wTimeUnit.getSelectionIndex()));
  }

  public void setTimeUnit(TimeUnit tu) {
    for (int i = 0; i < wTimeUnit.getItemCount(); i++) {
      if (tu.toString().equals(wTimeUnit.getItem(i))) {
        wTimeUnit.select(i);
        break;
      }
    }
  }

  public void addModifyListener(ModifyListener lsMod) {
    wText.addModifyListener(lsMod);
  }

  public void addSelectionListener(SelectionAdapter lsDef) {
    wText.addSelectionListener(lsDef);
  }

  public void setText(String name) {
    wText.setText(name);
  }

  public String getText() {
    return wText.getText();
  }

  public void setEchoChar(char c) {
    wText.setEchoChar(c);
  }

  public void setEnabled(boolean flag) {
    wText.setEnabled(flag);
    wLabel.setEnabled(flag);
  }

  public boolean setFocus() {
    return wText.setFocus();
  }

  public void addTraverseListener(TraverseListener tl) {
    wText.addTraverseListener(tl);
  }

  public Text getTextWidget() {
    return wText;
  }

  public Label getLabelWidget() {
    return wLabel;
  }
}
  public String open() {
    this.props = PropsUI.getInstance();
    Display display = shellParent.getDisplay();
    int margin = Const.MARGIN;

    shell = new Shell(shellParent, SWT.DIALOG_TRIM | SWT.CLOSE | SWT.ICON | SWT.APPLICATION_MODAL);

    props.setLook(shell);
    shell.setImage(GUIResource.getInstance().getImageSpoon());

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

    shell.setText(BaseMessages.getString(PKG, "MissingTransDialog.MissingPlugins"));
    shell.setLayout(formLayout);

    Label image = new Label(shell, SWT.NONE);
    props.setLook(image);
    Image icon = display.getSystemImage(SWT.ICON_QUESTION);
    image.setImage(icon);
    FormData imageData = new FormData();
    imageData.left = new FormAttachment(0, 5);
    imageData.right = new FormAttachment(11, 0);
    imageData.top = new FormAttachment(0, 10);
    image.setLayoutData(imageData);

    Label error = new Label(shell, SWT.WRAP);
    props.setLook(error);
    error.setText(getErrorMessage(missingTrans, mode));
    FormData errorData = new FormData();
    errorData.left = new FormAttachment(image, 5);
    errorData.right = new FormAttachment(100, -5);
    errorData.top = new FormAttachment(0, 10);
    error.setLayoutData(errorData);

    Label separator = new Label(shell, SWT.WRAP);
    props.setLook(separator);
    FormData separatorData = new FormData();
    separatorData.top = new FormAttachment(error, 10);
    separator.setLayoutData(separatorData);

    Button closeButton = new Button(shell, SWT.PUSH);
    props.setLook(closeButton);
    FormData fdClose = new FormData();
    fdClose.right = new FormAttachment(98);
    fdClose.top = new FormAttachment(separator);
    closeButton.setLayoutData(fdClose);
    closeButton.setText(BaseMessages.getString(PKG, "MissingTransDialog.Close"));
    closeButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            shell.dispose();
            stepResult = null;
          }
        });

    FormData fdSearch = new FormData();
    if (this.mode == MISSING_TRANS_STEPS) {
      Button openButton = new Button(shell, SWT.PUSH);
      props.setLook(openButton);
      FormData fdOpen = new FormData();
      fdOpen.right = new FormAttachment(closeButton, -5);
      fdOpen.bottom = new FormAttachment(closeButton, 0, SWT.BOTTOM);
      openButton.setLayoutData(fdOpen);
      openButton.setText(BaseMessages.getString(PKG, "MissingTransDialog.OpenFile"));
      openButton.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
              shell.dispose();
              stepResult = stepname;
            }
          });
      fdSearch.right = new FormAttachment(openButton, -5);
      fdSearch.bottom = new FormAttachment(openButton, 0, SWT.BOTTOM);
    } else {
      fdSearch.right = new FormAttachment(closeButton, -5);
      fdSearch.bottom = new FormAttachment(closeButton, 0, SWT.BOTTOM);
    }

    Button searchButton = new Button(shell, SWT.PUSH);
    props.setLook(searchButton);
    searchButton.setText(BaseMessages.getString(PKG, "MissingTransDialog.SearchMarketplace"));
    searchButton.setLayoutData(fdSearch);
    searchButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            try {
              shell.dispose();
              Spoon.getInstance().openMarketplace();
            } catch (Exception ex) {
              ex.printStackTrace();
            }
          }
        });

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