Ejemplo n.º 1
0
 private void handleConvert() {
   try {
     // remove listeners of Info section before we convert.  If we don't
     // we may get a model changed event while disposing the page.  Bug 156414
     fInfoSection.removeListeners();
     PDEFormEditor editor = getPDEEditor();
     IPluginModelBase model = (IPluginModelBase) editor.getAggregateModel();
     IRunnableWithProgress op = new CreateManifestOperation(model);
     IProgressService service = PlatformUI.getWorkbench().getProgressService();
     editor.doSave(null);
     service.runInUI(service, op, PDEPlugin.getWorkspace().getRoot());
     updateBuildProperties();
     editor.doSave(null);
   } catch (InvocationTargetException e) {
     MessageDialog.openError(
         PDEPlugin.getActiveWorkbenchShell(),
         PDEUIMessages.OverviewPage_error,
         e.getCause().getMessage());
     // if convert failed and this OverviewPage hasn't been removed from the editor, reattach
     // listeners
     if (!fDisposed) fInfoSection.addListeners();
   } catch (InterruptedException e) {
     // if convert failed and this OverviewPage hasn't been removed from the editor, reattach
     // listeners
     if (!fDisposed) fInfoSection.addListeners();
   }
 }
  /**
   * 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;
  }
  /**
   * Note: This method is for internal use only. Clients should not call this method.
   *
   * @param cu The compilation unit to process
   */
  public void run(ICompilationUnit cu) {
    if (!ElementValidator.check(
        cu, getShell(), ActionMessages.OrganizeImportsAction_error_title, fEditor != null)) return;
    if (!ActionUtil.isProcessable(getShell(), cu)) return;

    IEditingSupport helper = createViewerHelper();
    try {
      CodeGenerationSettings settings =
          JavaPreferencesSettings.getCodeGenerationSettings(cu.getJavaProject());

      if (fEditor == null && EditorUtility.isOpenInEditor(cu) == null) {
        IEditorPart editor = EditorUtility.openInEditor(cu);
        if (editor instanceof JavaEditor) {
          fEditor = (JavaEditor) editor;
        }
      }

      CompilationUnit astRoot =
          JavaPlugin.getDefault().getASTProvider().getAST(cu, ASTProvider.WAIT_ACTIVE_ONLY, null);

      AJOrganizeImportsOperation op =
          new AJOrganizeImportsOperation(
              cu,
              astRoot,
              settings.importIgnoreLowercase,
              !cu.isWorkingCopy(),
              true,
              createChooseImportQuery());

      IRewriteTarget target = null;
      if (fEditor != null) {
        target = (IRewriteTarget) fEditor.getAdapter(IRewriteTarget.class);
        if (target != null) {
          target.beginCompoundChange();
        }
      }

      IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
      IRunnableContext context = getSite().getWorkbenchWindow();
      if (context == null) {
        context = progressService;
      }
      try {
        registerHelper(helper);
        progressService.runInUI(
            context, new WorkbenchRunnableAdapter(op, op.getScheduleRule()), op.getScheduleRule());
        IProblem parseError = op.getParseError();
        if (parseError != null) {
          String message =
              Messages.format(
                  ActionMessages.OrganizeImportsAction_single_error_parse, parseError.getMessage());
          MessageDialog.openInformation(
              getShell(), ActionMessages.OrganizeImportsAction_error_title, message);
          if (fEditor != null && parseError.getSourceStart() != -1) {
            fEditor.selectAndReveal(
                parseError.getSourceStart(),
                parseError.getSourceEnd() - parseError.getSourceStart() + 1);
          }
        } else {
          if (fEditor != null) {
            setStatusBarMessage(getOrganizeInfo(op));
          }
        }
      } catch (InvocationTargetException e) {
        ExceptionHandler.handle(
            e,
            getShell(),
            ActionMessages.OrganizeImportsAction_error_title,
            ActionMessages.OrganizeImportsAction_error_message);
      } catch (InterruptedException e) {
      } finally {
        deregisterHelper(helper);
        if (target != null) {
          target.endCompoundChange();
        }
      }
    } catch (CoreException e) {
      ExceptionHandler.handle(
          e,
          getShell(),
          ActionMessages.OrganizeImportsAction_error_title,
          ActionMessages.OrganizeImportsAction_error_message);
    }
  }
  /** Print the bill(s) */
  public Result<Rechnung> doOutput(
      final TYPE type, final Collection<Rechnung> rnn, Properties props) {
    IWorkbenchPage rnPage;
    final Result<Rechnung> result = new Result<Rechnung>(); // =new
    // Result<Rechnung>(Log.ERRORS,99,"Not
    // yet implemented",null,true);
    rnPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
    final Result<Rechnung> res = new Result<Rechnung>();

    try {
      final RnPrintView rnp = (RnPrintView) rnPage.showView(RnPrintView.ID);
      progressService.runInUI(
          PlatformUI.getWorkbench().getProgressService(),
          new IRunnableWithProgress() {
            public void run(final IProgressMonitor monitor) {
              monitor.beginTask("Drucke Rechnungen", rnn.size() * 10);
              int errors = 0;
              for (Rechnung rn : rnn) {
                try {
                  result.add(rnp.doPrint(rn));
                  monitor.worked(10);
                  if (!result.isOK()) {
                    String errms = "Rechnung " + rn.getNr() + "konnte nicht gedruckt werden";
                    res.add(Result.SEVERITY.ERROR, 1, errms, rn, true);
                    errors++;
                    continue;
                  }
                  int status_vorher = rn.getStatus();
                  if ((status_vorher == RnStatus.OFFEN)
                      || (status_vorher == RnStatus.MAHNUNG_1)
                      || (status_vorher == RnStatus.MAHNUNG_2)
                      || (status_vorher == RnStatus.MAHNUNG_3)) {
                    rn.setStatus(status_vorher + 1);
                  }
                  rn.addTrace(
                      Rechnung.OUTPUT,
                      getDescription() + ": " + RnStatus.getStatusText(rn.getStatus()));
                } catch (Exception ex) {
                  SWTHelper.showError(
                      "Fehler beim Drucken der Rechnung " + rn.getRnId(), ex.getMessage());
                  errors++;
                }
              }
              monitor.done();
              if (errors == 0) {
                SWTHelper.showInfo("OK", "OK");
              } else {
                SWTHelper.showError("Fehler", "Fehler");
              }
            }
          },
          null);

      rnPage.hideView(rnp);

    } catch (Exception ex) {
      ExHandler.handle(ex);
      res.add(Result.SEVERITY.ERROR, 2, ex.getMessage(), null, true);
      ErrorDialog.openError(null, "Exception", "Exception", ResultAdapter.getResultAsStatus(res));
      return res;
    }
    if (!result.isOK()) {
      ResultAdapter.displayResult(result, "Fehler beim Rechnungsdruck");
    }
    return result;
  }