Search in sources :

Example 6 with FileElement

use of com.intellij.openapi.fileChooser.FileElement in project intellij-community by JetBrains.

the class RootFileElement method getChildren.

public Object[] getChildren() {
    if (myChildren == null) {
        if (myFiles == null) {
            myFiles = getFileSystemRoots();
        }
        List<FileElement> children = new ArrayList<>();
        for (final VirtualFile file : myFiles) {
            if (file != null) {
                children.add(new FileElement(file, file.getPresentableUrl()));
            }
        }
        myChildren = ArrayUtil.toObjectArray(children);
    }
    return myChildren;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) FileElement(com.intellij.openapi.fileChooser.FileElement)

Example 7 with FileElement

use of com.intellij.openapi.fileChooser.FileElement in project intellij-community by JetBrains.

the class FileTreeStructure method createDescriptor.

@NotNull
public NodeDescriptor createDescriptor(Object element, NodeDescriptor parentDescriptor) {
    LOG.assertTrue(element instanceof FileElement, element.getClass().getName());
    VirtualFile file = ((FileElement) element).getFile();
    Icon closedIcon = file == null ? null : myChooserDescriptor.getIcon(file);
    String name = file == null ? null : myChooserDescriptor.getName(file);
    String comment = file == null ? null : myChooserDescriptor.getComment(file);
    return new FileNodeDescriptor(myProject, (FileElement) element, parentDescriptor, closedIcon, name, comment);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileElement(com.intellij.openapi.fileChooser.FileElement) RootFileElement(com.intellij.openapi.fileChooser.ex.RootFileElement) FileNodeDescriptor(com.intellij.openapi.fileChooser.ex.FileNodeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with FileElement

use of com.intellij.openapi.fileChooser.FileElement in project intellij-community by JetBrains.

the class FileTreeStructure method getParentElement.

@Nullable
public Object getParentElement(Object element) {
    if (element instanceof FileElement) {
        final FileElement fileElement = (FileElement) element;
        final VirtualFile elementFile = getValidFile(fileElement);
        if (elementFile != null && myRootElement.getFile() != null && myRootElement.getFile().equals(elementFile)) {
            return null;
        }
        final VirtualFile parentElementFile = getValidFile(fileElement.getParent());
        if (elementFile != null && parentElementFile != null) {
            final VirtualFile parentFile = elementFile.getParent();
            if (parentElementFile.equals(parentFile))
                return fileElement.getParent();
        }
        VirtualFile file = fileElement.getFile();
        if (file == null)
            return null;
        VirtualFile parent = file.getParent();
        if (parent != null && parent.getFileSystem() instanceof JarFileSystem && parent.getParent() == null) {
            // parent of jar contents should be local jar file
            String localPath = parent.getPath().substring(0, parent.getPath().length() - JarFileSystem.JAR_SEPARATOR.length());
            parent = LocalFileSystem.getInstance().findFileByPath(localPath);
        }
        if (parent != null && parent.isValid() && parent.equals(myRootElement.getFile())) {
            return myRootElement;
        }
        if (parent == null) {
            return myRootElement;
        }
        return new FileElement(parent, parent.getName());
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) FileElement(com.intellij.openapi.fileChooser.FileElement) RootFileElement(com.intellij.openapi.fileChooser.ex.RootFileElement) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with FileElement

use of com.intellij.openapi.fileChooser.FileElement in project intellij-community by JetBrains.

the class FileSystemTreeImpl method processSelectionChange.

private void processSelectionChange() {
    if (myListeners.size() == 0)
        return;
    List<VirtualFile> selection = new ArrayList<>();
    final TreePath[] paths = myTree.getSelectionPaths();
    if (paths != null) {
        for (TreePath each : paths) {
            final Object last = each.getLastPathComponent();
            if (last instanceof DefaultMutableTreeNode) {
                final Object object = ((DefaultMutableTreeNode) last).getUserObject();
                if (object instanceof FileNodeDescriptor) {
                    final FileElement element = ((FileNodeDescriptor) object).getElement();
                    final VirtualFile file = element.getFile();
                    if (file != null) {
                        selection.add(file);
                    }
                }
            }
        }
    }
    fireSelection(selection);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) FileElement(com.intellij.openapi.fileChooser.FileElement)

Example 10 with FileElement

use of com.intellij.openapi.fileChooser.FileElement in project intellij-community by JetBrains.

the class FileSystemTreeImpl method getSelectedFile.

@Nullable
public VirtualFile getSelectedFile() {
    final TreePath path = myTree.getSelectionPath();
    if (path == null)
        return null;
    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    if (!(node.getUserObject() instanceof FileNodeDescriptor))
        return null;
    final FileElement element = ((FileNodeDescriptor) node.getUserObject()).getElement();
    return element.getFile();
}
Also used : FileElement(com.intellij.openapi.fileChooser.FileElement) Nullable(org.jetbrains.annotations.Nullable)

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