Java Code Examples for com.intellij.openapi.progress.progressmanager#runProcessWithProgressSynchronously()

The following examples show how to use com.intellij.openapi.progress.progressmanager#runProcessWithProgressSynchronously() . 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: FlutterModuleBuilder.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Runs flutter create without showing a console, but with an indeterminate progress dialog.
 * <p>
 * Returns the PubRoot if successful.
 */
@Nullable
public static PubRoot runFlutterCreateWithProgress(@NotNull VirtualFile baseDir,
                                                   @NotNull FlutterSdk sdk,
                                                   @NotNull Project project,
                                                   @Nullable ProcessListener processListener,
                                                   @Nullable FlutterCreateAdditionalSettings additionalSettings) {
  final ProgressManager progress = ProgressManager.getInstance();
  final AtomicReference<PubRoot> result = new AtomicReference<>(null);

  FlutterUtils.disableGradleProjectMigrationNotification(project);

  progress.runProcessWithProgressSynchronously(() -> {
    progress.getProgressIndicator().setIndeterminate(true);
    result.set(sdk.createFiles(baseDir, null, processListener, additionalSettings));
  }, "Creating Flutter Project", false, project);

  return result.get();
}
 
Example 2
Source File: FlutterModuleBuilder.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Runs flutter create without showing a console, but with an indeterminate progress dialog.
 * <p>
 * Returns the PubRoot if successful.
 */
@Nullable
public static PubRoot runFlutterCreateWithProgress(@NotNull VirtualFile baseDir,
                                                   @NotNull FlutterSdk sdk,
                                                   @NotNull Project project,
                                                   @Nullable ProcessListener processListener,
                                                   @Nullable FlutterCreateAdditionalSettings additionalSettings) {
  final ProgressManager progress = ProgressManager.getInstance();
  final AtomicReference<PubRoot> result = new AtomicReference<>(null);

  FlutterUtils.disableGradleProjectMigrationNotification(project);

  progress.runProcessWithProgressSynchronously(() -> {
    progress.getProgressIndicator().setIndeterminate(true);
    result.set(sdk.createFiles(baseDir, null, processListener, additionalSettings));
  }, "Creating Flutter Project", false, project);

  return result.get();
}
 
Example 3
Source File: NewClassAction.java    From json2java4idea with Apache License 2.0 5 votes vote down vote up
@Override
public void onOk(@Nonnull NewClassDialog dialog) {
    final PsiDirectory directory = ideView.getOrChooseDirectory();
    if (directory == null) {
        dialog.cancel();
        return;
    }

    try {
        final CommandActionFactory actionFactory = commandActionFactoryProvider.get();
        final JavaConverterFactory converterFactory = javaConverterFactoryProvider.get();
        final NewClassCommandAction command = actionFactory.create(
                dialog.getClassName(),
                dialog.getJson(),
                directory,
                converterFactory.create(settings)
        );

        final ProgressManager progressManager = ProgressManager.getInstance();
        progressManager.runProcessWithProgressSynchronously(() -> {
            final ProgressIndicator indicator = progressManager.getProgressIndicator();
            if (indicator != null) {
                indicator.setIndeterminate(true);
                indicator.setText(bundle.message("progress.text", dialog.getClassName()));
            }

            final RunResult<PsiFile> result = command.execute();
            return result.getResultObject();
        }, bundle.message("progress.title"), false, project);
        dialog.close();
    } catch (RuntimeException e) {
        LOGGER.warn("Unable to create a class", e);
        onError(dialog, e.getCause());
    }
}
 
Example 4
Source File: MuleSdkSelectionDialog.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
private void downloadVersionWithProgress(String version, String destinationDir) {

        Messages.showInfoMessage(contentPane, "Download Is Going to Take Some Time. Good time for a coffee.", "Mule Distribution Download");
        final Optional<MuleUrl> first = MuleUrl.getVERSIONS().stream().filter((url) -> url.getName().equals(version)).findFirst();
        final MuleUrl muleUrl = first.get();
        try {
            final ProgressManager instance = ProgressManager.getInstance();
            final File distro = instance.runProcessWithProgressSynchronously(() -> {
                final URL artifactUrl = new URL(muleUrl.getUrl());
                final File sourceFile = FileUtil.createTempFile("mule" + version, ".zip");
                if (download(instance.getProgressIndicator(), artifactUrl, sourceFile, version)) {
                    final File destDir = new File(destinationDir);
                    destDir.mkdirs();
                    ZipUtil.extract(sourceFile, destDir, null);
                    try (ZipFile zipFile = new ZipFile(sourceFile)) {
                        String rootName = zipFile.entries().nextElement().getName();
                        return new File(destDir, rootName);
                    }
                } else {
                    return null;
                }
            }, "Downloading Mule Distribution " + muleUrl.getName(), true, null);
            if (distro != null) {
                final MuleSdk muleSdk = new MuleSdk(distro.getAbsolutePath());
                MuleSdkManagerImpl.getInstance().addSdk(muleSdk);
                myTableModel.addRow(muleSdk);
                final int rowIndex = myTableModel.getRowCount() - 1;
                myInputsTable.getSelectionModel().setSelectionInterval(rowIndex, rowIndex);
                onOK();
            }
        } catch (Exception e) {
            Messages.showErrorDialog("An error occurred while trying to download " + version + ".\n" + e.getMessage(),
                    "Mule SDK Download Error");
        }

    }
 
