private static String getStatusMessage(final CvsHandler handler) {
   final String actionName = handler.getTitle();
   if (handler.getErrors().isEmpty()) {
     return CvsBundle.message("status.text.action.completed", actionName);
   } else {
     return CvsBundle.message("status.text.action.completed.with.errors", actionName);
   }
 }
 private void connectToOutput(CvsHandler output) {
   CvsTabbedWindow tabbedWindow = CvsTabbedWindow.getInstance(myProject);
   Editor editor = tabbedWindow.getOutput();
   if (editor == null) {
     output.connectToOutputView(tabbedWindow.addOutput(createView(myProject)), myProject);
   } else {
     output.connectToOutputView(editor, myProject);
   }
 }
 protected void showErrors(final CvsHandler handler, final CvsTabbedWindow tabbedWindow) {
   final List<VcsException> errors = handler.getErrorsExceptAborted();
   if (!myShowErrors || myIsQuietOperation) return;
   if (tabbedWindow == null) {
     if (errors.isEmpty()) return;
     final List<String> messages = new ArrayList<String>();
     for (VcsException error : errors) {
       if (!StringUtil.isEmptyOrSpaces(error.getMessage())) {
         messages.add(error.getMessage());
       }
     }
     final String errorMessage = StringUtil.join(messages, "\n");
     Messages.showErrorDialog(errorMessage, "CVS Error");
     return;
   }
   if (errors.isEmpty()) {
     tabbedWindow.hideErrors();
   } else {
     ErrorTreeView errorTreeView = tabbedWindow.getErrorsTreeView();
     for (final VcsException exception : errors) {
       final String groupName =
           DateFormatUtil.formatDateTime(System.currentTimeMillis()) + ' ' + handler.getTitle();
       if (exception.isWarning()) {
         errorTreeView.addMessage(
             MessageCategory.WARNING,
             exception.getMessages(),
             groupName,
             DummyNavigatable.INSTANCE,
             null,
             null,
             exception);
       } else {
         errorTreeView.addMessage(
             MessageCategory.ERROR,
             exception.getMessages(),
             groupName,
             DummyNavigatable.INSTANCE,
             null,
             null,
             exception);
       }
     }
     tabbedWindow.ensureVisible(myProject);
   }
 }
  public void performActionSync(
      final CvsHandler handler, final CvsOperationExecutorCallback callback) {
    final CvsTabbedWindow tabbedWindow = myIsQuietOperation ? null : openTabbedWindow(handler);

    final Runnable finish =
        new Runnable() {
          @Override
          public void run() {
            try {
              myResult.addAllErrors(handler.getErrorsExceptAborted());
              handler.finish();
              if (myProject == null || myProject != null && !myProject.isDisposed()) {
                showErrors(handler, tabbedWindow);
              }
            } finally {
              try {
                if (myResult.finishedUnsuccessfully(handler)) {
                  callback.executionFinished(false);
                } else {
                  if (handler.getErrors().isEmpty()) callback.executionFinishedSuccessfully();
                  callback.executionFinished(true);
                }
              } finally {
                if (myProject != null && handler != CvsHandler.NULL) {
                  StatusBar.Info.set(getStatusMessage(handler), myProject);
                }
              }
            }
          }
        };

    final Runnable cvsAction =
        new Runnable() {
          @Override
          public void run() {
            try {
              if (handler == CvsHandler.NULL) return;
              setText(CvsBundle.message("progress.text.preparing.for.login"));

              handler.beforeLogin();

              if (myResult.finishedUnsuccessfully(handler)) return;

              setText(CvsBundle.message("progress.text.preparing.for.action", handler.getTitle()));

              handler.run(myProject, myExecutor);
              if (myResult.finishedUnsuccessfully(handler)) return;

            } catch (ProcessCanceledException ex) {
              myResult.setIsCanceled();
            } finally {
              callback.executeInProgressAfterAction(myExecutor);
            }
          }
        };

    if (doNotShowProgress()) {
      cvsAction.run();
      if (myIsQuietOperation) {
        finish.run();
      } else {
        myExecutor.runInDispatchThread(finish, myProject);
      }
    } else {
      final PerformInBackgroundOption backgroundOption = handler.getBackgroundOption(myProject);
      if (backgroundOption != null) {
        final Task.Backgroundable task =
            new Task.Backgroundable(
                myProject, handler.getTitle(), handler.canBeCanceled(), backgroundOption) {
              @Override
              public void run(@NotNull final ProgressIndicator indicator) {
                cvsAction.run();
              }

              @Override
              public void onSuccess() {
                finish.run();
              }
            };
        ProgressManager.getInstance().run(task);
      } else {
        if (ProgressManager.getInstance()
            .runProcessWithProgressSynchronously(
                cvsAction, handler.getTitle(), handler.canBeCanceled(), myProject)) {
          finish.run();
        }
      }
    }
  }