Java Code Examples for com.intellij.openapi.progress.ProgressManager
The following are top voted examples for showing how to use
com.intellij.openapi.progress.ProgressManager. These examples are extracted from open source projects.
You can vote up the examples you like and your votes will be used in our system to generate
more good examples.
Example 1
Project: GitHub File: DataWriter.java View source code | 6 votes |
public void execute(ClassEntity targetClass) { this.targetClass = targetClass; ProgressManager.getInstance().run(new Task.Backgroundable(project, "GsonFormat") { @Override public void run(@NotNull ProgressIndicator progressIndicator) { progressIndicator.setIndeterminate(true); long currentTimeMillis = System.currentTimeMillis(); execute(); progressIndicator.setIndeterminate(false); progressIndicator.setFraction(1.0); StringBuffer sb = new StringBuffer(); sb.append("GsonFormat [" + (System.currentTimeMillis() - currentTimeMillis) + " ms]\n"); // sb.append("generate class : ( "+generateClassList.size()+" )\n"); // for (String item: generateClassList) { // sb.append(" at "+item+"\n"); // } // sb.append(" \n"); // NotificationCenter.info(sb.toString()); Toast.make(project, MessageType.INFO, sb.toString()); } }); }
Example 2
Project: CodeGenerate File: DataWriter.java View source code | 6 votes |
public void execute(ClassEntity targetClass) { this.targetClass = targetClass; ProgressManager.getInstance().run(new Task.Backgroundable(project, "GsonFormat") { @Override public void run(@NotNull ProgressIndicator progressIndicator) { progressIndicator.setIndeterminate(true); long currentTimeMillis = System.currentTimeMillis(); execute(); progressIndicator.setIndeterminate(false); progressIndicator.setFraction(1.0); StringBuffer sb = new StringBuffer(); sb.append("GsonFormat [" + (System.currentTimeMillis() - currentTimeMillis) + " ms]\n"); // sb.append("generate class : ( "+generateClassList.size()+" )\n"); // for (String item: generateClassList) { // sb.append(" at "+item+"\n"); // } // sb.append(" \n"); // NotificationCenter.info(sb.toString()); Toast.make(project, MessageType.INFO, sb.toString()); } }); }
Example 3
Project: TS-IJ File: TSGlobalCachedListGenerator.java View source code | 6 votes |
@Override public Set<TSVarExpr> generate(Project project) { Set<TSVarExpr> items = new HashSet<>(); //Search every file in the project Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, TSFileType.INSTANCE, GlobalSearchScope.projectScope(project)); for (VirtualFile virtualFile : virtualFiles) { TSFile tsFile = (TSFile) PsiManager.getInstance(project).findFile(virtualFile); if (tsFile != null) { Collection<TSAssignExpr> assignments = PsiTreeUtil.findChildrenOfType(tsFile, TSAssignExpr.class); for (TSAssignExpr assignment : assignments) { PsiElement first = assignment.getFirstChild(); if (!(first instanceof TSVarExpr)) continue; if (((TSVarExpr)first).isLocal()) continue; items.add((TSVarExpr) first); } } ProgressManager.progress("Loading Symbols"); } return items; }
Example 4
Project: jfrog-idea-plugin File: ScanManager.java View source code | 6 votes |
/** * Launch async dependency scan. */ public void asyncScanAndUpdateResults(boolean quickScan, @Nullable Collection<DataNode<LibraryDependencyData>> libraryDependencies) { Task.Backgroundable scanAndUpdateTask = new Task.Backgroundable(project, "Xray: Scanning for Vulnerabilities...") { @Override public void run(@NotNull ProgressIndicator indicator) { scanAndUpdate(quickScan, indicator, libraryDependencies); indicator.finishNonCancelableSection(); } }; // The progress manager is only good for foreground threads. if (SwingUtilities.isEventDispatchThread()) { ProgressManager.getInstance().run(scanAndUpdateTask); } else { // Run the scan task when the thread is in the foreground. SwingUtilities.invokeLater(() -> ProgressManager.getInstance().run(scanAndUpdateTask)); } }
Example 5
Project: AndroidSourceViewer File: GlobalSearchAction.java View source code | 6 votes |
@Override public void OnResult(String result) { int extPos = result.lastIndexOf('/'); if (extPos < 0 && extPos != result.length() - 1) { return; } String fileName = result.substring(extPos + 1); String title = "Download:" + fileName; File downloadFile = new File(Constant.CACHE_PATH + "search/" + fileName); ProgressManager.getInstance().run(new Task.Backgroundable(project, title) { @Override public void run(@NotNull ProgressIndicator progressIndicator) { try { DownloadUtil.downloadAtomically(null, result, downloadFile); } catch (IOException e) { e.printStackTrace(); } if (downloadFile.exists()) { Utils.openFileInPanel(downloadFile.getPath(), project); } } }); }
Example 6
Project: educational-plugin File: PyStudyDirectoryProjectGenerator.java View source code | 6 votes |
@Nullable @Override public BooleanFunction<PythonProjectGenerator> beforeProjectGenerated(@Nullable Sdk sdk) { return generator -> { final List<Integer> enrolledCoursesIds = myGenerator.getEnrolledCoursesIds(); final Course course = myGenerator.getSelectedCourse(); if (course == null || !(course instanceof RemoteCourse)) return true; if (((RemoteCourse)course).getId() > 0 && !enrolledCoursesIds.contains(((RemoteCourse)course).getId())) { ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> { ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true); return StudyUtils.execCancelable(() -> EduStepicConnector.enrollToCourse(((RemoteCourse)course).getId(), StudySettings.getInstance().getUser())); }, "Creating Course", true, ProjectManager.getInstance().getDefaultProject()); } return true; }; }
Example 7
Project: educational-plugin File: StudyUtils.java View source code | 6 votes |
@Nullable public static <T> T execCancelable(@NotNull final Callable<T> callable) { final Future<T> future = ApplicationManager.getApplication().executeOnPooledThread(callable); while (!future.isCancelled() && !future.isDone()) { ProgressManager.checkCanceled(); TimeoutUtil.sleep(500); } T result = null; try { result = future.get(); } catch (InterruptedException | ExecutionException e) { LOG.warn(e.getMessage()); } return result; }
Example 8
Project: educational-plugin File: EduNextRecommendationCheckListener.java View source code | 6 votes |
@Override public void afterCheck(@NotNull Project project, @NotNull Task task) { Course course = task.getLesson().getCourse(); if (!(course instanceof RemoteCourse && course.isAdaptive())) { return; } if (myStatusBeforeCheck == StudyStatus.Solved) { return; } StudyStatus statusAfterCheck = task.getStatus(); if (statusAfterCheck != StudyStatus.Solved) { return; } ProgressManager.getInstance().run(new com.intellij.openapi.progress.Task.Backgroundable(project, EduAdaptiveStepicConnector.LOADING_NEXT_RECOMMENDATION, false, PerformInBackgroundOption.DEAF) { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); EduAdaptiveStepicConnector.addNextRecommendedTask(project, task.getLesson(), indicator, EduAdaptiveStepicConnector.NEXT_RECOMMENDATION_REACTION); } }); }
Example 9
Project: educational-plugin File: OAuthDialog.java View source code | 6 votes |
@Override protected void doOKAction() { String code = myLoginPanel.getCode(); if (code == null || code.isEmpty()) return; ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> { ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true); myStepicUser = StudyUtils.execCancelable(() -> EduStepicAuthorizedClient.login(code, EduStepicNames.EXTERNAL_REDIRECT_URL)); if (myStepicUser != null) { doJustOkAction(); } else { setError("Login Failed"); } }, myProgressTitle, true, new DefaultProjectFactoryImpl().getDefaultProject()); }
Example 10
Project: educational-plugin File: StepicAdaptiveReactionsPanel.java View source code | 6 votes |
@Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 1 && isEnabled()) { final com.jetbrains.edu.learning.courseFormat.tasks.Task task = StudyUtils.getCurrentTask(myProject); if (task != null && task.getStatus() != StudyStatus.Solved) { final ProgressIndicatorBase progress = new ProgressIndicatorBase(); progress.setText(EduAdaptiveStepicConnector.LOADING_NEXT_RECOMMENDATION); ProgressManager.getInstance().run(new Task.Backgroundable(myProject, EduAdaptiveStepicConnector.LOADING_NEXT_RECOMMENDATION) { @Override public void run(@NotNull ProgressIndicator indicator) { StepicAdaptiveReactionsPanel.this.setEnabledRecursive(false); ApplicationManager.getApplication().invokeLater(()->setBackground(UIUtil.getLabelBackground())); EduAdaptiveStepicConnector.addNextRecommendedTask(StepicAdaptiveReactionsPanel.this.myProject, task.getLesson(), indicator, myReaction); StepicAdaptiveReactionsPanel.this.setEnabledRecursive(true); } }); } } }
Example 11
Project: educational-plugin File: RemoteCourse.java View source code | 6 votes |
public boolean isUpToDate() { if (id == 0) return true; if (!EduNames.STUDY.equals(courseMode)) return true; ProgressManager.getInstance().runProcessWithProgressAsynchronously(new Backgroundable(null, "Updating Course") { @Override public void run(@NotNull ProgressIndicator indicator) { final Date date = EduStepicConnector.getCourseUpdateDate(id); if (date == null) return; if (date.after(myUpdateDate)) { isUpToDate = false; } for (Lesson lesson : lessons) { if (!lesson.isUpToDate()) { isUpToDate = false; } } } }, new EmptyProgressIndicator()); return isUpToDate; }
Example 12
Project: educational-plugin File: EduCreateNewStepikProjectDialog.java View source code | 6 votes |
public EduCreateNewStepikProjectDialog(int courseId) { this(); StepicUser user = EduStepicAuthorizedClient.getCurrentUser(); Project defaultProject = ProjectManager.getInstance().getDefaultProject(); ApplicationManager.getApplication().invokeAndWait(() -> ProgressManager.getInstance() .runProcessWithProgressSynchronously(() -> { ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true); execCancelable(() -> { try { Course course = EduStepicConnector.getCourseFromStepik(user, courseId); if (course != null) { setTitle("New Project - " + course.getName()); } setCourse(course); } catch (IOException e) { LOG.warn("Tried to create a project for course with id=" + courseId, e); } return null; }); }, "Getting Available Courses", true, defaultProject) ); }
Example 13
Project: educational-plugin File: CCGetCourseFromStepic.java View source code | 6 votes |
@Override public void actionPerformed(@NotNull AnActionEvent e) { final IdeView view = e.getData(LangDataKeys.IDE_VIEW); final Project project = e.getData(CommonDataKeys.PROJECT); if (view == null || project == null) { return; } final String courseId = Messages.showInputDialog("Please, enter course id", "Get Course From Stepik", null); if (StringUtil.isNotEmpty(courseId)) { ProgressManager.getInstance().run(new Task.Modal(project, "Creating Course", true) { @Override public void run(@NotNull final ProgressIndicator indicator) { createCourse(project, courseId); } }); } }
Example 14
Project: manifold-ij File: HotSwapComponent.java View source code | 6 votes |
private Map<DebuggerSession, Map<String, HotSwapFile>> scanForModifiedClassesWithProgress( List<DebuggerSession> sessions, HotSwapProgressImpl progress ) { Ref<Map<DebuggerSession, Map<String, HotSwapFile>>> result = Ref.create( null ); ProgressManager.getInstance().runProcess( () -> { try { result.set( scanForModifiedClasses( sessions, progress ) ); } finally { progress.finished(); } }, progress.getProgressIndicator() ); return result.get(); }
Example 15
Project: intellij-ce-playground File: AntTasksProvider.java View source code | 6 votes |
@NotNull public Map<String, Class> getAntObjects() { while (true) { try { final Map<String, Class> map = myFuture.get(100, TimeUnit.MILLISECONDS); if (map != null) { return map; } } catch (TimeoutException ignore) { } catch (Exception e) { LOG.error(e); break; } ProgressManager.checkCanceled(); } return Collections.emptyMap(); }
Example 16
Project: intellij-ce-playground File: SelectLocationDialog.java View source code | 6 votes |
@Nullable private static SVNURL initRoot(final Project project, final SVNURL url) throws SvnBindException { final Ref<SVNURL> result = new Ref<SVNURL>(); final Ref<SvnBindException> excRef = new Ref<SvnBindException>(); ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() { public void run() { try { result.set(SvnUtil.getRepositoryRoot(SvnVcs.getInstance(project), url)); } catch (SvnBindException e) { excRef.set(e); } } }, "Detecting repository root", true, project); if (! excRef.isNull()) { throw excRef.get(); } return result.get(); }
Example 17
Project: intellij-ce-playground File: MarkLocallyDeletedTreeConflictResolvedAction.java View source code | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { final MyLocallyDeletedChecker locallyDeletedChecker = new MyLocallyDeletedChecker(e); if (! locallyDeletedChecker.isEnabled()) return; final String markText = SvnBundle.message("action.mark.tree.conflict.resolved.confirmation.title"); final Project project = locallyDeletedChecker.getProject(); final int result = Messages.showYesNoDialog(project, SvnBundle.message("action.mark.tree.conflict.resolved.confirmation.text"), markText, Messages.getQuestionIcon()); if (result == Messages.YES) { final Ref<VcsException> exception = new Ref<VcsException>(); ProgressManager .getInstance().run(new Task.Backgroundable(project, markText, true, BackgroundFromStartOption.getInstance()) { public void run(@NotNull ProgressIndicator indicator) { resolveLocallyDeletedTextConflict(locallyDeletedChecker, exception); } }); if (! exception.isNull()) { AbstractVcsHelper.getInstance(project).showError(exception.get(), markText); } } }
Example 18
Project: intellij-ce-playground File: FormReferencesSearcher.java View source code | 6 votes |
private static boolean processReferencesInFiles(List<PsiFile> files, PsiManager psiManager, String baseName, PsiElement element, LocalSearchScope filterScope, Processor<PsiReference> processor) { psiManager.startBatchFilesProcessingMode(); try { for (PsiFile file : files) { ProgressManager.checkCanceled(); if (file.getFileType() != StdFileTypes.GUI_DESIGNER_FORM) continue; if (!processReferences(processor, file, baseName, element, filterScope)) return false; } } finally { psiManager.finishBatchFilesProcessingMode(); } return true; }
Example 19
Project: intellij-ce-playground File: ControlFlowAnalyzer.java View source code | 6 votes |
private void generateThrow(@NotNull PsiClassType unhandledException, @NotNull PsiElement throwingElement) { final List<PsiElement> catchBlocks = findThrowToBlocks(unhandledException); for (PsiElement block : catchBlocks) { ProgressManager.checkCanceled(); ConditionalThrowToInstruction instruction = new ConditionalThrowToInstruction(0); myCurrentFlow.addInstruction(instruction); if (!patchCheckedThrowInstructionIfInsideFinally(instruction, throwingElement, block)) { if (block == null) { addElementOffsetLater(myCodeFragment, false); } else { instruction.offset--; // -1 for catch block param init addElementOffsetLater(block, true); } } } }
Example 20
Project: intellij-ce-playground File: ControlFlowAnalyzer.java View source code | 6 votes |
@Override public void visitCodeBlock(PsiCodeBlock block) { startElement(block); int prevOffset = myCurrentFlow.getSize(); PsiStatement[] statements = block.getStatements(); for (PsiStatement statement : statements) { ProgressManager.checkCanceled(); statement.accept(this); } //each statement should contain at least one instruction in order to getElement(offset) work int nextOffset = myCurrentFlow.getSize(); if (!(block.getParent() instanceof PsiSwitchStatement) && prevOffset == nextOffset) { emitEmptyInstruction(); } finishElement(block); if (prevOffset != 0) { registerSubRange(block, prevOffset); } }
Example 21
Project: intellij-ce-playground File: ControlFlowAnalyzer.java View source code | 6 votes |
@Override public void visitDeclarationStatement(PsiDeclarationStatement statement) { startElement(statement); int pc = myCurrentFlow.getSize(); PsiElement[] elements = statement.getDeclaredElements(); for (PsiElement element : elements) { ProgressManager.checkCanceled(); if (element instanceof PsiClass) { element.accept(this); } else if (element instanceof PsiVariable) { processVariable((PsiVariable)element); } } if (pc == myCurrentFlow.getSize()) { // generate at least one instruction for declaration emitEmptyInstruction(); } finishElement(statement); }
Example 22
Project: intellij-ce-playground File: ResolveUtil.java View source code | 6 votes |
public static boolean doTreeWalkUp(@NotNull final PsiElement place, @NotNull final PsiElement originalPlace, @NotNull final PsiScopeProcessor processor, @Nullable final PsiScopeProcessor nonCodeProcessor, @NotNull final ResolveState state) { final GrClosableBlock maxScope = nonCodeProcessor != null ? PsiTreeUtil.getParentOfType(place, GrClosableBlock.class, true, PsiFile.class) : null; return PsiTreeUtil.treeWalkUp(place, maxScope, new PairProcessor<PsiElement, PsiElement>() { @Override public boolean process(PsiElement scope, PsiElement lastParent) { ProgressManager.checkCanceled(); if (!doProcessDeclarations(originalPlace, lastParent, scope, substituteProcessor(processor, scope), nonCodeProcessor, state)) { return false; } issueLevelChangeEvents(processor, scope); return true; } }); }
Example 23
Project: intellij-ce-playground File: DefaultHighlightVisitor.java View source code | 6 votes |
private void runAnnotators(PsiElement element) { List<Annotator> annotators = cachedAnnotators.get(element.getLanguage().getID()); if (annotators.isEmpty()) return; final boolean dumb = myDumbService.isDumb(); //noinspection ForLoopReplaceableByForEach for (int i = 0; i < annotators.size(); i++) { Annotator annotator = annotators.get(i); if (dumb && !DumbService.isDumbAware(annotator)) { continue; } ProgressManager.checkCanceled(); annotator.annotate(element, myAnnotationHolder); } }
Example 24
Project: intellij-ce-playground File: RepositoryBrowserDialog.java View source code | 6 votes |
private void doCopy(final SVNURL src, final SVNURL dst, final boolean move, final String comment) { final Ref<Exception> exception = new Ref<Exception>(); Runnable command = new Runnable() { public void run() { ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator(); if (progress != null) { progress.setText((move ? SvnBundle.message("progress.text.browser.moving", src) : SvnBundle.message("progress.text.browser.copying", src))); progress.setText2(SvnBundle.message("progress.text.browser.remote.destination", dst)); } SvnVcs vcs = SvnVcs.getInstance(myProject); try { vcs.getFactoryFromSettings().createCopyMoveClient().copy(SvnTarget.fromURL(src), SvnTarget.fromURL(dst), SVNRevision.HEAD, true, move, comment, null); } catch (VcsException e) { exception.set(e); } } }; String progressTitle = move ? SvnBundle.message("progress.title.browser.move") : SvnBundle.message("progress.title.browser.copy"); ProgressManager.getInstance().runProcessWithProgressSynchronously(command, progressTitle, false, myProject); if (!exception.isNull()) { Messages.showErrorDialog(exception.get().getMessage(), SvnBundle.message("message.text.error")); } }
Example 25
Project: intellij-ce-playground File: AnalysisScope.java View source code | 6 votes |
private static boolean processFile(@NotNull final VirtualFile vFile, @NotNull final PsiElementVisitor visitor, @NotNull final PsiManager psiManager, final boolean needReadAction, final boolean clearResolveCache) { final Runnable runnable = new Runnable() { @Override public void run() { doProcessFile(visitor, psiManager, vFile, clearResolveCache); } }; if (needReadAction && !ApplicationManager.getApplication().isDispatchThread()) { commitAndRunInSmartMode(runnable, psiManager.getProject()); } else { runnable.run(); } final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); return indicator == null || !indicator.isCanceled(); }
Example 26
Project: intellij-ce-playground File: SingleTargetRequestResultProcessor.java View source code | 6 votes |
@Override public boolean processTextOccurrence(@NotNull PsiElement element, int offsetInElement, @NotNull final Processor<PsiReference> consumer) { if (!myTarget.isValid()) { return false; } final List<PsiReference> references = ourReferenceService.getReferences(element, new PsiReferenceService.Hints(myTarget, offsetInElement)); //noinspection ForLoopReplaceableByForEach for (int i = 0; i < references.size(); i++) { PsiReference ref = references.get(i); ProgressManager.checkCanceled(); if (ReferenceRange.containsOffsetInElement(ref, offsetInElement) && ref.isReferenceTo(myTarget) && !consumer.process(ref)) { return false; } } return true; }
Example 27
Project: intellij-ce-playground File: VcsSynchronousProgressWrapper.java View source code | 6 votes |
public static boolean wrap(final ThrowableRunnable<VcsException> runnable, final Project project, final String title) { final VcsException[] exc = new VcsException[1]; final Runnable process = new Runnable() { @Override public void run() { try { runnable.run(); } catch (VcsException e) { exc[0] = e; } } }; final boolean notCanceled; if (ApplicationManager.getApplication().isDispatchThread()) { notCanceled = ProgressManager.getInstance().runProcessWithProgressSynchronously(process, title, true, project); } else { process.run(); notCanceled = true; } if (exc[0] != null) { AbstractVcsHelper.getInstance(project).showError(exc[0], title); return false; } return notCanceled; }
Example 28
Project: intellij-ce-playground File: SvnLogUtil.java View source code | 6 votes |
@NotNull private LogEntryConsumer createLogHandler(final SVNRevision fromIncluding, final SVNRevision toIncluding, final boolean includingYoungest, final boolean includeOldest, final List<CommittedChangeList> result) { return new LogEntryConsumer() { @Override public void consume(LogEntry logEntry) { if (myProject.isDisposed()) throw new ProcessCanceledException(); final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator(); if (progress != null) { progress.setText2(SvnBundle.message("progress.text2.processing.revision", logEntry.getRevision())); progress.checkCanceled(); } if ((!includingYoungest) && (logEntry.getRevision() == fromIncluding.getNumber())) { return; } if ((!includeOldest) && (logEntry.getRevision() == toIncluding.getNumber())) { return; } result.add(new SvnChangeList(myVcs, myLocation, logEntry, myRepositoryRoot.toString())); } }; }
Example 29
Project: intellij-ce-playground File: CCPushLesson.java View source code | 6 votes |
@Override public void actionPerformed(@NotNull AnActionEvent e) { final IdeView view = e.getData(LangDataKeys.IDE_VIEW); final Project project = e.getData(CommonDataKeys.PROJECT); if (view == null || project == null) { return; } final Course course = CCProjectService.getInstance(project).getCourse(); if (course == null) { return; } PsiDirectory lessonDir = DirectoryChooserUtil.getOrChooseDirectory(view); if (lessonDir == null || !lessonDir.getName().contains("lesson")) { return; } final Lesson lesson = course.getLesson(lessonDir.getName()); if (lesson == null) { return; } ProgressManager.getInstance().run(new Task.Modal(project, "Uploading Lesson", true) { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setText("Uploading lesson to http://stepic.org"); EduStepicConnector.updateLesson(project, lesson, indicator); }}); }
Example 30
Project: intellij-ce-playground File: CommitHelper.java View source code | 6 votes |
public void customRefresh() { final List<Change> toRefresh = new ArrayList<Change>(); ChangesUtil.processChangesByVcs(myProject, myIncludedChanges, new ChangesUtil.PerVcsProcessor<Change>() { @Override public void process(AbstractVcs vcs, List<Change> items) { CheckinEnvironment ce = vcs.getCheckinEnvironment(); if (ce != null && ce.isRefreshAfterCommitNeeded()) { toRefresh.addAll(items); } } }); if (toRefresh.isEmpty()) { return; } final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); if (indicator != null) { indicator.setText(VcsBundle.message("commit.dialog.refresh.files")); } RefreshVFsSynchronously.updateChanges(toRefresh); }
Example 31
Project: intellij-ce-playground File: AbstractTerminalRunner.java View source code | 6 votes |
public void run() { ProgressManager.getInstance().run(new Task.Backgroundable(myProject, "Running the terminal", false) { public void run(@NotNull final ProgressIndicator indicator) { indicator.setText("Running the terminal..."); try { doRun(); } catch (final Exception e) { LOG.warn("Error running terminal", e); UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { Messages.showErrorDialog(AbstractTerminalRunner.this.getProject(), e.getMessage(), getTitle()); } }); } } }); }
Example 32
Project: intellij-ce-playground File: SpellCheckerDictionaryGenerator.java View source code | 6 votes |
public void generate() { ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() { @Override public void run() { ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator(); // let's do result a bit more predictable // ruby dictionary generate(myDefaultDictName, progressIndicator); // other gem-related dictionaries in alphabet order final List<String> dictionaries = new ArrayList<String>(myDict2FolderMap.keySet()); Collections.sort(dictionaries); for (String dict : dictionaries) { if (myDefaultDictName.equals(dict)) { continue; } generate(dict, progressIndicator); } } }, "Generating Dictionaries", false, myProject); }
Example 33
Project: intellij-ce-playground File: VcsBackgroundableComputable.java View source code | 6 votes |
private static <T> void createAndRun(final Project project, @Nullable final VcsBackgroundableActions actionKey, @Nullable final Object actionParameter, final String title, final String errorTitle, final ThrowableComputable<T, VcsException> backgroundable, @Nullable final Consumer<T> awtSuccessContinuation, @Nullable final Runnable awtErrorContinuation, final boolean silent) { final ProjectLevelVcsManagerImpl vcsManager = (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(project); final BackgroundableActionEnabledHandler handler; if (actionKey != null) { handler = vcsManager.getBackgroundableActionHandler(actionKey); // fo not start same action twice if (handler.isInProgress(actionParameter)) return; } else { handler = null; } final VcsBackgroundableComputable<T> backgroundableComputable = new VcsBackgroundableComputable<T>(project, title, errorTitle, backgroundable, awtSuccessContinuation, awtErrorContinuation, handler, actionParameter); backgroundableComputable.setSilent(silent); if (handler != null) { handler.register(actionParameter); } ProgressManager.getInstance().run(backgroundableComputable); }
Example 34
Project: intellij-ce-playground File: CloneDvcsDialog.java View source code | 6 votes |
private void test() { myTestURL = getCurrentUrlText(); boolean testResult = ProgressManager.getInstance().runProcessWithProgressSynchronously(new ThrowableComputable<Boolean, RuntimeException>() { @Override public Boolean compute() { return test(myTestURL); } }, DvcsBundle.message("clone.testing", myTestURL), true, myProject); if (testResult) { Messages.showInfoMessage(myTestButton, DvcsBundle.message("clone.test.success.message", myTestURL), DvcsBundle.getString("clone.test.connection.title")); myTestResult = Boolean.TRUE; } else { myTestResult = Boolean.FALSE; } updateButtons(); }
Example 35
Project: intellij-ce-playground File: BaseCoverageAnnotator.java View source code | 6 votes |
public void renewCoverageData(@NotNull final CoverageSuitesBundle suite, @NotNull final CoverageDataManager dataManager) { final Runnable request = createRenewRequest(suite, dataManager); if (request != null) { if (myProject.isDisposed()) return; ProgressManager.getInstance().run(new Task.Backgroundable(myProject, "Loading Coverage Data", false) { @Override public void run(@NotNull ProgressIndicator indicator) { request.run(); } @Override public void onSuccess() { final CoverageView coverageView = CoverageViewManager.getInstance(myProject).getToolwindow(suite); if (coverageView != null) { coverageView.updateParentTitle(); } } }); } }
Example 36
Project: intellij-ce-playground File: DefaultChooseByNameItemProvider.java View source code | 6 votes |
private static void processNamesByPattern(@NotNull final ChooseByNameBase base, @NotNull final String[] names, @NotNull final String pattern, final ProgressIndicator indicator, @NotNull final Consumer<MatchResult> consumer) { final MinusculeMatcher matcher = buildPatternMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE); Processor<String> processor = new Processor<String>() { @Override public boolean process(String name) { ProgressManager.checkCanceled(); MatchResult result = matches(base, pattern, matcher, name); if (result != null) { consumer.consume(result); } return true; } }; if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Arrays.asList(names), indicator, false, true, processor)) { throw new ProcessCanceledException(); } }
Example 37
Project: intellij-ce-playground File: WaitForProgressToShow.java View source code | 6 votes |
public static void execute(ProgressIndicator pi) { if (pi.isShowing()) { final long maxWait = 3000; final long start = System.currentTimeMillis(); while ((! pi.isPopupWasShown()) && (pi.isRunning()) && (System.currentTimeMillis() - maxWait < start)) { final Object lock = new Object(); synchronized (lock) { try { lock.wait(100); } catch (InterruptedException e) { // } } } ProgressManager.checkCanceled(); } }
Example 38
Project: intellij-ce-playground File: DvcsCommitAdditionalComponent.java View source code | 6 votes |
private void loadMessagesInModalTask(@NotNull Project project) { try { myMessagesForRoots = ProgressManager.getInstance().runProcessWithProgressSynchronously(new ThrowableComputable<Map<VirtualFile,String>, VcsException>() { @Override public Map<VirtualFile, String> compute() throws VcsException { return getLastCommitMessages(); } }, "Reading commit message...", false, project); } catch (VcsException e) { Messages.showErrorDialog(getComponent(), "Couldn't load commit message of the commit to amend.\n" + e.getMessage(), "Commit Message not Loaded"); log.info(e); } }
Example 39
Project: intellij-ce-playground File: GitHandlerUtil.java View source code | 6 votes |
/** * Execute simple process synchronously with progress * * @param handler a handler * @param operationTitle an operation title shown in progress dialog * @param operationName an operation name shown in failure dialog * @return A stdout content or null if there was error (exit code != 0 or exception during start). */ @Nullable public static String doSynchronously(final GitSimpleHandler handler, final String operationTitle, @NonNls final String operationName) { handler.addListener(new GitHandlerListenerBase(handler, operationName) { protected String getErrorText() { String text = handler.getStderr(); if (text.length() == 0) { text = handler.getStdout(); } return text; } }); final ProgressManager manager = ProgressManager.getInstance(); manager.runProcessWithProgressSynchronously(new Runnable() { public void run() { runInCurrentThread(handler, manager.getProgressIndicator(), true, operationTitle); } }, operationTitle, false, handler.project()); if (!handler.isStarted() || handler.getExitCode() != 0) { return null; } return handler.getStdout(); }
Example 40
Project: intellij-ce-playground File: AbstractFileProcessor.java View source code | 6 votes |
private void execute(final Runnable readAction, final Runnable writeAction) { ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() { @Override public void run() { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { readAction.run(); } }); } }, title, true, myProject); new WriteCommandAction(myProject, title) { @Override protected void run(@NotNull Result result) throws Throwable { writeAction.run(); } }.execute(); }