Search in sources :

Example 51 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class SearchCommand method startSearching.

public void startSearching() {
    final UsageViewContext context = createUsageViewContext();
    final UsageViewPresentation presentation = new UsageViewPresentation();
    presentation.setOpenInNewTab(FindSettings.getInstance().isShowResultsInSeparateView());
    context.configure(presentation);
    final FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation(presentation);
    processPresentation.setShowNotFoundMessage(true);
    processPresentation.setShowPanelIfOnlyOneUsage(true);
    processPresentation.setProgressIndicatorFactory(new Factory<ProgressIndicator>() {

        @Override
        public ProgressIndicator create() {
            FindProgressIndicator indicator = new FindProgressIndicator(mySearchContext.getProject(), presentation.getScopeText());
            indicator.addStateDelegate(new AbstractProgressIndicatorExBase() {

                @Override
                public void cancel() {
                    super.cancel();
                    stopAsyncSearch();
                }
            });
            return indicator;
        }
    });
    PsiDocumentManager.getInstance(mySearchContext.getProject()).commitAllDocuments();
    final ConfigurableUsageTarget target = context.getTarget();
    ((FindManagerImpl) FindManager.getInstance(mySearchContext.getProject())).getFindUsagesManager().addToHistory(target);
    UsageViewManager.getInstance(mySearchContext.getProject()).searchAndShowUsages(new UsageTarget[] { target }, () -> new UsageSearcher() {

        @Override
        public void generate(@NotNull final Processor<Usage> processor) {
            findUsages(processor);
        }
    }, processPresentation, presentation, new UsageViewManager.UsageViewStateListener() {

        @Override
        public void usageViewCreated(@NotNull UsageView usageView) {
            context.setUsageView(usageView);
            context.configureActions();
        }

        @Override
        public void findingUsagesFinished(final UsageView usageView) {
        }
    });
}
Also used : AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) FindProgressIndicator(com.intellij.find.FindProgressIndicator) FindProgressIndicator(com.intellij.find.FindProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 52 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class SearchCommand method findUsages.

public void findUsages(final Processor<Usage> processor) {
    final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
    final MatchResultSink sink = new MatchResultSink() {

        int count;

        public void setMatchingProcess(MatchingProcess _process) {
            process = _process;
            findStarted();
        }

        public void processFile(PsiFile element) {
            final VirtualFile virtualFile = element.getVirtualFile();
            if (virtualFile != null)
                progress.setText(SSRBundle.message("looking.in.progress.message", virtualFile.getPresentableName()));
        }

        public void matchingFinished() {
            if (mySearchContext.getProject().isDisposed())
                return;
            findEnded();
            progress.setText(SSRBundle.message("found.progress.message", count));
        }

        public ProgressIndicator getProgressIndicator() {
            return progress;
        }

        public void newMatch(MatchResult result) {
            UsageInfo info;
            if (MatchResult.MULTI_LINE_MATCH.equals(result.getName())) {
                int start = -1;
                int end = -1;
                PsiElement parent = result.getMatch().getParent();
                for (final MatchResult matchResult : ((MatchResultImpl) result).getMatches()) {
                    PsiElement el = matchResult.getMatch();
                    final int elementStart = el.getTextRange().getStartOffset();
                    if (start == -1 || start > elementStart) {
                        start = elementStart;
                    }
                    final int newend = elementStart + el.getTextLength();
                    if (newend > end) {
                        end = newend;
                    }
                }
                final int parentStart = parent.getTextRange().getStartOffset();
                int startOffset = start - parentStart;
                info = new UsageInfo(parent, startOffset, end - parentStart);
            } else {
                info = new UsageInfo(StructuralSearchUtil.getPresentableElement(result.getMatch()));
            }
            Usage usage = new UsageInfo2UsageAdapter(info);
            processor.process(usage);
            foundUsage(result, usage);
            ++count;
        }
    };
    try {
        new Matcher(mySearchContext.getProject()).findMatches(sink, myConfiguration.getMatchOptions());
    } catch (final StructuralSearchException e) {
        final Alarm alarm = new Alarm();
        alarm.addRequest(() -> NotificationGroup.toolWindowGroup("Structural Search", ToolWindowId.FIND).createNotification(SSRBundle.message("problem", e.getMessage()), MessageType.ERROR).notify(mySearchContext.getProject()), 100, ModalityState.NON_MODAL);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FindProgressIndicator(com.intellij.find.FindProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Alarm(com.intellij.util.Alarm) MatchResultImpl(com.intellij.structuralsearch.impl.matcher.MatchResultImpl) PsiFile(com.intellij.psi.PsiFile) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement)

Example 53 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class SearchForUsagesRunnable method searchUsages.

private void searchUsages(@NotNull final AtomicBoolean findStartedBalloonShown) {
    ProgressIndicator indicator = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
    assert indicator != null : "must run find usages under progress";
    TooManyUsagesStatus.createFor(indicator);
    Alarm findUsagesStartedBalloon = new Alarm();
    findUsagesStartedBalloon.addRequest(() -> {
        notifyByFindBalloon(null, MessageType.WARNING, myProcessPresentation, myProject, Collections.singletonList(StringUtil.escapeXml(UsageViewManagerImpl.getProgressTitle(myPresentation))));
        findStartedBalloonShown.set(true);
    }, 300, ModalityState.NON_MODAL);
    UsageSearcher usageSearcher = mySearcherFactory.create();
    usageSearcher.generate(usage -> {
        ProgressIndicator indicator1 = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
        assert indicator1 != null : "must run find usages under progress";
        if (indicator1.isCanceled())
            return false;
        if (!UsageViewManagerImpl.isInScope(usage, mySearchScopeToWarnOfFallingOutOf)) {
            myOutOfScopeUsages.incrementAndGet();
            return true;
        }
        boolean incrementCounter = !UsageViewManager.isSelfUsage(usage, mySearchFor);
        if (incrementCounter) {
            final int usageCount = myUsageCountWithoutDefinition.incrementAndGet();
            if (usageCount == 1 && !myProcessPresentation.isShowPanelIfOnlyOneUsage()) {
                myFirstUsage.compareAndSet(null, usage);
            }
            final UsageViewImpl usageView = getUsageView(indicator1);
            TooManyUsagesStatus tooManyUsagesStatus = TooManyUsagesStatus.getFrom(indicator1);
            if (usageCount > UsageLimitUtil.USAGES_LIMIT && tooManyUsagesStatus.switchTooManyUsagesStatus()) {
                UsageViewManagerImpl.showTooManyUsagesWarning(myProject, tooManyUsagesStatus, indicator1, myPresentation, usageCount, usageView);
            }
            tooManyUsagesStatus.pauseProcessingIfTooManyUsages();
            if (usageView != null) {
                ApplicationManager.getApplication().runReadAction(() -> usageView.appendUsage(usage));
            }
        }
        return !indicator1.isCanceled();
    });
    if (getUsageView(indicator) != null) {
        ApplicationManager.getApplication().invokeLater(() -> myUsageViewManager.showToolWindow(true), myProject.getDisposed());
    }
    Disposer.dispose(findUsagesStartedBalloon);
    ApplicationManager.getApplication().invokeLater(() -> {
        if (findStartedBalloonShown.get()) {
            Balloon balloon = ToolWindowManager.getInstance(myProject).getToolWindowBalloon(ToolWindowId.FIND);
            if (balloon != null) {
                balloon.hide();
            }
        }
    }, myProject.getDisposed());
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Alarm(com.intellij.util.Alarm) Balloon(com.intellij.openapi.ui.popup.Balloon) TooManyUsagesStatus(com.intellij.openapi.progress.util.TooManyUsagesStatus)

Example 54 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class ShowDiffFromAnnotation method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final int actualNumber = currentLine;
    if (actualNumber < 0)
        return;
    final VcsRevisionNumber revisionNumber = myFileAnnotation.getLineRevisionNumber(actualNumber);
    if (revisionNumber != null) {
        final VcsException[] exc = new VcsException[1];
        final List<Change> changes = new LinkedList<>();
        final FilePath[] targetPath = new FilePath[1];
        ProgressManager.getInstance().run(new Task.Backgroundable(myVcs.getProject(), "Loading revision " + revisionNumber.asString() + " contents", true) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                final CommittedChangesProvider provider = myVcs.getCommittedChangesProvider();
                try {
                    final Pair<CommittedChangeList, FilePath> pair = provider.getOneList(myFile, revisionNumber);
                    if (pair == null || pair.getFirst() == null) {
                        VcsBalloonProblemNotifier.showOverChangesView(myVcs.getProject(), "Can not load data for show diff", MessageType.ERROR);
                        return;
                    }
                    targetPath[0] = pair.getSecond() == null ? VcsUtil.getFilePath(myFile) : pair.getSecond();
                    final CommittedChangeList cl = pair.getFirst();
                    changes.addAll(cl.getChanges());
                    Collections.sort(changes, ChangesComparator.getInstance(true));
                } catch (VcsException e1) {
                    exc[0] = e1;
                }
            }

            @Override
            public void onSuccess() {
                if (exc[0] != null) {
                    VcsBalloonProblemNotifier.showOverChangesView(myVcs.getProject(), "Can not show diff: " + exc[0].getMessage(), MessageType.ERROR);
                } else if (!changes.isEmpty()) {
                    int idx = findSelfInList(changes, targetPath[0]);
                    final ShowDiffContext context = new ShowDiffContext(DiffDialogHints.FRAME);
                    if (idx != -1) {
                        context.putChangeContext(changes.get(idx), DiffUserDataKeysEx.NAVIGATION_CONTEXT, createDiffNavigationContext(actualNumber));
                    }
                    if (ChangeListManager.getInstance(myVcs.getProject()).isFreezedWithNotification(null))
                        return;
                    ShowDiffAction.showDiffForChange(myVcs.getProject(), changes, idx, context);
                }
            }
        });
    }
}
Also used : Task(com.intellij.openapi.progress.Task) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) ShowDiffContext(com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext) Change(com.intellij.openapi.vcs.changes.Change) LinkedList(java.util.LinkedList) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) Pair(com.intellij.openapi.util.Pair)

