Search in sources :

Example 11 with NodeDescriptor

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

the class AndroidProjectViewPane method getSelectedDirectories.

@Override
@NotNull
public PsiDirectory[] getSelectedDirectories() {
    Object selectedElement = getSelectedElement();
    if (selectedElement instanceof PackageElement) {
        PackageElement packageElement = (PackageElement) selectedElement;
        Module m = packageElement.getModule();
        if (m != null) {
            return packageElement.getPackage().getDirectories(GlobalSearchScope.moduleScope(m));
        }
    }
    NodeDescriptor descriptor = getSelectedDescriptor();
    if (descriptor instanceof DirectoryGroupNode) {
        return ((DirectoryGroupNode) descriptor).getDirectories();
    }
    PsiDirectory[] selectedDirectories = super.getSelectedDirectories();
    // to treat these as selectable (for target output directories etc)
    if (selectedElement instanceof Module && selectedDirectories.length > 0) {
        List<PsiDirectory> dirs = Lists.newArrayListWithExpectedSize(selectedDirectories.length);
        for (PsiDirectory dir : selectedDirectories) {
            VirtualFile file = dir.getVirtualFile();
            if (!GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(file, myProject)) {
                if (file.getParent() != null && file.getPath().contains("/generated/")) {
                    /// build/generated/res/rs/debug, build/generated/res/rs/test/debug, etc.
                    continue;
                }
                dirs.add(dir);
            }
        }
        selectedDirectories = dirs.toArray(new PsiDirectory[dirs.size()]);
    }
    return selectedDirectories;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DirectoryGroupNode(com.android.tools.idea.navigator.nodes.DirectoryGroupNode) PsiDirectory(com.intellij.psi.PsiDirectory) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with NodeDescriptor

use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.

the class ExcludeFromCompileAction method getSelectedFile.

@Nullable
private VirtualFile getSelectedFile() {
    final ErrorTreeNodeDescriptor descriptor = myErrorTreeView.getSelectedNodeDescriptor();
    ErrorTreeElement element = descriptor != null ? descriptor.getElement() : null;
    if (element != null && !(element instanceof GroupingElement)) {
        NodeDescriptor parent = descriptor.getParentDescriptor();
        if (parent instanceof ErrorTreeNodeDescriptor) {
            element = ((ErrorTreeNodeDescriptor) parent).getElement();
        }
    }
    return element instanceof GroupingElement ? ((GroupingElement) element).getFile() : null;
}
Also used : ErrorTreeElement(com.intellij.ide.errorTreeView.ErrorTreeElement) GroupingElement(com.intellij.ide.errorTreeView.GroupingElement) ErrorTreeNodeDescriptor(com.intellij.ide.errorTreeView.ErrorTreeNodeDescriptor) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) ErrorTreeNodeDescriptor(com.intellij.ide.errorTreeView.ErrorTreeNodeDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with NodeDescriptor

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

the class AndroidProjectViewPane method getData.

@Override
public Object getData(String dataId) {
    if (CommonDataKeys.PROJECT.is(dataId)) {
        return myProject;
    }
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        Object o = getSelectedElement();
        if (o instanceof PsiDirectory) {
            VirtualFile directory = ((PsiDirectory) o).getVirtualFile();
            // See https://code.google.com/p/android/issues/detail?id=212522
            if (isTopModuleDirectoryOrParent(directory)) {
                return new NoOpDeleteProvider();
            }
        }
    }
    if (LangDataKeys.MODULE.is(dataId)) {
        Object o = getSelectedElement();
        if (o instanceof PackageElement) {
            PackageElement packageElement = (PackageElement) o;
            return packageElement.getModule();
        } else if (o instanceof AndroidFacet) {
            return ((AndroidFacet) o).getModule();
        }
    }
    if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
        Object o = getSelectedElement();
        if (o instanceof PackageElement) {
            PackageElement packageElement = (PackageElement) o;
            Module m = packageElement.getModule();
            if (m != null) {
                PsiDirectory[] folders = packageElement.getPackage().getDirectories(GlobalSearchScope.moduleScope(m));
                if (folders.length > 0) {
                    return folders[0].getVirtualFile();
                } else {
                    return null;
                }
            }
        }
    }
    if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
        NodeDescriptor selectedDescriptor = getSelectedDescriptor();
        if (selectedDescriptor instanceof FileGroupNode) {
            PsiFile[] files = ((FileGroupNode) selectedDescriptor).getFiles();
            if (files.length > 0) {
                List<VirtualFile> virtualFiles = Lists.newArrayListWithExpectedSize(files.length);
                for (PsiFile file : files) {
                    if (file.isValid()) {
                        virtualFiles.add(file.getVirtualFile());
                    }
                }
                return virtualFiles.toArray(new VirtualFile[virtualFiles.size()]);
            }
        }
        if (selectedDescriptor instanceof DirectoryGroupNode) {
            PsiDirectory[] directories = ((DirectoryGroupNode) selectedDescriptor).getDirectories();
            if (directories.length > 0) {
                List<VirtualFile> virtualFiles = Lists.newArrayListWithExpectedSize(directories.length);
                for (PsiDirectory directory : directories) {
                    if (directory.isValid()) {
                        virtualFiles.add(directory.getVirtualFile());
                    }
                }
                return virtualFiles.toArray(new VirtualFile[virtualFiles.size()]);
            }
        }
    }
    if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        Object o = getSelectedElement();
        if (o instanceof PsiElement) {
            return o;
        } else if (o instanceof List<?>) {
            List<?> l = (List<?>) o;
            if (!l.isEmpty() && l.get(0) instanceof PsiElement) {
                return l.get(0);
            }
        }
        NodeDescriptor selectedDescriptor = getSelectedDescriptor();
        if (selectedDescriptor instanceof FileGroupNode) {
            PsiFile[] files = ((FileGroupNode) selectedDescriptor).getFiles();
            if (files.length > 0) {
                return files[0];
            }
        }
        if (selectedDescriptor instanceof DirectoryGroupNode) {
            PsiDirectory[] directories = ((DirectoryGroupNode) selectedDescriptor).getDirectories();
            if (directories.length > 0) {
                return directories[0];
            }
        }
    }
    return super.getData(dataId);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DirectoryGroupNode(com.android.tools.idea.navigator.nodes.DirectoryGroupNode) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) FileGroupNode(com.android.tools.idea.navigator.nodes.FileGroupNode) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) ArrayList(java.util.ArrayList) List(java.util.List) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 14 with NodeDescriptor

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

