Search in sources :

Example 1 with FileElement

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

the class ImportTree method customize.

private boolean customize(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    if (!(value instanceof DefaultMutableTreeNode)) {
        return false;
    }
    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    final Object userObject = node.getUserObject();
    if (!(userObject instanceof NodeDescriptor)) {
        return false;
    }
    final NodeDescriptor descriptor = (NodeDescriptor) userObject;
    final Object element = descriptor.getElement();
    if (!(element instanceof FileElement)) {
        return false;
    }
    final FileElement fileElement = (FileElement) element;
    if (!isExcluded(fileElement)) {
        return false;
    }
    setIcon(IconLoader.getDisabledIcon(descriptor.getIcon()));
    final String text = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
    append(text, new SimpleTextAttributes(SimpleTextAttributes.STYLE_STRIKEOUT, tree.getForeground()));
    return true;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) FileElement(com.intellij.openapi.fileChooser.FileElement) AbstractFileObject(org.netbeans.lib.cvsclient.file.AbstractFileObject)

Example 2 with FileElement

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

the class FileTreeBuilder method isAlwaysShowPlus.

@Override
protected boolean isAlwaysShowPlus(NodeDescriptor nodeDescriptor) {
    Object element = nodeDescriptor.getElement();
    if (element != null) {
        FileElement descriptor = (FileElement) element;
        VirtualFile file = descriptor.getFile();
        if (file != null) {
            if (myChooserDescriptor.isChooseJarContents() && FileElement.isArchive(file)) {
                return true;
            }
            return file.isDirectory();
        }
    }
    return true;
}
Also used : FileElement(com.intellij.openapi.fileChooser.FileElement) RootFileElement(com.intellij.openapi.fileChooser.ex.RootFileElement)

Example 3 with FileElement

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

the class FileTreeStructure method getChildElements.

public Object[] getChildElements(Object nodeElement) {
    if (!(nodeElement instanceof FileElement)) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    FileElement element = (FileElement) nodeElement;
    VirtualFile file = element.getFile();
    if (file == null || !file.isValid()) {
        if (element == myRootElement) {
            return myRootElement.getChildren();
        }
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    VirtualFile[] children = null;
    if (element.isArchive() && myChooserDescriptor.isChooseJarContents()) {
        String path = file.getPath();
        if (!(file.getFileSystem() instanceof JarFileSystem)) {
            file = JarFileSystem.getInstance().findFileByPath(path + JarFileSystem.JAR_SEPARATOR);
        }
        if (file != null) {
            children = file.getChildren();
        }
    } else {
        children = file.getChildren();
    }
    if (children == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    Set<FileElement> childrenSet = new HashSet<>();
    for (VirtualFile child : children) {
        if (myChooserDescriptor.isFileVisible(child, myShowHidden)) {
            final FileElement childElement = new FileElement(child, child.getName());
            childElement.setParent(element);
            childrenSet.add(childElement);
        }
    }
    return ArrayUtil.toObjectArray(childrenSet);
}
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) HashSet(java.util.HashSet)

Example 4 with FileElement

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

the class ContentEntryTreeCellRenderer method customizeCellRenderer.

@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
    final ContentEntryEditor editor = myTreeEditor.getContentEntryEditor();
    if (editor != null) {
        final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
        if (userObject instanceof NodeDescriptor) {
            final Object element = ((NodeDescriptor) userObject).getElement();
            if (element instanceof FileElement) {
                final VirtualFile file = ((FileElement) element).getFile();
                if (file != null && file.isDirectory()) {
                    final ContentEntry contentEntry = editor.getContentEntry();
                    if (contentEntry != null) {
                        final String prefix = getPresentablePrefix(contentEntry, file);
                        if (!prefix.isEmpty()) {
                            append(" (" + prefix + ")", new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
                        }
                        setIcon(updateIcon(contentEntry, file, getIcon()));
                    }
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ContentEntry(com.intellij.openapi.roots.ContentEntry) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) FileElement(com.intellij.openapi.fileChooser.FileElement)

Example 5 with FileElement

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

the class ContentEntryEditingAction method getSelectedFiles.

@NotNull
protected final 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