Search in sources :

Example 1 with AndroidProjectTreeBuilder

use of com.android.tools.idea.navigator.AndroidProjectTreeBuilder in project android by JetBrains.

the class AndroidResFolderNode method getChildren.

/**
   * Returns the children of the res folder. Rather than showing the existing directory hierarchy, this merges together
   * all the folders by their {@link com.android.resources.ResourceFolderType}.
   */
@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
    // collect all res folders from all source providers
    List<PsiDirectory> resFolders = Lists.newArrayList();
    for (PsiDirectory directory : getSourceDirectories()) {
        resFolders.addAll(Lists.newArrayList(directory.getSubdirectories()));
    }
    // group all the res folders by their folder type
    HashMultimap<ResourceFolderType, PsiDirectory> foldersByResourceType = HashMultimap.create();
    for (PsiDirectory resFolder : resFolders) {
        ResourceFolderType type = ResourceFolderType.getFolderType(resFolder.getName());
        if (type == null) {
            // skip unknown folder types inside res
            continue;
        }
        foldersByResourceType.put(type, resFolder);
    }
    // create a node for each res folder type that actually has some resources
    AndroidProjectTreeBuilder treeBuilder = (AndroidProjectTreeBuilder) myProjectViewPane.getTreeBuilder();
    List<AbstractTreeNode> children = Lists.newArrayListWithExpectedSize(foldersByResourceType.size());
    for (ResourceFolderType type : foldersByResourceType.keySet()) {
        Set<PsiDirectory> folders = foldersByResourceType.get(type);
        final AndroidResFolderTypeNode androidResFolderTypeNode = new AndroidResFolderTypeNode(myProject, getValue(), Lists.newArrayList(folders), getSettings(), type, myProjectViewPane);
        children.add(androidResFolderTypeNode);
        // Inform the tree builder of the node that this particular virtual file maps to
        for (PsiDirectory folder : folders) {
            treeBuilder.createMapping(folder.getVirtualFile(), androidResFolderTypeNode);
        }
    }
    return children;
}
Also used : ResourceFolderType(com.android.resources.ResourceFolderType) PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) AndroidProjectTreeBuilder(com.android.tools.idea.navigator.AndroidProjectTreeBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with AndroidProjectTreeBuilder

use of com.android.tools.idea.navigator.AndroidProjectTreeBuilder 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)

Aggregations

AndroidProjectTreeBuilder (com.android.tools.idea.navigator.AndroidProjectTreeBuilder)2 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 PsiDirectory (com.intellij.psi.PsiDirectory)2 NotNull (org.jetbrains.annotations.NotNull)2 ResourceFolderType (com.android.resources.ResourceFolderType)1 ProjectViewDirectoryHelper (com.intellij.ide.projectView.impl.nodes.ProjectViewDirectoryHelper)1