Beispiel #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();
   }
 }
 private void doInvokeExportMarshallers(final BpmnMemoryModel model)
     throws InvocationTargetException, InterruptedException {
   final Collection<ExportMarshaller> marshallers = ExtensionPointUtil.getExportMarshallers();
   final ExportMarshallerRunnable runnable = new ExportMarshallerRunnable(model, marshallers);
   final IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
   progressService.busyCursorWhile(runnable);
 }
  /**
   * Perform organize import on multiple compilation units. No editors are opened.
   *
   * @param cus The compilation units to run on
   */
  public void runOnMultiple(final ICompilationUnit[] cus) {
    try {
      String message =
          "Problems while organizing imports on some compilation units. See 'Details' for more information.";
      final MultiStatus status = new MultiStatus(JavaUI.ID_PLUGIN, IStatus.OK, message, null);

      IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
      progressService.run(
          true,
          true,
          new WorkbenchRunnableAdapter(
              new IWorkspaceRunnable() {
                public void run(IProgressMonitor monitor) {
                  doRunOnMultiple(cus, status, monitor);
                }
              })); // workspace lock
      if (!status.isOK()) {
        String title = "Organize Imports";
        ErrorDialog.openError(getShell(), title, null, status);
      }
    } catch (InvocationTargetException e) {
      ExceptionHandler.handle(
          e,
          getShell(),
          ActionMessages.OrganizeImportsAction_error_title,
          ActionMessages.OrganizeImportsAction_error_message);
    } catch (InterruptedException e) {
      // Canceled by user
    }
  }
 public void build() throws CoreException, InvocationTargetException, InterruptedException {
   WorkspaceModifyOperation op =
       new WorkspaceModifyOperation() {
         @Override
         protected void execute(IProgressMonitor monitor) throws CoreException {
           project.build(IncrementalProjectBuilder.FULL_BUILD, null);
         };
       };
   IProgressService service = PlatformUI.getWorkbench().getProgressService();
   service.run(true, true, op);
 }
  public synchronized void backupNow(boolean synchronous, IProgressMonitor monitor) {

    monitor = Policy.monitorFor(monitor);

    File backupFolder = new File(backupFolderPath);
    if (!backupFolder.exists()) {
      backupFolder.mkdir();
    }

    final TaskDataExportOperation backupJob =
        new TaskDataSnapshotOperation(backupFolderPath, getBackupFileName());
    try {
      if (!synchronous) {
        backupJob.run(monitor);
        removeOldBackups();
      } else {
        IProgressService service = PlatformUI.getWorkbench().getProgressService();
        service.run(false, true, backupJob);
      }
    } catch (InterruptedException e) {
    } catch (Throwable e) {
      if (!errorDisplayed) {
        final Status status =
            new Status(
                IStatus.ERROR,
                TasksUiPlugin.ID_PLUGIN,
                Messages.TaskListBackupManager_Error_occured_during_scheduled_tasklist_backup,
                e);
        errorDisplayed = true;
        if (Display.getCurrent() != null) {
          TasksUiInternal.logAndDisplayStatus(
              Messages.TaskListBackupManager_Scheduled_task_data_backup, status);
        } else {
          PlatformUI.getWorkbench()
              .getDisplay()
              .asyncExec(
                  new Runnable() {
                    public void run() {
                      TasksUiInternal.logAndDisplayStatus(
                          Messages.TaskListBackupManager_Scheduled_task_data_backup, status);
                    }
                  });
        }
      }

      // clean up corrupt backup file
      if (backupJob.getDestinationFile() != null) {
        backupJob.getDestinationFile().delete();
      }
    }
  }
