use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class PackageViewPane method getSelectedPackageElement.
@Nullable
private PackageElement getSelectedPackageElement() {
PackageElement result = null;
final DefaultMutableTreeNode selectedNode = getSelectedNode();
if (selectedNode != null) {
Object o = selectedNode.getUserObject();
if (o instanceof AbstractTreeNode) {
Object selected = ((AbstractTreeNode) o).getValue();
result = selected instanceof PackageElement ? (PackageElement) selected : null;
}
}
return result;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class PackageElementNode method getChildren.
@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
final PackageElement value = getValue();
if (value == null)
return Collections.emptyList();
final List<AbstractTreeNode> children = new ArrayList<>();
final Module module = value.getModule();
final PsiPackage aPackage = value.getPackage();
if (!getSettings().isFlattenPackages()) {
final PsiPackage[] subpackages = PackageUtil.getSubpackages(aPackage, module, isLibraryElement());
for (PsiPackage subpackage : subpackages) {
PackageUtil.addPackageAsChild(children, subpackage, module, getSettings(), isLibraryElement());
}
}
// process only files in package's directories
final GlobalSearchScope scopeToShow = PackageUtil.getScopeToShow(aPackage.getProject(), module, isLibraryElement());
PsiFile[] packageChildren = aPackage.getFiles(scopeToShow);
for (PsiFile file : packageChildren) {
if (file.getVirtualFile() != null) {
children.add(new PsiFileNode(getProject(), file, getSettings()));
}
}
return children;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class SameNamesJoiner method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
if (parent instanceof JoinedNode)
return children;
ArrayList<AbstractTreeNode> result = new ArrayList<>();
MultiValuesMap<Object, AbstractTreeNode> executed = new MultiValuesMap<>();
for (Iterator<AbstractTreeNode> iterator = children.iterator(); iterator.hasNext(); ) {
ProjectViewNode treeNode = (ProjectViewNode) iterator.next();
Object o = treeNode.getValue();
if (o instanceof PsiFile) {
String name = ((PsiFile) o).getVirtualFile().getNameWithoutExtension();
executed.put(name, treeNode);
} else {
executed.put(o, treeNode);
}
}
Iterator<Object> keys = executed.keySet().iterator();
while (keys.hasNext()) {
Object each = keys.next();
Collection<AbstractTreeNode> objects = executed.get(each);
if (objects.size() > 1) {
result.add(new JoinedNode(objects, new Joined(findPsiFileIn(objects))));
} else if (objects.size() == 1) {
result.add(objects.iterator().next());
}
}
return result;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class JavaCoverageViewExtension method createTopLevelNodes.
@Override
public List<AbstractTreeNode> createTopLevelNodes() {
final List<AbstractTreeNode> topLevelNodes = new ArrayList<>();
final LinkedHashSet<PsiPackage> packages = new LinkedHashSet<>();
final LinkedHashSet<PsiClass> classes = new LinkedHashSet<>();
for (CoverageSuite suite : mySuitesBundle.getSuites()) {
packages.addAll(((JavaCoverageSuite) suite).getCurrentSuitePackages(myProject));
classes.addAll(((JavaCoverageSuite) suite).getCurrentSuiteClasses(myProject));
}
final Set<PsiPackage> packs = new HashSet<>();
for (PsiPackage aPackage : packages) {
final String qualifiedName = aPackage.getQualifiedName();
for (PsiPackage psiPackage : packages) {
if (psiPackage.getQualifiedName().startsWith(qualifiedName + ".")) {
packs.add(psiPackage);
break;
}
}
}
packages.removeAll(packs);
for (PsiPackage aPackage : packages) {
final GlobalSearchScope searchScope = mySuitesBundle.getSearchScope(myProject);
if (aPackage.getClasses(searchScope).length != 0) {
final CoverageListNode node = new CoverageListNode(myProject, aPackage, mySuitesBundle, myStateBean);
topLevelNodes.add(node);
}
collectSubPackages(topLevelNodes, aPackage);
}
for (PsiClass aClass : classes) {
topLevelNodes.add(new CoverageListNode(myProject, aClass, mySuitesBundle, myStateBean));
}
return topLevelNodes;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class DirectoryCoverageViewExtension method getChildrenNodes.
@Override
public List<AbstractTreeNode> getChildrenNodes(AbstractTreeNode node) {
List<AbstractTreeNode> children = new ArrayList<>();
if (node instanceof CoverageListNode) {
final Object val = node.getValue();
if (val instanceof PsiFile || val == null)
return Collections.emptyList();
final PsiDirectory psiDirectory = (PsiDirectory) val;
final PsiDirectory[] subdirectories = ApplicationManager.getApplication().runReadAction(new Computable<PsiDirectory[]>() {
@Override
public PsiDirectory[] compute() {
return psiDirectory.getSubdirectories();
}
});
for (PsiDirectory subdirectory : subdirectories) {
children.add(new CoverageListNode(myProject, subdirectory, mySuitesBundle, myStateBean));
}
final PsiFile[] psiFiles = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile[]>() {
@Override
public PsiFile[] compute() {
return psiDirectory.getFiles();
}
});
for (PsiFile psiFile : psiFiles) {
children.add(new CoverageListNode(myProject, psiFile, mySuitesBundle, myStateBean));
}
for (AbstractTreeNode childNode : children) {
childNode.setParent(node);
}
}
return children;
}
Aggregations