コード例 #1
0
  /** qzhang Comment method "runPreviewCode". */
  public Process runPreviewCode() {
    getProcess();
    if (jobContextManager == null) {
      // proc.getContextManager().setListContext(component.getProcess().getContextManager().getListContext());
      proc.getContextManager()
          .setDefaultContext(component.getProcess().getContextManager().getDefaultContext());
    } else {
      // proc.getContextManager().setListContext(jobContextManager.getListContext());
      proc.getContextManager().setDefaultContext(jobContextManager.getDefaultContext());
    }
    // IContext context2 = new org.talend.core.model.context.JobContext(PREVIEW);
    // if (UIManager.isJavaProject()) {
    // List<IContextParameter> params = new ArrayList<IContextParameter>();
    // JobContextParameter contextParameter = new JobContextParameter();
    // contextParameter.setContext(context2);
    // contextParameter.setName(PREVIEW);
    // contextParameter.setValue(PREVIEW);
    // contextParameter.setType("String");
    // params.add(contextParameter);
    // context2.setContextParameterList(params);
    // }

    // generate context files.
    IProcessor contextProcessor = ProcessorUtilities.getProcessor(proc, null);
    contextProcessor.setContext(proc.getContextManager().getDefaultContext());
    try {
      contextProcessor.cleanBeforeGenerate(TalendProcessOptionConstants.CLEAN_CONTEXTS);
      contextProcessor.generateContextCode();
    } catch (ProcessorException pe) {
      ExceptionHandler.process(pe);
    }

    IProcessor processor =
        ProcessorUtilities.getProcessor(proc, null, proc.getContextManager().getDefaultContext());
    try {
      return processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
    } catch (Exception e) {
      ExceptionHandler.process(e);
      return null;
    }
  }
コード例 #2
0
  /**
   * yzhang Comment method "run".
   *
   * @param refresh
   * @param number
   * @return
   */
  public List<List<String>> run(final Button refresh, String number) {
    this.number = number;
    results.clear();
    IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
    try {
      progressService.runInUI(
          PlatformUI.getWorkbench().getProgressService(),
          new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) {
              monitor.beginTask(
                  Messages.getString("RowGenPreivewCodeMain.Process.Generate"),
                  IProgressMonitor.UNKNOWN); // $NON-NLS-1$
              try {
                try {
                  process = runPreviewCode();
                  if (process == null) {
                    return;
                  }

                  StringBuffer out = new StringBuffer();
                  StringBuffer err = new StringBuffer();

                  createResultThread(process.getErrorStream(), err).start();
                  createResultThread(process.getInputStream(), out).start();

                  process.waitFor();

                  if (out.length() > 0) {
                    convert(out.toString());
                  }
                  if (err.length() > 0) {
                    String mainMsg =
                        Messages.getString("RowGenPreivewCodeMain.PerlRun.Error"); // $NON-NLS-1$
                    new ErrorDialogWidthDetailArea(
                        Display.getCurrent().getActiveShell(),
                        PluginUtils.PLUGIN_ID,
                        mainMsg,
                        Messages.getString(
                            "RowGenProcessMain.checkParameter", err.toString())); // $NON-NLS-1$
                  }
                } catch (Exception e) {
                  ExceptionHandler.process(e);
                  kill();
                }
              } finally {
                monitor.done();
                refresh.setText(
                    Messages.getString("RowGenPreivewCodeMain.PreviewBtn.Text")); // $NON-NLS-1$
              }
            }
          },
          null);

    } catch (Exception ex) {
      ExceptionHandler.process(ex);
    } finally {
      proc.reconnection();
    }
    return results;
  }