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