Search in sources :

Example 1 with UsageViewImpl

use of com.intellij.usages.impl.UsageViewImpl in project intellij-community by JetBrains.

the class BackgroundUpdaterTask method updateComponent.

public boolean updateComponent(final PsiElement element, @Nullable final Comparator comparator) {
    final UsageView view = myUsageView.get();
    if (view != null && !((UsageViewImpl) view).isDisposed()) {
        ApplicationManager.getApplication().runReadAction(() -> view.appendUsage(new UsageInfo2UsageAdapter(new UsageInfo(element))));
        return true;
    }
    if (myCanceled)
        return false;
    final JComponent content = myPopup.getContent();
    if (content == null || myPopup.isDisposed())
        return false;
    synchronized (lock) {
        if (myData.contains(element))
            return true;
        myData.add(element);
        if (comparator != null) {
            Collections.sort(myData, comparator);
        }
    }
    myAlarm.addRequest(() -> {
        myAlarm.cancelAllRequests();
        refreshModelImmediately();
    }, 200, ModalityState.stateForComponent(content));
    return true;
}
Also used : UsageView(com.intellij.usages.UsageView) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) UsageViewImpl(com.intellij.usages.impl.UsageViewImpl) UsageInfo(com.intellij.usageView.UsageInfo)

Example 2 with UsageViewImpl

use of com.intellij.usages.impl.UsageViewImpl in project intellij-community by JetBrains.

the class FindUtil method showInUsageView.

@Nullable
public static UsageView showInUsageView(@Nullable PsiElement sourceElement, @NotNull PsiElement[] targets, @NotNull String title, @NotNull final Project project) {
    if (targets.length == 0)
        return null;
    final UsageViewPresentation presentation = new UsageViewPresentation();
    presentation.setCodeUsagesString(title);
    presentation.setTabName(title);
    presentation.setTabText(title);
    UsageTarget[] usageTargets = sourceElement == null ? UsageTarget.EMPTY_ARRAY : new UsageTarget[] { new PsiElement2UsageTargetAdapter(sourceElement) };
    PsiElement[] primary = sourceElement == null ? PsiElement.EMPTY_ARRAY : new PsiElement[] { sourceElement };
    UsageView view = UsageViewManager.getInstance(project).showUsages(usageTargets, Usage.EMPTY_ARRAY, presentation);
    SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(project);
    List<SmartPsiElementPointer> pointers = ContainerUtil.map(targets, smartPointerManager::createSmartPsiElementPointer);
    // usage view will load document/AST so still referencing all these PSI elements might lead to out of memory
    //noinspection UnusedAssignment
    targets = PsiElement.EMPTY_ARRAY;
    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Updating Usage View ...") {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            for (final SmartPsiElementPointer pointer : pointers) {
                if (((UsageViewImpl) view).isDisposed())
                    break;
                ApplicationManager.getApplication().runReadAction(() -> {
                    final PsiElement target = pointer.getElement();
                    if (target != null) {
                        view.appendUsage(UsageInfoToUsageConverter.convert(primary, new UsageInfo(target)));
                    }
                });
            }
            UIUtil.invokeLaterIfNeeded(((UsageViewImpl) view)::expandAll);
        }
    });
    return view;
}
Also used : Task(com.intellij.openapi.progress.Task) PsiElement2UsageTargetAdapter(com.intellij.find.findUsages.PsiElement2UsageTargetAdapter) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) UsageViewImpl(com.intellij.usages.impl.UsageViewImpl) UsageInfo(com.intellij.usageView.UsageInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with UsageViewImpl

use of com.intellij.usages.impl.UsageViewImpl in project intellij-community by JetBrains.

the class RerunSearchAction method update.

@Override
public void update(@NotNull AnActionEvent e) {
    UsageView usageView = UsageView.USAGE_VIEW_KEY.getData(e.getDataContext());
    boolean enabled = usageView instanceof UsageViewImpl && ((UsageViewImpl) usageView).canPerformReRun();
    e.getPresentation().setEnabled(enabled);
}
Also used : UsageView(com.intellij.usages.UsageView) UsageViewImpl(com.intellij.usages.impl.UsageViewImpl)

Aggregations

UsageViewImpl (com.intellij.usages.impl.UsageViewImpl)3 UsageInfo (com.intellij.usageView.UsageInfo)2 UsageView (com.intellij.usages.UsageView)2 PsiElement2UsageTargetAdapter (com.intellij.find.findUsages.PsiElement2UsageTargetAdapter)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 UsageInfo2UsageAdapter (com.intellij.usages.UsageInfo2UsageAdapter)1 Nullable (org.jetbrains.annotations.Nullable)1