Select in project view: when calculating element to select, filter tree structure...
authorKirill.Safonov <kirill.safonov@jetbrains.com>
Thu, 5 May 2011 14:28:28 +0000 (18:28 +0400)
committerKirill.Safonov <kirill.safonov@jetbrains.com>
Thu, 5 May 2011 15:50:50 +0000 (19:50 +0400)
platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInTarget.java

index dde21573fcf62deb72c8735672d00a2485090db4..edd31c4291208cf64ae8cf8c02f55dc41d975230 100644 (file)
@@ -24,6 +24,7 @@ import com.intellij.ide.projectView.SelectableTreeStructureProvider;
 import com.intellij.ide.projectView.TreeStructureProvider;
 import com.intellij.ide.projectView.impl.AbstractProjectViewPane;
 import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.project.DumbService;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.ActionCallback;
 import com.intellij.openapi.vfs.VirtualFile;
@@ -36,6 +37,7 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
@@ -109,7 +111,7 @@ public abstract class ProjectViewSelectInTarget extends SelectInTargetPsiWrapper
 
   public void select(PsiElement element, final boolean requestFocus) {
     PsiElement toSelect = null;
-    for (TreeStructureProvider provider : Extensions.getExtensions(TreeStructureProvider.EP_NAME, myProject)) {
+    for (TreeStructureProvider provider : getProvidersDumbAware()) {
       if (provider instanceof SelectableTreeStructureProvider) {
         toSelect = ((SelectableTreeStructureProvider) provider).getTopLevelElement(element);
       }
@@ -132,6 +134,12 @@ public abstract class ProjectViewSelectInTarget extends SelectInTargetPsiWrapper
     select(originalElement, virtualFile, requestFocus);
   }
 
+  private TreeStructureProvider[] getProvidersDumbAware() {
+    List<TreeStructureProvider> allProviders = Arrays.asList(Extensions.getExtensions(TreeStructureProvider.EP_NAME, myProject));
+    List<TreeStructureProvider> dumbAware = DumbService.getInstance(myProject).filterByDumbAwareness(allProviders);
+    return dumbAware.toArray(new TreeStructureProvider[dumbAware.size()]);
+  }
+
   public final String getToolWindowId() {
     return ToolWindowId.PROJECT_VIEW;
   }