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;
}
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;
}
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);
}
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()));
}
}
}
}
}
}
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()]);
}
Aggregations