com.intellij.openapi.progress.impl.BackgroundableProcessIndicator Java Examples
The following examples show how to use
com.intellij.openapi.progress.impl.BackgroundableProcessIndicator.
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: FormatUtils.java From intellij with Apache License 2.0 | 6 votes |
/** Runs a format future under a progress dialog. */ public static void formatWithProgressDialog( Project project, String title, ListenableFuture<?> future) { ProgressWindow progressWindow = new BackgroundableProcessIndicator( project, title, PerformInBackgroundOption.DEAF, "Cancel", "Cancel", true); progressWindow.setIndeterminate(true); progressWindow.start(); progressWindow.addStateDelegate( new AbstractProgressIndicatorExBase() { @Override public void cancel() { super.cancel(); future.cancel(true); } }); future.addListener( () -> { if (progressWindow.isRunning()) { progressWindow.stop(); progressWindow.processFinish(); } }, MoreExecutors.directExecutor()); }
Example #2
Source File: SMTestRunnerResultsForm.java From consulo with Apache License 2.0 | 6 votes |
private void addToHistory(final SMTestProxy.SMRootTestProxy root, TestConsoleProperties consoleProperties, Disposable parentDisposable) { final RunProfile configuration = consoleProperties.getConfiguration(); if (configuration instanceof RunConfiguration && !(consoleProperties instanceof ImportedTestConsoleProperties) && !ApplicationManager.getApplication().isUnitTestMode() && !myDisposed) { final MySaveHistoryTask backgroundable = new MySaveHistoryTask(consoleProperties, root, (RunConfiguration)configuration); final BackgroundableProcessIndicator processIndicator = new BackgroundableProcessIndicator(backgroundable); Disposer.register(parentDisposable, new Disposable() { @Override public void dispose() { processIndicator.cancel(); backgroundable.dispose(); } }); Disposer.register(parentDisposable, processIndicator); ProgressManager.getInstance().runProcessWithProgressAsynchronously(backgroundable, processIndicator); } }
Example #3
Source File: ShowImplementationsAction.java From consulo with Apache License 2.0 | 6 votes |
private void updateInBackground(Editor editor, @Nullable PsiElement element, @Nonnull ImplementationViewComponent component, String title, @Nonnull AbstractPopup popup, @Nonnull Ref<UsageView> usageView) { final ImplementationsUpdaterTask updaterTask = SoftReference.dereference(myTaskRef); if (updaterTask != null) { updaterTask.cancelTask(); } if (element == null) return; //already found final ImplementationsUpdaterTask task = new ImplementationsUpdaterTask(element, editor, title, isIncludeAlwaysSelf(), component); task.init(popup, new ImplementationViewComponentUpdater(component, isIncludeAlwaysSelf() ? 1 : 0), usageView); myTaskRef = new WeakReference<>(task); ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task)); }
Example #4
Source File: PendingAsyncTestContext.java From intellij with Apache License 2.0 | 5 votes |
/** * Waits for the run configuration to be configured, displaying a progress dialog if necessary. * * @throws com.intellij.execution.ExecutionException if the run configuration is not successfully * configured */ private void waitForFutureUnderProgressDialog(Project project) throws com.intellij.execution.ExecutionException { if (future.isDone()) { getFutureHandlingErrors(); } // The progress indicator must be created on the UI thread. ProgressWindow indicator = UIUtil.invokeAndWaitIfNeeded( () -> new BackgroundableProcessIndicator( project, progressMessage, PerformInBackgroundOption.ALWAYS_BACKGROUND, "Cancel", "Cancel", /* cancellable= */ true)); indicator.setIndeterminate(true); indicator.start(); indicator.addStateDelegate( new AbstractProgressIndicatorExBase() { @Override public void cancel() { super.cancel(); future.cancel(true); } }); try { getFutureHandlingErrors(); } finally { if (indicator.isRunning()) { indicator.stop(); indicator.processFinish(); } } }
Example #5
Source File: SeparatePiecesRunner.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess private void pingImpl() { while (true) { myCurrentWrapper.set(null); // stop if project is being disposed if (!myProject.isDefault() && !myProject.isOpen()) return; if (getSuspendFlag()) return; final TaskDescriptor current = getNextMatching(); if (current == null) { return; } if (Where.AWT.equals(current.getWhere())) { setIndicator(null); try { current.run(this); } catch (RuntimeException th) { handleException(th, true); } } else { final TaskWrapper task = new TaskWrapper(myProject, current.getName(), myCancellable, current); myCurrentWrapper.set(task); if (ApplicationManager.getApplication().isUnitTestMode()) { setIndicator(new EmptyProgressIndicator()); } else { setIndicator(new BackgroundableProcessIndicator(task)); } ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, getIndicator()); return; } } }
Example #6
Source File: RefreshAction.java From NutzCodeInsight with Apache License 2.0 | 4 votes |
public void loadTree(Project project) { Module[] modules = ModuleManager.getInstance(toolWindowEx.getProject()).getModules(); DumbService.getInstance(toolWindowEx.getProject()).smartInvokeLater(() -> { Task.Backgroundable backgroundable = new Task.Backgroundable(project, "Nutz Api 扫描中...") { @Override public void run(@NotNull ProgressIndicator progressIndicator) { ApplicationManager.getApplication().runReadAction(() -> { Set<String> repeat = new HashSet<>(); //定义tree 的根目录 int size = 0; ApiMutableTreeNode root = new ApiMutableTreeNode(); for (Module module : modules) { List<AtMappingNavigationItem> requestMappingItems = FindRequestMappingItemsUtil.findRequestMappingItems(module); ApiMutableTreeNode apiMutableTreeNode = new ApiMutableTreeNode(new TreeNodeObject(project, TreeObjectTypeEnum.MODULE, module.getName())); List<ApiMutableTreeNode> list = new ArrayList<>(); for (AtMappingNavigationItem atMappingNavigationItem : requestMappingItems) { //是这个模块的api size = size + 1; progressIndicator.setText(atMappingNavigationItem.getText()); repeat.add(atMappingNavigationItem.getText()); TreeNodeObject treeNodeObject = new TreeNodeObject(project, atMappingNavigationItem); list.add(new ApiMutableTreeNode(treeNodeObject)); } if (list.size() > 0) { Collections.sort(list, (o1, o2) -> COMPARATOR.compare(o1.toString(), o2.toString())); list.forEach(mutableTreeNode -> apiMutableTreeNode.add(mutableTreeNode)); } if (apiMutableTreeNode.getChildCount() > 0) { root.add(apiMutableTreeNode); } } root.setUserObject(new TreeNodeObject(project, TreeObjectTypeEnum.ROOT, "Found " + size + " api")); apiTree.setModel(new DefaultTreeModel(root)); }); } }; BackgroundableProcessIndicator backgroundableProcessIndicator = new BackgroundableProcessIndicator(backgroundable); backgroundableProcessIndicator.setIndeterminate(true); ProgressManager.getInstance().runProcessWithProgressAsynchronously(backgroundable, backgroundableProcessIndicator); }); }
Example #7
Source File: ProgressiveTaskWithProgressIndicator.java From intellij with Apache License 2.0 | 4 votes |
/** * Runs the given task on the specified executor (defaulting to BlazeExecutor's executor) with a * progress dialog. */ public <T> ListenableFuture<T> submitTaskWithResult(ProgressiveWithResult<T> progressive) { // The progress indicator must be created on the UI thread. final ProgressWindow indicator = UIUtil.invokeAndWaitIfNeeded( () -> { if (modality == Modality.MODAL) { ProgressWindow window = new ProgressWindow(cancelable, project); window.setTitle(title); return window; } else { PerformInBackgroundOption backgroundOption = modality == Modality.BACKGROUNDABLE ? PerformInBackgroundOption.DEAF : PerformInBackgroundOption.ALWAYS_BACKGROUND; return new BackgroundableProcessIndicator( project, title, backgroundOption, "Cancel", "Cancel", cancelable); } }); indicator.setIndeterminate(true); indicator.start(); final ListenableFuture<T> future = executor.submit( () -> ProgressManager.getInstance() .runProcess(() -> progressive.compute(indicator), indicator)); if (cancelable) { indicator.addStateDelegate( new AbstractProgressIndicatorExBase() { @Override public void cancel() { super.cancel(); future.cancel(true); } }); } future.addListener( () -> { if (indicator.isRunning()) { indicator.stop(); indicator.processFinish(); } }, MoreExecutors.directExecutor()); return future; }
Example #8
Source File: AbstractVcsHelperImpl.java From consulo with Apache License 2.0 | 4 votes |
@Override public void loadAndShowCommittedChangesDetails(@Nonnull final Project project, @Nonnull final VcsRevisionNumber revision, @Nonnull final VirtualFile virtualFile, @Nonnull VcsKey vcsKey, @Nullable final RepositoryLocation location, final boolean isNonLocal) { final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).findVcsByName(vcsKey.getName()); if (vcs == null) return; final CommittedChangesProvider provider = vcs.getCommittedChangesProvider(); if (provider == null) return; if (isNonLocal && provider.getForNonLocal(virtualFile) == null) return; final String title = VcsBundle.message("paths.affected.in.revision", revision instanceof ShortVcsRevisionNumber ? ((ShortVcsRevisionNumber)revision).toShortString() : revision.asString()); final CommittedChangeList[] list = new CommittedChangeList[1]; final FilePath[] targetPath = new FilePath[1]; final VcsException[] exc = new VcsException[1]; final BackgroundableActionLock lock = BackgroundableActionLock.getLock(project, VcsBackgroundableActions.COMMITTED_CHANGES_DETAILS, revision, virtualFile.getPath()); if (lock.isLocked()) return; lock.lock(); Task.Backgroundable task = new Task.Backgroundable(project, title, true) { @Override public void run(@Nonnull ProgressIndicator indicator) { try { if (!isNonLocal) { final Pair<CommittedChangeList, FilePath> pair = provider.getOneList(virtualFile, revision); if (pair != null) { list[0] = pair.getFirst(); targetPath[0] = pair.getSecond(); } } else { if (location != null) { final ChangeBrowserSettings settings = provider.createDefaultSettings(); settings.USE_CHANGE_BEFORE_FILTER = true; settings.CHANGE_BEFORE = revision.asString(); final List<CommittedChangeList> changes = provider.getCommittedChanges(settings, location, 1); if (changes != null && changes.size() == 1) { list[0] = changes.get(0); } } else { list[0] = getRemoteList(vcs, revision, virtualFile); } } } catch (VcsException e) { exc[0] = e; } } @Override public void onCancel() { lock.unlock(); } @Override public void onSuccess() { lock.unlock(); if (exc[0] != null) { showError(exc[0], failedText(virtualFile, revision)); } else if (list[0] == null) { Messages.showErrorDialog(project, failedText(virtualFile, revision), getTitle()); } else { VirtualFile navigateToFile = targetPath[0] != null ? new VcsVirtualFile(targetPath[0].getPath(), null, VcsFileSystem.getInstance()) : virtualFile; showChangesListBrowser(list[0], navigateToFile, title); } } }; // we can's use runProcessWithProgressAsynchronously(task) because then ModalityState.NON_MODAL would be used CoreProgressManager progressManager = (CoreProgressManager)ProgressManager.getInstance(); progressManager.runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task), null, ModalityState.current()); }