diff --git a/java/java-impl/src/com/intellij/ide/projectView/impl/nodes/PackageElement.java b/java/java-impl/src/com/intellij/ide/projectView/impl/nodes/PackageElement.java index 870bbb702191..c6872679c030 100644 --- a/java/java-impl/src/com/intellij/ide/projectView/impl/nodes/PackageElement.java +++ b/java/java-impl/src/com/intellij/ide/projectView/impl/nodes/PackageElement.java @@ -15,19 +15,24 @@ */ package com.intellij.ide.projectView.impl.nodes; +import com.intellij.ide.projectView.RootsProvider; import com.intellij.openapi.actionSystem.DataKey; import com.intellij.openapi.module.Module; import com.intellij.openapi.ui.Queryable; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; import com.intellij.psi.PsiPackage; +import com.intellij.psi.search.GlobalSearchScope; -import java.util.Map; +import java.util.*; /** * @author Eugene Zhuravlev * Date: Sep 19, 2003 * Time: 3:51:02 PM */ -public final class PackageElement implements Queryable { +public final class PackageElement implements Queryable, RootsProvider { public static final DataKey DATA_KEY = DataKey.create("package.element"); private final Module myModule; @@ -48,6 +53,17 @@ public final class PackageElement implements Queryable { return myElement; } + @Override + public Collection getRoots() { + Set roots= new HashSet(); + final GlobalSearchScope scopeToShow = PackageUtil.getScopeToShow(myModule.getProject(), myModule, isLibraryElement()); + final PsiDirectory[] dirs = getPackage().getDirectories(scopeToShow); + for (PsiDirectory each : dirs) { + roots.add(each.getVirtualFile()); + } + return roots; + } + public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof PackageElement)) return false; @@ -73,6 +89,8 @@ public final class PackageElement implements Queryable { return myIsLibraryElement; } + + public void putInfo(Map info) { PsiPackage pkg = getPackage(); if (pkg instanceof Queryable) { diff --git a/java/java-impl/src/com/intellij/ide/projectView/impl/nodes/PackageViewModuleNode.java b/java/java-impl/src/com/intellij/ide/projectView/impl/nodes/PackageViewModuleNode.java index d2430b7a4e11..8ea8a6c9b157 100644 --- a/java/java-impl/src/com/intellij/ide/projectView/impl/nodes/PackageViewModuleNode.java +++ b/java/java-impl/src/com/intellij/ide/projectView/impl/nodes/PackageViewModuleNode.java @@ -51,4 +51,9 @@ public class PackageViewModuleNode extends AbstractModuleNode{ return module != null && !module.isDisposed() && (ModuleUtil.moduleContainsFile(module, file, false) || ModuleUtil.moduleContainsFile(module, file, true)); } + + @Override + public boolean someChildContainsFile(VirtualFile file) { + return true; + } } diff --git a/java/java-impl/src/com/intellij/ide/projectView/impl/nodes/PackageViewProjectNode.java b/java/java-impl/src/com/intellij/ide/projectView/impl/nodes/PackageViewProjectNode.java index f96b1ec5772c..e306cdbaa7b5 100644 --- a/java/java-impl/src/com/intellij/ide/projectView/impl/nodes/PackageViewProjectNode.java +++ b/java/java-impl/src/com/intellij/ide/projectView/impl/nodes/PackageViewProjectNode.java @@ -110,4 +110,9 @@ public class PackageViewProjectNode extends AbstractProjectNode { throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { return createTreeNode(PackageViewModuleGroupNode.class, getProject(), moduleGroup, getSettings()); } + + @Override + public boolean someChildContainsFile(VirtualFile file) { + return true; + } } diff --git a/platform/lang-api/src/com/intellij/ide/projectView/ProjectViewNode.java b/platform/lang-api/src/com/intellij/ide/projectView/ProjectViewNode.java index 881df35b28da..9686501b679e 100644 --- a/platform/lang-api/src/com/intellij/ide/projectView/ProjectViewNode.java +++ b/platform/lang-api/src/com/intellij/ide/projectView/ProjectViewNode.java @@ -20,19 +20,19 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.problems.WolfTheProblemSolver; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiUtilBase; +import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; +import java.util.*; /** * A node in the project view tree. @@ -40,7 +40,7 @@ import java.util.List; * @see TreeStructureProvider#modify(com.intellij.ide.util.treeView.AbstractTreeNode, java.util.Collection, com.intellij.ide.projectView.ViewSettings) */ -public abstract class ProjectViewNode extends AbstractTreeNode { +public abstract class ProjectViewNode extends AbstractTreeNode implements RootsProvider { protected static final Logger LOG = Logger.getInstance("#com.intellij.ide.projectView.ProjectViewNode"); @@ -123,6 +123,22 @@ public abstract class ProjectViewNode extends AbstractTreeNode { } public boolean someChildContainsFile(final VirtualFile file) { + VirtualFile parent = file.getParent(); + if (parent == null) return false; + + boolean mayContain = false; + Collection roots = getRoots(); + for (VirtualFile eachRoot : roots) { + if (parent.equals(eachRoot.getParent())) { + mayContain = true; + break; + } + } + + if (!mayContain) { + return false; + } + Collection kids = getChildren(); for (final AbstractTreeNode kid : kids) { ProjectViewNode node = (ProjectViewNode)kid; @@ -131,6 +147,24 @@ public abstract class ProjectViewNode extends AbstractTreeNode { return false; } + public Collection getRoots() { + Value value = getValue(); + + if (value instanceof RootsProvider) { + return ((RootsProvider)value).getRoots(); + } else if (value instanceof PsiFile) { + PsiFile vFile = ((PsiFile)value).getContainingFile(); + if (vFile != null && vFile.getVirtualFile() != null) { + return Collections.singleton(vFile.getVirtualFile()); + } + } else if (value instanceof VirtualFile) { + return Collections.singleton(((VirtualFile)value)); + } + + return EMPTY_ROOTS; + } + + protected boolean hasProblemFileBeneath() { if (!Registry.is("projectView.showHierarchyErrors")) return false; diff --git a/platform/lang-api/src/com/intellij/ide/projectView/RootsProvider.java b/platform/lang-api/src/com/intellij/ide/projectView/RootsProvider.java new file mode 100644 index 000000000000..cdb858f4d559 --- /dev/null +++ b/platform/lang-api/src/com/intellij/ide/projectView/RootsProvider.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ide.projectView; + +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.HashSet; + +import java.util.Collection; +import java.util.Set; + +public interface RootsProvider { + + Set EMPTY_ROOTS = new HashSet(); + + Collection getRoots(); + +} diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java index 6b41c6e41baf..b595a834afdf 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java @@ -29,6 +29,9 @@ import com.intellij.pom.NavigatableWithText; import com.intellij.ui.SimpleTextAttributes; import org.jetbrains.annotations.NotNull; +import java.util.Arrays; +import java.util.Collection; + public abstract class AbstractModuleNode extends ProjectViewNode implements NavigatableWithText { protected AbstractModuleNode(Project project, Module module, ViewSettings viewSettings) { super(project, module, viewSettings); @@ -57,6 +60,11 @@ public abstract class AbstractModuleNode extends ProjectViewNode impleme return "Module"; } + @Override + public Collection getRoots() { + return Arrays.asList(ModuleRootManager.getInstance(getValue()).getContentRoots()); + } + @Override public boolean contains(@NotNull VirtualFile file) { Module module = getValue(); diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/StructureViewModuleNode.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/StructureViewModuleNode.java index fde7b5837188..14fbc7249c8e 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/StructureViewModuleNode.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/StructureViewModuleNode.java @@ -58,4 +58,9 @@ public class StructureViewModuleNode extends AbstractModuleNode { public boolean contains(@NotNull VirtualFile file) { return false; } + + @Override + public boolean someChildContainsFile(VirtualFile file) { + return true; + } }