/**
   * 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();
      }
    }
  }
Esempio n. 4
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);
   }
 }