Beispiel #6
0
 private void fillProcessesList(final TableViewer tableViewer) {
   final IProgressService ps = PlatformUI.getWorkbench().getProgressService();
   try {
     ps.busyCursorWhile(
         new IRunnableWithProgress() {
           @Override
           public void run(final IProgressMonitor pm) {
             final TracedProcess[] processesList = ProcessHelper.getProcsOnTracedNodes();
             TraceBackend.getInstance().setProcesses(processesList);
           }
         });
   } catch (final Exception e) {
     ErlLogger.error(e);
   }
 }
Beispiel #7
0
 public static void runWithProgress(String name, Runnable runnable) {
   IProgressService progress = PlatformUI.getWorkbench().getProgressService();
   try {
     progress.run(
         true,
         false,
         (monitor) -> {
           monitor.beginTask(name, IProgressMonitor.UNKNOWN);
           runnable.run();
           monitor.done();
         });
   } catch (InvocationTargetException | InterruptedException e) {
     log.error("Error while running progress " + name, e);
   }
 }
Beispiel #8
0
 /**
  * The action has been activated. The argument of the method represents the 'real' action sitting
  * in the workbench UI.
  *
  * @see IWorkbenchWindowActionDelegate#run
  */
 public void run(IAction action) {
   final SettingsDialog sd = new SettingsDialog(window.getShell());
   if (sd.open() == Dialog.OK) {
     if (SWTHelper.askYesNo(
         "Wirklich Datenbank anonymisieren",
         "Achtung! Diese Aktion macht die Datenbank unwiderruflich unbrauchbar! Wirklich anonymisieren?")) {
       zufallsnamen = sd.replaceNames;
       IWorkbench wb = PlatformUI.getWorkbench();
       IProgressService ps = wb.getProgressService();
       try {
         ps.busyCursorWhile(
             new IRunnableWithProgress() {
               public void run(IProgressMonitor pm) {
                 pm.beginTask("Anonymisiere Datenbank", TOTAL);
                 int jobs = 1;
                 if (sd.replaceKons) {
                   jobs++;
                 }
                 if (sd.deleteDocs) {
                   jobs++;
                 }
                 if (sd.purgeDB) {
                   jobs++;
                 }
                 doShakeNames(pm, TOTAL / jobs);
                 if (sd.replaceKons) {
                   doShakeKons(pm, TOTAL / jobs);
                 }
                 if (sd.deleteDocs) {
                   new DocumentRemover().run(pm, TOTAL / jobs);
                 }
                 if (sd.purgeDB) {
                   doPurgeDB(pm, TOTAL / jobs);
                 }
                 pm.done();
               }
             });
       } catch (InvocationTargetException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       } catch (InterruptedException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
     }
   }
 }
  private RenameSupport undoAndCreateRenameSupport(String newName) throws CoreException {
    // Assumption: the linked mode model should be shut down by now.

    final ISourceViewer viewer = fEditor.getViewer();

    try {
      if (!fOriginalName.equals(newName)) {
        IWorkbenchWindow workbenchWindow = fEditor.getSite().getWorkbenchWindow();
        // undo
        workbenchWindow.run(
            false,
            true,
            new IRunnableWithProgress() {
              @Override
              public void run(IProgressMonitor monitor)
                  throws InvocationTargetException, InterruptedException {
                if (viewer instanceof ITextViewerExtension6) {
                  IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager();
                  if (undoManager instanceof IUndoManagerExtension) {
                    IUndoManagerExtension undoManagerExtension =
                        (IUndoManagerExtension) undoManager;
                    IUndoContext undoContext = undoManagerExtension.getUndoContext();
                    IOperationHistory operationHistory =
                        OperationHistoryFactory.getOperationHistory();
                    while (undoManager.undoable()) {
                      if (fStartingUndoOperation != null
                          && fStartingUndoOperation.equals(
                              operationHistory.getUndoOperation(undoContext))) {
                        return;
                      }
                      undoManager.undo();
                    }
                  }
                }
              }
            });
        // wait for analysis
        IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
        progressService.busyCursorWhile(
            new IRunnableWithProgress() {
              @Override
              public void run(IProgressMonitor monitor)
                  throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Waiting for background analysis...", IProgressMonitor.UNKNOWN);
                try {
                  RefactoringUtils.waitResolvedCompilationUnit(fEditor, monitor);
                  RefactoringUtils.waitReadyForRefactoring(monitor);
                } finally {
                  monitor.done();
                }
              }
            });
        // by some reason "busyCursorWhile" looses focus, so restore it
        fEditor.setFocus();
        // get new Element, after background build finished
        prepareElement();
        if (fDartElement == null) {
          return null;
        }
      }
    } catch (InvocationTargetException e) {
      throw new CoreException(
          new Status(
              IStatus.ERROR,
              DartToolsPlugin.getPluginId(),
              ReorgMessages.RenameLinkedMode_error_saving_editor,
              e));
    } catch (InterruptedException e) {
      // canceling is OK
      return null;
    }

    viewer.setSelectedRange(fOriginalSelection.x, fOriginalSelection.y);

    if (newName.length() == 0) {
      return null;
    }

    return RenameSupport.create(fDartElement, newName);
  }
  /**
   * 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;
  }
Beispiel #13
0
  /*
   * (non-Javadoc)
   *
   * @see org.mwc.debrief.core.interfaces.IPlotLoader#loadFile(org.mwc.cmap.plotViewer.editors.CorePlotEditor,
   *      org.eclipse.ui.IEditorInput)
   */
  public void loadFile(
      final PlotEditor thePlot, final InputStream inputStream, final String fileName) {
    final Layers theLayers = (Layers) thePlot.getAdapter(Layers.class);

    try {

      // hmm, is there anything in the file?
      final int numAvailable = inputStream.available();
      if (numAvailable > 0) {

        final IWorkbench wb = PlatformUI.getWorkbench();
        final IProgressService ps = wb.getProgressService();
        ps.busyCursorWhile(
            new IRunnableWithProgress() {
              public void run(final IProgressMonitor pm) {
                // right, better suspend the LayerManager extended updates from
                // firing
                theLayers.suspendFiringExtended(true);

                try {
                  DebriefPlugin.logError(Status.INFO, "about to start loading:" + fileName, null);

                  // quick check, is this a KMZ
                  if (fileName.endsWith(".tif")) {
                    // create a layer name from the filename
                    File tmpFile = new File(fileName);
                    String layerName = tmpFile.getName();

                    // ok - get loading going
                    final ExternallyManagedDataLayer dl =
                        new ExternallyManagedDataLayer(
                            ChartBoundsWrapper.WORLDIMAGE_TYPE, layerName, fileName);
                    theLayers.addThisLayer(dl);
                  }

                  DebriefPlugin.logError(Status.INFO, "completed loading:" + fileName, null);

                  // and inform the plot editor
                  thePlot.loadingComplete(this);

                  DebriefPlugin.logError(Status.INFO, "parent plot informed", null);

                } catch (final RuntimeException e) {
                  DebriefPlugin.logError(Status.ERROR, "Problem loading datafile:" + fileName, e);
                } finally {
                  // ok, allow the layers object to inform anybody what's
                  // happening
                  // again
                  theLayers.suspendFiringExtended(false);

                  // and trigger an update ourselves
                  // theLayers.fireExtended();
                }
              }
            });
      }

    } catch (final InvocationTargetException e) {
      DebriefPlugin.logError(Status.ERROR, "Problem loading tif:" + fileName, e);
    } catch (final InterruptedException e) {
      DebriefPlugin.logError(Status.ERROR, "Problem loading tif:" + fileName, e);
    } catch (final IOException e) {
      DebriefPlugin.logError(Status.ERROR, "Problem loading tif:" + fileName, e);
    } finally {
    }
    //	}
    // ok, load the data...
    DebriefPlugin.logError(Status.INFO, "Successfully loaded tuf file", null);
  }