Example 5
Source File: AbstractMissingFilesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  final List<FilePath> files = e.getData(ChangesListView.MISSING_FILES_DATA_KEY);
  if (files == null) return;

  final ProgressManager progressManager = ProgressManager.getInstance();
  final Runnable action = new Runnable() {
    public void run() {
      final List<VcsException> allExceptions = new ArrayList<VcsException>();
      ChangesUtil.processFilePathsByVcs(project, files, new ChangesUtil.PerVcsProcessor<FilePath>() {
        public void process(final AbstractVcs vcs, final List<FilePath> items) {
          final List<VcsException> exceptions = processFiles(vcs, files);
          if (exceptions != null) {
            allExceptions.addAll(exceptions);
          }
        }
      });

      for (FilePath file : files) {
        VcsDirtyScopeManager.getInstance(project).fileDirty(file);
      }
      ChangesViewManager.getInstance(project).scheduleRefresh();
      if (allExceptions.size() > 0) {
        AbstractVcsHelper.getInstance(project).showErrors(allExceptions, "VCS Errors");
      }
    }
  };
  if (synchronously()) {
    action.run();
  } else {
    progressManager.runProcessWithProgressSynchronously(action, getName(), true, project);
  }
}
 
Example 6
Source File: FlutterProjectCreator.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void createProject() {
  IdeFrame frame = IdeFocusManager.getGlobalInstance().getLastFocusedFrame();
  final Project projectToClose = frame != null ? frame.getProject() : null;

  VirtualFile baseDir = getLocationFromModel(projectToClose, true);
  if (baseDir == null) {
    return;
  }
  //noinspection ConstantConditions (Keep this refresh even if the converter is removed.)
  VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);

  // Create the project files using 'flutter create'.
  FlutterSdk sdk = FlutterSdk.forPath(myModel.flutterSdk().get());
  if (sdk == null) {
    FlutterMessages.showError("Error creating project", myModel.flutterSdk().get() + " is not a valid Flutter SDK");
    return;
  }
  final OutputListener listener = new OutputListener();
  // TODO(messick,pq): Refactor createFiles() to accept a logging interface instead of module, and display it in the wizard.
  ProgressManager progress = ProgressManager.getInstance();
  AtomicReference<PubRoot> result = new AtomicReference<>(null);
  progress.runProcessWithProgressSynchronously(() -> {
    progress.getProgressIndicator().setIndeterminate(true);
    sdk.createFiles(baseDir, null, listener, makeAdditionalSettings());
    VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);
    result.set(PubRoot.forDirectory(baseDir));
  }, "Creating Flutter Project", false, null);
  PubRoot root = result.get();
  if (root == null) {
    String stderr = listener.getOutput().getStderr();
    FlutterMessages.showError("Error creating project", stderr.isEmpty() ? "Flutter create command was unsuccessful" : stderr);
    return;
  }

  Project project = null;
  if (myModel.shouldOpenNewWindow()) {
    // Open the project window.
    EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class);
    project = PlatformProjectOpenProcessor.doOpenProject(baseDir, projectToClose, -1, null, options);
  }

  if (project != null) {
    // Android Studio changes the default project type, so we need to set it.
    ProjectTypeService.setProjectType(project, ProjectOpenActivity.FLUTTER_PROJECT_TYPE);
    disableGradleProjectMigrationNotification(project);
    disableUserConfig(project);
    Project proj = project;
    StartupManager.getInstance(project).registerPostStartupActivity(
      () -> ApplicationManager.getApplication().invokeLater(
        () -> {
          // We want to show the Project view, not the Android view since it doesn't make the Dart code visible.
          DumbService.getInstance(proj).runWhenSmart(
            () -> {
              ToolWindowManager.getInstance(proj).getToolWindow(ToolWindowId.PROJECT_VIEW).activate(null);
              ProjectView.getInstance(proj).changeView(ProjectViewPane.ID);
            });
        }, ModalityState.defaultModalityState()));
  }
}
 
