Search in sources :

Example 66 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project android by JetBrains.

the class AndroidResFolderTypeNode method getChildren.

@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
    // all resource folders of a given folder type
    List<PsiDirectory> folders = getValue();
    Multimap<String, PsiFile> multimap = HashMultimap.create();
    for (PsiDirectory res : folders) {
        for (PsiFile file : res.getFiles()) {
            String resName = file.getName();
            multimap.put(resName, file);
        }
    }
    List<AbstractTreeNode> children = Lists.newArrayListWithExpectedSize(multimap.size());
    for (String resName : multimap.keySet()) {
        List<PsiFile> files = Lists.newArrayList(multimap.get(resName));
        if (files.size() > 1) {
            children.add(new AndroidResGroupNode(myProject, myFacet, files, resName, getSettings()));
        } else {
            children.add(new AndroidResFileNode(myProject, files.get(0), getSettings(), myFacet));
        }
    }
    return children;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 67 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project android by JetBrains.

the class AndroidSourceTypeNode method annotateWithSourceProvider.

private Collection<AbstractTreeNode> annotateWithSourceProvider(Collection<AbstractTreeNode> directoryChildren) {
    List<AbstractTreeNode> children = Lists.newArrayListWithExpectedSize(directoryChildren.size());
    for (AbstractTreeNode child : directoryChildren) {
        if (child instanceof PsiDirectoryNode) {
            PsiDirectory directory = ((PsiDirectoryNode) child).getValue();
            children.add(new AndroidPsiDirectoryNode(myProject, directory, getSettings(), findSourceProvider(directory.getVirtualFile())));
        } else if (child instanceof PsiFileNode) {
            PsiFile file = ((PsiFileNode) child).getValue();
            children.add(new AndroidPsiFileNode(myProject, file, getSettings(), findSourceProvider(file.getVirtualFile())));
        } else {
            children.add(child);
        }
    }
    return children;
}
Also used : PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) PsiFile(com.intellij.psi.PsiFile)

Example 68 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project android by JetBrains.

the class AndroidSourceTypeNode method getChildren.

@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
    List<AbstractTreeNode> children = Lists.newArrayList();
    ProjectViewDirectoryHelper projectViewDirectoryHelper = ProjectViewDirectoryHelper.getInstance(myProject);
    AndroidProjectTreeBuilder treeBuilder = (AndroidProjectTreeBuilder) myProjectViewPane.getTreeBuilder();
    for (PsiDirectory directory : getSourceDirectories()) {
        Collection<AbstractTreeNode> directoryChildren = projectViewDirectoryHelper.getDirectoryChildren(directory, getSettings(), true);
        children.addAll(annotateWithSourceProvider(directoryChildren));
        // Inform the tree builder of the node that this particular virtual file maps to
        treeBuilder.createMapping(directory.getVirtualFile(), this);
    }
    return children;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ProjectViewDirectoryHelper(com.intellij.ide.projectView.impl.nodes.ProjectViewDirectoryHelper) AndroidProjectTreeBuilder(com.android.tools.idea.navigator.AndroidProjectTreeBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode 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 70 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project folding-plugin by dmytrodanylyk.

the class ProjectStructureProvider method filterByDirName.

@NotNull
private List<AbstractTreeNode> filterByDirName(Collection<AbstractTreeNode> fileNodes, String token) {
    List<AbstractTreeNode> resultList = new ArrayList<>();
    final boolean customPrefix = PropertiesComponent.getInstance().getBoolean(SettingConfigurable.PREFIX_CUSTOM_USE, false);
    Pattern pattern = customPrefix ? Pattern.compile(PropertiesComponent.getInstance().getValue(SettingConfigurable.PREFIX_PATTERN, SettingConfigurable.DEFAULT_PATTERN)) : null;
    for (AbstractTreeNode fileNode : fileNodes) {
        if (fileNode.getValue() instanceof PsiFile) {
            PsiFile psiFile = (PsiFile) fileNode.getValue();
            String fileName = psiFile.getName();
            if (customPrefix) {
                Matcher m = pattern.matcher(fileName);
                if (m.find()) {
                    String composedDirName = m.group(0);
                    if (composedDirName.equals(token)) {
                        resultList.add(fileNode);
                    }
                }
            } else {
                int endIndex = fileName.indexOf(COMPOSE_BY_CHAR);
                if (endIndex != -1) {
                    String composedDirName = fileName.substring(0, endIndex);
                    if (composedDirName.equals(token)) {
                        resultList.add(fileNode);
                    }
                }
            }
        }
    }
    return resultList;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)150 NotNull (org.jetbrains.annotations.NotNull)69 ArrayList (java.util.ArrayList)51 VirtualFile (com.intellij.openapi.vfs.VirtualFile)40 Project (com.intellij.openapi.project.Project)33 PsiFile (com.intellij.psi.PsiFile)30 Module (com.intellij.openapi.module.Module)27 PsiDirectory (com.intellij.psi.PsiDirectory)25 PsiElement (com.intellij.psi.PsiElement)16 Nullable (org.jetbrains.annotations.Nullable)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)10 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)9 PsiManager (com.intellij.psi.PsiManager)9 List (java.util.List)9 PresentationData (com.intellij.ide.projectView.PresentationData)6 ViewSettings (com.intellij.ide.projectView.ViewSettings)6 PsiFileNode (com.intellij.ide.projectView.impl.nodes.PsiFileNode)6 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)5 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)5