Search in sources :

Example 6 with PsiFileNode

use of com.intellij.ide.projectView.impl.nodes.PsiFileNode in project folding-plugin by dmytrodanylyk.

the class DirectoryNode method getChildren.

@NotNull
@Override
public List<AbstractTreeNode> getChildren() {
    if (PropertiesComponent.getInstance().getBoolean(SettingConfigurable.PREFIX_HIDE, false)) {
        final ArrayList<AbstractTreeNode> abstractTreeNodes = new ArrayList<>();
        for (AbstractTreeNode fileNode : mChildNodeList) {
            PsiFile psiFile = (PsiFile) fileNode.getValue();
            final ViewSettings settings = ((PsiFileNode) fileNode).getSettings();
            String shortName = psiFile.getName().substring(mName.length());
            final int beginIndex = shortName.indexOf(ProjectStructureProvider.COMPOSE_BY_CHAR);
            if (beginIndex != -1) {
                shortName = shortName.substring(beginIndex + 1);
            }
            abstractTreeNodes.add(new FoldingNode(fileNode.getProject(), psiFile, settings, shortName));
        }
        return abstractTreeNodes;
    } else {
        return mChildNodeList;
    }
}
Also used : PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ViewSettings(com.intellij.ide.projectView.ViewSettings) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with PsiFileNode

use of com.intellij.ide.projectView.impl.nodes.PsiFileNode 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)

Example 8 with PsiFileNode

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

the class NestingTreeStructureProvider method calcParentToChildren.

/*
    This is a graph theory problem. PsiFileNodes are graph nodes.
    Edges go from parent file to child file according to NestingRules, for example foo.js->foo.min.js.
    Parent may have several children. Child may have several parents.
    There may be cycles with 3 or more nodes, but cycle with 2 nodes (A->B and B->A) is impossible because parentFileSuffix != childFileSuffix
    For each child its outbound edges are removed. For example in case of a cycle all edges that form it are removed. In case of A->B->C only A->B remains.
    As a result we get a number of separated parent-to-many-children sub-graphs, and use them to nest child files under parent file in Project View.
    One child still may have more than one parent. For real use cases it is not expected to happen, but anyway it's not a big problem, it will be shown as a subnode more than once.
   */
@NotNull
private static MultiMap<PsiFileNode, PsiFileNode> calcParentToChildren(@NotNull final Collection<AbstractTreeNode> nodes, @NotNull final Collection<NestingRule> rules) {
    // result that will contain number of separated parent-to-many-children sub-graphs
    MultiMap<PsiFileNode, PsiFileNode> parentToChildren = null;
    // helps to remove all outbound edges of a node that has inbound edge itself
    Set<PsiFileNode> allChildNodes = null;
    // temporary map for building edges
    Map<Pair<String, NestingRule>, Edge<PsiFileNode>> baseNameAndRuleToEdge = null;
    for (AbstractTreeNode node : nodes) {
        if (!(node instanceof PsiFileNode))
            continue;
        final PsiFile file = ((PsiFileNode) node).getValue();
        if (file == null)
            continue;
        for (NestingRule rule : rules) {
            final String fileName = file.getName();
            final Couple<Boolean> c = checkMatchingAsParentOrChild(rule, fileName);
            final boolean matchesParent = c.first;
            final boolean matchesChild = c.second;
            if (!matchesChild && !matchesParent)
                continue;
            if (baseNameAndRuleToEdge == null) {
                baseNameAndRuleToEdge = new THashMap<>();
                parentToChildren = new MultiMap<>();
                allChildNodes = new THashSet<>();
            }
            if (matchesParent) {
                final String baseName = fileName.substring(0, fileName.length() - rule.myParentFileSuffix.length());
                final Edge<PsiFileNode> edge = getOrCreateEdge(baseNameAndRuleToEdge, baseName, rule);
                edge.from = (PsiFileNode) node;
                updateInfoIfEdgeComplete(parentToChildren, allChildNodes, edge);
            }
            if (matchesChild) {
                final String baseName = fileName.substring(0, fileName.length() - rule.myChildFileSuffix.length());
                final Edge<PsiFileNode> edge = getOrCreateEdge(baseNameAndRuleToEdge, baseName, rule);
                edge.to = (PsiFileNode) node;
                updateInfoIfEdgeComplete(parentToChildren, allChildNodes, edge);
            }
        }
    }
    return parentToChildren == null ? MultiMap.empty() : parentToChildren;
}
Also used : PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with PsiFileNode

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

