Java Code Examples for com.intellij.openapi.progress.ProgressManager#run()

The following examples show how to use com.intellij.openapi.progress.ProgressManager#run() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuckBuildManager.java    From Buck-IntelliJ-Plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Execute simple process asynchronously with progress.
 *
 * @param handler        a handler
 * @param operationTitle an operation title shown in progress dialog
 */
public void runBuckCommand(
    final BuckCommandHandler handler,
    final String operationTitle) {
  Project project = handler.project();

  // Always save files
  FileDocumentManager.getInstance().saveAllDocuments();

  String exec = BuckSettingsProvider.getInstance().getState().buckExecutable;
  if (exec == null) {
    BuckToolWindowFactory.outputConsoleMessage(
        project,
        "Please specify the buck executable path!\n",
        ConsoleViewContentType.ERROR_OUTPUT);

    BuckToolWindowFactory.outputConsoleMessage(
        project,
        "Preference -> Tools -> Buck -> Path to Buck executable\n",
        ConsoleViewContentType.NORMAL_OUTPUT);
    return;
  }

  final ProgressManager manager = ProgressManager.getInstance();
  manager.run(new Task.Backgroundable(handler.project(), operationTitle, true) {
    public void run(final ProgressIndicator indicator) {
      mProgressIndicator = indicator;
      runInCurrentThread(handler, indicator, true, operationTitle);
    }
  });
}
 
Example 2
Source File: DevToolsManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public CompletableFuture<Boolean> installDevTools() {
  if (isBazel(project)) {
    // TODO(jacobr): prebuild devtools so the initial devtools load is faster.
    // Bazel projects do not need to load DevTools.
    return createCompletedFuture(true);
  }

  final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
  if (sdk == null) {
    return createCompletedFuture(false);
  }

  final CompletableFuture<Boolean> result = new CompletableFuture<>();
  final FlutterCommand command = sdk.flutterPub(null, "global", "activate", "devtools");

  final ProgressManager progressManager = ProgressManager.getInstance();
  progressManager.run(new Task.Backgroundable(project, "Installing DevTools...", true) {
    Process process;

    @Override
    public void run(@NotNull ProgressIndicator indicator) {
      indicator.setText(getTitle());
      indicator.setIndeterminate(true);

      process = command.start((ProcessOutput output) -> {
        if (output.getExitCode() != 0) {
          final String message = (output.getStdout() + "\n" + output.getStderr()).trim();
          FlutterConsoles.displayMessage(project, null, message, true);
        }
      }, null);

      try {
        final int resultCode = process.waitFor();
        if (resultCode == 0) {
          installedDevTools = true;
        }
        result.complete(resultCode == 0);
      }
      catch (RuntimeException | InterruptedException re) {
        if (!result.isDone()) {
          result.complete(false);
        }
      }

      process = null;
    }

    @Override
    public void onCancel() {
      if (process != null && process.isAlive()) {
        process.destroy();
        if (!result.isDone()) {
          result.complete(false);
        }
      }
    }
  });

  return result;
}
 
Example 3
Source File: DevToolsManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public CompletableFuture<Boolean> installDevTools() {
  if (isBazel(project)) {
    // TODO(jacobr): prebuild devtools so the initial devtools load is faster.
    // Bazel projects do not need to load DevTools.
    return createCompletedFuture(true);
  }

  final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
  if (sdk == null) {
    return createCompletedFuture(false);
  }

  final CompletableFuture<Boolean> result = new CompletableFuture<>();
  final FlutterCommand command = sdk.flutterPub(null, "global", "activate", "devtools");

  final ProgressManager progressManager = ProgressManager.getInstance();
  progressManager.run(new Task.Backgroundable(project, "Installing DevTools...", true) {
    Process process;

    @Override
    public void run(@NotNull ProgressIndicator indicator) {
      indicator.setText(getTitle());
      indicator.setIndeterminate(true);

      process = command.start((ProcessOutput output) -> {
        if (output.getExitCode() != 0) {
          final String message = (output.getStdout() + "\n" + output.getStderr()).trim();
          FlutterConsoles.displayMessage(project, null, message, true);
        }
      }, null);

      try {
        final int resultCode = process.waitFor();
        if (resultCode == 0) {
          installedDevTools = true;
        }
        result.complete(resultCode == 0);
      }
      catch (RuntimeException | InterruptedException re) {
        if (!result.isDone()) {
          result.complete(false);
        }
      }

      process = null;
    }

    @Override
    public void onCancel() {
      if (process != null && process.isAlive()) {
        process.destroy();
        if (!result.isDone()) {
          result.complete(false);
        }
      }
    }
  });

  return result;
}