Search in sources :

Example 1 with FileGroupNode

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

Aggregations

DirectoryGroupNode (com.android.tools.idea.navigator.nodes.DirectoryGroupNode)1 FileGroupNode (com.android.tools.idea.navigator.nodes.FileGroupNode)1 PackageElement (com.intellij.ide.projectView.impl.nodes.PackageElement)1 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)1 Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1