Search in sources :

Example 1 with NestingTreeNode

use of com.intellij.ide.projectView.impl.nodes.NestingTreeNode in project intellij-community by JetBrains.

the class NestingTreeStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
    if (!(parent instanceof PsiDirectoryNode))
        return children;
    final Collection<NestingRule> rules = getNestingRules();
    if (rules.isEmpty())
        return children;
    final MultiMap<PsiFileNode, PsiFileNode> parentToChildren = calcParentToChildren(children, rules);
    if (parentToChildren.isEmpty())
        return children;
    // initial ArrayList size may be not exact, not a big problem
    final Collection<AbstractTreeNode> newChildren = new ArrayList<>(children.size() - parentToChildren.size());
    final Set<PsiFileNode> childrenToMoveDown = new THashSet<>(parentToChildren.values());
    for (AbstractTreeNode node : children) {
        if (!(node instanceof PsiFileNode)) {
            newChildren.add(node);
            continue;
        }
        if (childrenToMoveDown.contains(node)) {
            continue;
        }
        final Collection<PsiFileNode> childrenOfThisFile = parentToChildren.get((PsiFileNode) node);
        if (childrenOfThisFile.isEmpty()) {
            newChildren.add(node);
            continue;
        }
        newChildren.add(new NestingTreeNode((PsiFileNode) node, childrenOfThisFile));
    }
    return newChildren;
}
Also used : PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) NestingTreeNode(com.intellij.ide.projectView.impl.nodes.NestingTreeNode) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NestingTreeNode (com.intellij.ide.projectView.impl.nodes.NestingTreeNode)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 PsiFileNode (com.intellij.ide.projectView.impl.nodes.PsiFileNode)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 THashSet (gnu.trove.THashSet)1 NotNull (org.jetbrains.annotations.NotNull)1