Example 7
Source File: FlutterProjectCreator.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void createProject() {
  IdeFrame frame = IdeFocusManager.getGlobalInstance().getLastFocusedFrame();
  final Project projectToClose = frame != null ? frame.getProject() : null;

  VirtualFile baseDir = getLocationFromModel(projectToClose, true);
  if (baseDir == null) {
    return;
  }
  //noinspection ConstantConditions (Keep this refresh even if the converter is removed.)
  VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);

  // Create the project files using 'flutter create'.
  FlutterSdk sdk = FlutterSdk.forPath(myModel.flutterSdk().get());
  if (sdk == null) {
    FlutterMessages.showError("Error creating project", myModel.flutterSdk().get() + " is not a valid Flutter SDK");
    return;
  }
  final OutputListener listener = new OutputListener();
  // TODO(messick,pq): Refactor createFiles() to accept a logging interface instead of module, and display it in the wizard.
  ProgressManager progress = ProgressManager.getInstance();
  AtomicReference<PubRoot> result = new AtomicReference<>(null);
  progress.runProcessWithProgressSynchronously(() -> {
    progress.getProgressIndicator().setIndeterminate(true);
    sdk.createFiles(baseDir, null, listener, makeAdditionalSettings());
    VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);
    result.set(PubRoot.forDirectory(baseDir));
  }, "Creating Flutter Project", false, null);
  PubRoot root = result.get();
  if (root == null) {
    String stderr = listener.getOutput().getStderr();
    FlutterMessages.showError("Error creating project", stderr.isEmpty() ? "Flutter create command was unsuccessful" : stderr);
    return;
  }

  Project project = null;
  if (myModel.shouldOpenNewWindow()) {
    // Open the project window.
    EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class);
    project = PlatformProjectOpenProcessor.doOpenProject(baseDir, projectToClose, -1, null, options);
  }

  if (project != null) {
    // Android Studio changes the default project type, so we need to set it.
    ProjectTypeService.setProjectType(project, ProjectOpenActivity.FLUTTER_PROJECT_TYPE);
    disableGradleProjectMigrationNotification(project);
    disableUserConfig(project);
    Project proj = project;
    StartupManager.getInstance(project).registerPostStartupActivity(
      () -> ApplicationManager.getApplication().invokeLater(
        () -> {
          // We want to show the Project view, not the Android view since it doesn't make the Dart code visible.
          DumbService.getInstance(proj).runWhenSmart(
            () -> {
              ToolWindowManager.getInstance(proj).getToolWindow(ToolWindowId.PROJECT_VIEW).activate(null);
              ProjectView.getInstance(proj).changeView(ProjectViewPane.ID);
            });
        }, ModalityState.defaultModalityState()));
  }
}
 
Example 8
Source File: RollbackAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void rollbackModifiedWithoutEditing(final Project project, final LinkedHashSet<VirtualFile> modifiedWithoutEditing) {
  final String operationName = StringUtil.decapitalize(UIUtil.removeMnemonic(RollbackUtil.getRollbackOperationName(project)));
  String message = (modifiedWithoutEditing.size() == 1)
                   ? VcsBundle.message("rollback.modified.without.editing.confirm.single",
                                       operationName, modifiedWithoutEditing.iterator().next().getPresentableUrl())
                   : VcsBundle.message("rollback.modified.without.editing.confirm.multiple",
                                       operationName, modifiedWithoutEditing.size());
  int rc = showYesNoDialog(project, message, VcsBundle.message("changes.action.rollback.title", operationName), getQuestionIcon());
  if (rc != Messages.YES) {
    return;
  }
  final List<VcsException> exceptions = new ArrayList<>();

  final ProgressManager progressManager = ProgressManager.getInstance();
  final Runnable action = new Runnable() {
    public void run() {
      final ProgressIndicator indicator = progressManager.getProgressIndicator();
      try {
        ChangesUtil.processVirtualFilesByVcs(project, modifiedWithoutEditing, (vcs, items) -> {
          final RollbackEnvironment rollbackEnvironment = vcs.getRollbackEnvironment();
          if (rollbackEnvironment != null) {
            if (indicator != null) {
              indicator.setText(vcs.getDisplayName() +
                                ": performing " + UIUtil.removeMnemonic(rollbackEnvironment.getRollbackOperationName()).toLowerCase() + "...");
              indicator.setIndeterminate(false);
            }
            rollbackEnvironment
                    .rollbackModifiedWithoutCheckout(items, exceptions, new RollbackProgressModifier(items.size(), indicator));
            if (indicator != null) {
              indicator.setText2("");
            }
          }
        });
      }
      catch (ProcessCanceledException e) {
        // for files refresh
      }
      if (!exceptions.isEmpty()) {
        AbstractVcsHelper.getInstance(project).showErrors(exceptions, VcsBundle.message("rollback.modified.without.checkout.error.tab",
                                                                                        operationName));
      }

      VfsUtil.markDirty(true, false, VfsUtilCore.toVirtualFileArray(modifiedWithoutEditing));

      VirtualFileManager.getInstance().asyncRefresh(new Runnable() {
        public void run() {
          for (VirtualFile virtualFile : modifiedWithoutEditing) {
            VcsDirtyScopeManager.getInstance(project).fileDirty(virtualFile);
          }
        }
      });
    }
  };
  progressManager.runProcessWithProgressSynchronously(action, operationName, true, project);
}