the class ResourceBundleNode method extractPropertiesFileFromNode.

@Nullable
private static PropertiesFile extractPropertiesFileFromNode(TreeNode node) {
    if (!(node instanceof DefaultMutableTreeNode))
        return null;
    final Object userObject = ((DefaultMutableTreeNode) node).getUserObject();
    if (!(userObject instanceof PsiFileNode))
        return null;
    final PsiFile file = ((PsiFileNode) userObject).getValue();
    final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
    if (propertiesFile == null || !file.getManager().isInProject(file) || !file.isValid())
        return null;
    return propertiesFile;
}
Also used : PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with PsiFileNode

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

the class PyTreeStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    final Project project = parent.getProject();
    final Sdk sdk = getPythonSdk(parent);
    if (sdk != null && project != null) {
        final Collection<AbstractTreeNode> newChildren = hideSkeletons(children);
        final PySkeletonsNode skeletonsNode = PySkeletonsNode.create(project, sdk, settings);
        if (skeletonsNode != null) {
            newChildren.add(skeletonsNode);
        }
        final PyUserSkeletonsNode userSkeletonsNode = PyUserSkeletonsNode.create(project, settings);
        if (userSkeletonsNode != null) {
            newChildren.add(userSkeletonsNode);
        }
        final PyRemoteLibrariesNode remoteLibrariesNode = PyRemoteLibrariesNode.create(project, sdk, settings);
        if (remoteLibrariesNode != null) {
            newChildren.add(remoteLibrariesNode);
        }
        final PyTypeShedNode typeShedNode = PyTypeShedNode.Companion.create(project, sdk, settings);
        if (typeShedNode != null) {
            newChildren.add(typeShedNode);
        }
        return newChildren;
    }
    if (settings.isShowMembers()) {
        List<AbstractTreeNode> newChildren = new ArrayList<>();
        for (AbstractTreeNode child : children) {
            if (child instanceof PsiFileNode && ((PsiFileNode) child).getValue() instanceof PyFile) {
                newChildren.add(new PyFileNode(project, ((PsiFileNode) child).getValue(), settings));
            } else {
                newChildren.add(child);
            }
        }
        return newChildren;
    }
    return children;
}
Also used : PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PyFile(com.jetbrains.python.psi.PyFile) Project(com.intellij.openapi.project.Project) Sdk(com.intellij.openapi.projectRoots.Sdk) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiFileNode (com.intellij.ide.projectView.impl.nodes.PsiFileNode)11 PsiFile (com.intellij.psi.PsiFile)7 NotNull (org.jetbrains.annotations.NotNull)7 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)6 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)2 PsiElement (com.intellij.psi.PsiElement)2 ArrayList (java.util.ArrayList)2 IdeBundle (com.intellij.ide.IdeBundle)1 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)1 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)1 TreeStructureProvider (com.intellij.ide.projectView.TreeStructureProvider)1 ViewSettings (com.intellij.ide.projectView.ViewSettings)1 AbstractProjectTreeStructure (com.intellij.ide.projectView.impl.AbstractProjectTreeStructure)1 ProjectAbstractTreeStructureBase (com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase)1 ProjectTreeBuilder (com.intellij.ide.projectView.impl.ProjectTreeBuilder)1 BasePsiNode (com.intellij.ide.projectView.impl.nodes.BasePsiNode)1 ClassTreeNode (com.intellij.ide.projectView.impl.nodes.ClassTreeNode)1