Search in sources :

Example 11 with FileElement

use of com.intellij.openapi.fileChooser.FileElement in project Perl5-IDEA by Camelcade.

the class PerlContentEntriesTreeEditor method getSelectedFiles.

@NotNull
VirtualFile[] getSelectedFiles() {
    final TreePath[] selectionPaths = myTree.getSelectionPaths();
    if (selectionPaths == null) {
        return VirtualFile.EMPTY_ARRAY;
    }
    final List<VirtualFile> selected = new ArrayList<>();
    for (TreePath treePath : selectionPaths) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
        final Object nodeDescriptor = node.getUserObject();
        if (!(nodeDescriptor instanceof FileNodeDescriptor)) {
            return VirtualFile.EMPTY_ARRAY;
        }
        final FileElement fileElement = ((FileNodeDescriptor) nodeDescriptor).getElement();
        final VirtualFile file = fileElement.getFile();
        if (file != null) {
            selected.add(file);
        }
    }
    return selected.toArray(new VirtualFile[selected.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) FileElement(com.intellij.openapi.fileChooser.FileElement) FileNodeDescriptor(com.intellij.openapi.fileChooser.ex.FileNodeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileElement (com.intellij.openapi.fileChooser.FileElement)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 RootFileElement (com.intellij.openapi.fileChooser.ex.RootFileElement)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 FileNodeDescriptor (com.intellij.openapi.fileChooser.ex.FileNodeDescriptor)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)2 JarFileSystem (com.intellij.openapi.vfs.JarFileSystem)2 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)2 TreePath (javax.swing.tree.TreePath)2 Nullable (org.jetbrains.annotations.Nullable)2 ContentEntry (com.intellij.openapi.roots.ContentEntry)1 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)1 HashSet (java.util.HashSet)1 AbstractFileObject (org.netbeans.lib.cvsclient.file.AbstractFileObject)1