From 6a0d3921539b5dc6c775b23d32b5989b3d0b47e7 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 31 Aug 2011 16:43:15 +0200 Subject: [PATCH] show definitions: update in background according to filter --- .../hint/ImplementationViewComponent.java | 18 +++++++++- .../actions/ShowImplementationsAction.java | 35 +++++++++++++++---- .../navigation/BackgroundUpdaterTask.java | 6 +++- .../navigation/ListBackgroundUpdaterTask.java | 4 +-- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewComponent.java index 8ee54bd6b9f1..68ac5f8bbc00 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewComponent.java @@ -18,6 +18,8 @@ package com.intellij.codeInsight.hint; import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.ide.highlighter.HighlighterFactory; import com.intellij.ide.ui.ListCellRendererWrapper; +import com.intellij.navigation.ItemPresentation; +import com.intellij.navigation.NavigationItem; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; @@ -50,6 +52,7 @@ import com.intellij.usages.UsageViewManager; import com.intellij.usages.UsageViewPresentation; import com.intellij.util.PairFunction; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import javax.swing.*; @@ -100,7 +103,20 @@ public class ImplementationViewComponent extends JPanel { public FileDescriptor(PsiFile file, PsiElement element) { myFile = file; - myElementPresentation = SymbolPresentationUtil.getSymbolPresentableText(element); + myElementPresentation = getPresentation(element); + } + + @Nullable + private static String getPresentation(PsiElement element) { + if (element instanceof NavigationItem) { + final ItemPresentation presentation = ((NavigationItem)element).getPresentation(); + if (presentation != null) { + return presentation.getPresentableText(); + } + } + + if (element instanceof PsiNamedElement) return ((PsiNamedElement)element).getName(); + return null; } public String getPresentableName(VirtualFile vFile) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java index 447920b48491..7f0f7c160bca 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java @@ -299,6 +299,7 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { private String myCaption; private Editor myEditor; private PsiElement myElement; + private PsiElement[] myElements; public ImplementationsUpdaterTask(final PsiElement element, final Editor editor, final String caption) { super(element.getProject(), ImplementationSearcher.SEARCHING_FOR_IMPLEMENTATIONS); @@ -318,7 +319,7 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { } @Override - protected void replaceModel(ArrayList data) { + protected void replaceModel(List data) { final PsiElement[] elements = myComponent.getElements(); final int includeSelfIdx = myElement instanceof PomTargetPsiElement ? 0 : 1; final int startIdx = elements.length - includeSelfIdx; @@ -331,12 +332,32 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { @Override public void run(@NotNull ProgressIndicator indicator) { super.run(indicator); - getSelfAndImplementations(myEditor, myElement, new ImplementationSearcher.BackgroundableImplementationSearcher() { - @Override - protected void processElement(PsiElement element) { - updateComponent(element, null); - } - }); + myElements = + getSelfAndImplementations(myEditor, myElement, new ImplementationSearcher.BackgroundableImplementationSearcher() { + @Override + protected void processElement(PsiElement element) { + updateComponent(element, null); + } + + @Override + protected PsiElement[] filterElements(PsiElement element, PsiElement[] targetElements, int offset) { + return ShowImplementationsAction.filterElements(targetElements); + } + }); + } + + @Override + public int getCurrentSize() { + if (myElements != null) return myElements.length; + return super.getCurrentSize(); + } + + @Override + public void onSuccess() { + if (!isCanceled()) { + myComponent.update(myElements, myComponent.getIndex()); + } + super.onSuccess(); } } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/BackgroundUpdaterTask.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/BackgroundUpdaterTask.java index 96257225c872..41d9cdf332aa 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/BackgroundUpdaterTask.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/BackgroundUpdaterTask.java @@ -75,13 +75,17 @@ public abstract class BackgroundUpdaterTask extends Task.Backgroundable { } public abstract String getCaption(int size); - protected abstract void replaceModel(ArrayList data); + protected abstract void replaceModel(List data); protected abstract void paintBusy(boolean paintBusy); public void setCanceled() { myCanceled = true; } + public boolean isCanceled() { + return myCanceled; + } + public void updateComponent(PsiElement element, @Nullable final Comparator comparator) { if (myCanceled) return; if (myPopup.isDisposed()) return; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/ListBackgroundUpdaterTask.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/ListBackgroundUpdaterTask.java index 88fbbf759441..30b1db8e47d0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/ListBackgroundUpdaterTask.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/ListBackgroundUpdaterTask.java @@ -23,7 +23,7 @@ import com.intellij.ui.speedSearch.NameFilteringListModel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; +import java.util.List; /** * User: anna @@ -51,7 +51,7 @@ public abstract class ListBackgroundUpdaterTask extends BackgroundUpdaterTask data) { + protected void replaceModel(List data) { final Object selectedValue = myComponent.getSelectedValue(); final int index = myComponent.getSelectedIndex(); ((NameFilteringListModel)myComponent.getModel()).replaceAll(data);