the class AndroidResComparator method compare.

@Override
public int compare(Object o1, Object o2) {
    if (!(o1 instanceof NodeDescriptor) || !(o2 instanceof NodeDescriptor)) {
        return 0;
    }
    // we only support comparing res file nodes and res group nodes
    if (!(o1 instanceof AndroidResFileNode) && !(o1 instanceof AndroidResGroupNode)) {
        return 0;
    }
    if (!(o2 instanceof AndroidResFileNode) && !(o2 instanceof AndroidResGroupNode)) {
        return 0;
    }
    // if one of them is a group node, then we just have to compare them alphabetically
    if (o1 instanceof AndroidResGroupNode || o2 instanceof AndroidResGroupNode) {
        String n1 = getName(o1);
        String n2 = getName(o2);
        return StringUtil.compare(n1, n2, false);
    }
    AndroidResFileNode r1 = (AndroidResFileNode) o1;
    AndroidResFileNode r2 = (AndroidResFileNode) o2;
    // first check file names
    PsiFile file1 = r1.getValue();
    PsiFile file2 = r2.getValue();
    if (file1 != null && file2 != null) {
        int c = StringUtil.compare(file1.getName(), file2.getName(), false);
        if (c != 0) {
            return c;
        }
    }
    // check folder configurations
    FolderConfiguration config1 = r1.getFolderConfiguration();
    FolderConfiguration config2 = r2.getFolderConfiguration();
    if (config1 != null && config2 != null) {
        int c = config1.compareTo(config2);
        if (c != 0) {
            return c;
        }
    }
    // then check qualifiers
    return StringUtil.compare(r1.getQualifier(), r2.getQualifier(), false);
}
Also used : NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) PsiFile(com.intellij.psi.PsiFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Example 15 with NodeDescriptor

use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.

the class ServersToolWindowContent method setupBuilder.

private void setupBuilder(@NotNull final Project project) {
    ServersTreeStructure structure = myContribution.createTreeStructure(project, this);
    myBuilder = new TreeBuilderBase(myTree, structure, myTreeModel) {

        @Override
        protected boolean isAutoExpandNode(NodeDescriptor nodeDescriptor) {
            return (nodeDescriptor instanceof ServersTreeStructure.RemoteServerNode || nodeDescriptor instanceof ServersTreeStructure.DeploymentNodeImpl) && (!myCollapsedTreeNodeValues.contains(((AbstractTreeNode) nodeDescriptor).getValue()));
        }
    };
    Disposer.register(this, myBuilder);
    project.getMessageBus().connect().subscribe(ServerConnectionListener.TOPIC, new ServerConnectionListener() {

        @Override
        public void onConnectionCreated(@NotNull ServerConnection<?> connection) {
            getBuilder().queueUpdate();
        }

        @Override
        public void onConnectionStatusChanged(@NotNull ServerConnection<?> connection) {
            getBuilder().queueUpdate();
            updateSelectedServerDetails();
            if (connection.getStatus() == ConnectionStatus.CONNECTED) {
                pollDeployments(connection);
            }
        }

        @Override
        public void onDeploymentsChanged(@NotNull ServerConnection<?> connection) {
            getBuilder().queueUpdate();
            updateSelectedServerDetails();
        }
    });
}
Also used : ServersTreeStructure(com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeStructure) ServerConnectionListener(com.intellij.remoteServer.runtime.ServerConnectionListener) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) TreeBuilderBase(com.intellij.remoteServer.impl.runtime.ui.tree.TreeBuilderBase)

Aggregations

NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)25 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 PsiFile (com.intellij.psi.PsiFile)4 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)4 TreePath (javax.swing.tree.TreePath)4 TodoItemNode (com.intellij.ide.todo.nodes.TodoItemNode)3 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)3 DirectoryGroupNode (com.android.tools.idea.navigator.nodes.DirectoryGroupNode)2 PackageElement (com.intellij.ide.projectView.impl.nodes.PackageElement)2 FileElement (com.intellij.openapi.fileChooser.FileElement)2 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 ContentEntry (com.intellij.openapi.roots.ContentEntry)2 PsiDirectory (com.intellij.psi.PsiDirectory)2 PsiElement (com.intellij.psi.PsiElement)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)1 FileGroupNode (com.android.tools.idea.navigator.nodes.FileGroupNode)1