Example 55 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class AnnotateVcsVirtualFileAction method doAnnotate.

private static void doAnnotate(@NotNull final Project project, @NotNull final Editor editor, @NotNull final VirtualFile file) {
    final AnnotationData data = extractData(project, file);
    assert data != null;
    final AnnotationProviderEx provider = (AnnotationProviderEx) data.vcs.getAnnotationProvider();
    assert provider != null;
    final Ref<FileAnnotation> fileAnnotationRef = new Ref<>();
    final Ref<VcsException> exceptionRef = new Ref<>();
    VcsAnnotateUtil.getBackgroundableLock(project, file).lock();
    final Task.Backgroundable annotateTask = new Task.Backgroundable(project, VcsBundle.message("retrieving.annotations"), true) {

        @Override
        public void run(@NotNull final ProgressIndicator indicator) {
            try {
                fileAnnotationRef.set(provider.annotate(data.filePath, data.revisionNumber));
            } catch (VcsException e) {
                exceptionRef.set(e);
            } catch (ProcessCanceledException pce) {
                throw pce;
            } catch (Throwable t) {
                exceptionRef.set(new VcsException(t));
            }
        }

        @Override
        public void onCancel() {
            onSuccess();
        }

        @Override
        public void onSuccess() {
            VcsAnnotateUtil.getBackgroundableLock(project, file).unlock();
            if (!exceptionRef.isNull()) {
                LOG.warn(exceptionRef.get());
                AbstractVcsHelper.getInstance(project).showErrors(Collections.singletonList(exceptionRef.get()), VcsBundle.message("message.title.annotate"));
            }
            if (!fileAnnotationRef.isNull()) {
                AnnotateToggleAction.doAnnotate(editor, project, null, fileAnnotationRef.get(), data.vcs);
            }
        }
    };
    ProgressManager.getInstance().run(annotateTask);
}
Also used : Task(com.intellij.openapi.progress.Task) AnnotationProviderEx(com.intellij.vcs.AnnotationProviderEx) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)352 Task (com.intellij.openapi.progress.Task)139 NotNull (org.jetbrains.annotations.NotNull)98 VirtualFile (com.intellij.openapi.vfs.VirtualFile)96 Project (com.intellij.openapi.project.Project)78 File (java.io.File)52 IOException (java.io.IOException)48 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)44 Nullable (org.jetbrains.annotations.Nullable)43 ProgressManager (com.intellij.openapi.progress.ProgressManager)35 List (java.util.List)30 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)28 Ref (com.intellij.openapi.util.Ref)27 VcsException (com.intellij.openapi.vcs.VcsException)25 ArrayList (java.util.ArrayList)23 ApplicationManager (com.intellij.openapi.application.ApplicationManager)22 Module (com.intellij.openapi.module.Module)21 Logger (com.intellij.openapi.diagnostic.Logger)20 java.util (java.util)20 Processor (com.intellij.util.Processor)18