com.intellij.ide.projectView.impl.nodes.PsiFileNode Java Examples
The following examples show how to use
com.intellij.ide.projectView.impl.nodes.PsiFileNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VirtualFileTreeNode.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
@Override protected void update(@NotNull PresentationData presentation) { final PsiManager psiManager = PsiManager.getInstance(myProject); final VirtualFile virtualFile = getValue(); final PsiFile psiElement = virtualFile.isValid() ? psiManager.findFile(virtualFile) : null; if (psiElement instanceof PsiDirectory) { new PsiDirectoryNode(myProject, (PsiDirectory)psiElement, getSettings()).update(presentation); } else if (psiElement != null) { new PsiFileNode(myProject, psiElement, getSettings()).update(presentation); } else { presentation.setPresentableText(virtualFile.getName()); presentation.setIcon(virtualFile.isDirectory() ? AllIcons.Nodes.Folder : virtualFile.getFileType().getIcon()); } }
Example #2
Source File: VirtualFileTreeNode.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
@NotNull @Override public Collection<? extends AbstractTreeNode<?>> getChildren() { final PsiManager psiManager = PsiManager.getInstance(myProject); final VirtualFile virtualFile = getValue(); return ContainerUtil.mapNotNull( virtualFile.isValid() && virtualFile.isDirectory() ? virtualFile.getChildren() : VirtualFile.EMPTY_ARRAY, new Function<VirtualFile, AbstractTreeNode<?>>() { @Override public AbstractTreeNode<?> fun(VirtualFile file) { final PsiElement psiElement = file.isDirectory() ? psiManager.findDirectory(file) : psiManager.findFile(file); if (psiElement instanceof PsiDirectory && ModuleUtil.findModuleForPsiElement(psiElement) != null) { // PsiDirectoryNode doesn't render files outside of a project // let's use PsiDirectoryNode only for folders in a modules return new PsiDirectoryNode(myProject, (PsiDirectory)psiElement, getSettings()); } else if (psiElement instanceof PsiFile) { return new PsiFileNode(myProject, (PsiFile)psiElement, getSettings()); } else { return shouldShow(file) ? new VirtualFileTreeNode(myProject, file, getSettings()) : null; } } } ); }
Example #3
Source File: PantsTreeStructureProvider.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
@NotNull @Override public Collection<AbstractTreeNode<?>> modify( @NotNull final AbstractTreeNode<?> node, @NotNull Collection<AbstractTreeNode<?>> collection, ViewSettings settings ) { Project project = node.getProject(); if (project == null || !(node instanceof PsiDirectoryNode)) return collection; PsiDirectoryNode directory = (PsiDirectoryNode) node; List<PsiFileNode> newNodes = Optional.ofNullable(getModuleOf(directory)) .filter(module -> isModuleRoot(directory, module)) .flatMap(PantsUtil::findModuleAddress) .flatMap(buildPAth -> PantsUtil.findFileRelativeToBuildRoot(project, buildPAth)) .filter(buildFile -> !alreadyExists(collection, buildFile)) .map(buildFile -> createNode(settings, project, buildFile)) .orElseGet(Collections::emptyList); if (newNodes.isEmpty()) return collection; return Stream.concat(collection.stream(), newNodes.stream()).collect(Collectors.toList()); }
Example #4
Source File: TextOnlyTreeStructureProvider.java From intellij-sdk-docs with Apache License 2.0 | 6 votes |
@NotNull @Override public Collection<AbstractTreeNode<?>> modify(@NotNull AbstractTreeNode<?> parent, @NotNull Collection<AbstractTreeNode<?>> children, ViewSettings settings) { ArrayList<AbstractTreeNode<?>> nodes = new ArrayList<>(); for (AbstractTreeNode<?> child : children) { if (child instanceof PsiFileNode) { VirtualFile file = ((PsiFileNode) child).getVirtualFile(); if (file != null && !file.isDirectory() && !(file.getFileType() instanceof PlainTextFileType)) { continue; } } nodes.add(child); } return nodes; }
Example #5
Source File: BackgroundTaskPsiFileTreeNode.java From consulo with Apache License 2.0 | 6 votes |
@Override public Collection<AbstractTreeNode> getChildrenImpl() { VirtualFile ourVirtualFile = getVirtualFile(); if(ourVirtualFile == null) { return super.getChildrenImpl(); } BackgroundTaskByVfsChangeManager vfsChangeManager = BackgroundTaskByVfsChangeManager.getInstance(getProject()); List<BackgroundTaskByVfsChangeTask> tasks = vfsChangeManager.findTasks(ourVirtualFile); if(tasks.isEmpty()) { return super.getChildrenImpl(); } List<VirtualFile> generatedFiles = new ArrayList<VirtualFile>(); for (BackgroundTaskByVfsChangeTask task : tasks) { Collections.addAll(generatedFiles, task.getGeneratedFiles()); } if(generatedFiles.isEmpty()) { return super.getChildrenImpl(); } PsiFile[] psiFiles = PsiUtilBase.virtualToPsiFiles(generatedFiles, myProject); List<AbstractTreeNode> newChildren = new ArrayList<AbstractTreeNode>(psiFiles.length); for (PsiFile psiFile : psiFiles) { newChildren.add(new PsiFileNode(getProject(), psiFile, getSettings())); } return newChildren; }
Example #6
Source File: CppSyncStatusContributor.java From intellij with Apache License 2.0 | 5 votes |
@Nullable @Override public PsiFileAndName toPsiFileAndName(BlazeProjectData projectData, ProjectViewNode<?> node) { if (!(node instanceof PsiFileNode)) { return null; } PsiFile psiFile = ((PsiFileNode) node).getValue(); if (!(psiFile instanceof OCFile)) { return null; } return new PsiFileAndName(psiFile, psiFile.getName()); }
Example #7
Source File: PySyncStatusContributor.java From intellij with Apache License 2.0 | 5 votes |
@Nullable @Override public PsiFileAndName toPsiFileAndName(BlazeProjectData projectData, ProjectViewNode<?> node) { if (!(node instanceof PsiFileNode)) { return null; } PsiFile psiFile = ((PsiFileNode) node).getValue(); if (!(psiFile instanceof PyFile)) { return null; } return new PsiFileAndName(psiFile, psiFile.getName()); }
Example #8
Source File: GoSyncStatusContributor.java From intellij with Apache License 2.0 | 5 votes |
@Nullable @Override public PsiFileAndName toPsiFileAndName(BlazeProjectData projectData, ProjectViewNode<?> node) { if (!(node instanceof PsiFileNode)) { return null; } PsiFile psiFile = ((PsiFileNode) node).getValue(); if (!(psiFile instanceof GoFile)) { return null; } return new PsiFileAndName(psiFile, psiFile.getName()); }
Example #9
Source File: PantsTreeStructureProvider.java From intellij-pants-plugin with Apache License 2.0 | 5 votes |
@NotNull private List<PsiFileNode> createNode(ViewSettings settings, Project project, VirtualFile buildFile) { final PsiFile buildPsiFile = PsiManager.getInstance(project).findFile(buildFile); if(buildPsiFile == null) return Collections.emptyList(); PsiFileNode node = new PsiFileNode(project, buildPsiFile, settings) { @Override protected void updateImpl(@NotNull PresentationData data) { super.updateImpl(data); data.setIcon(PantsIcons.Icon); } }; return Collections.singletonList(node); }
Example #10
Source File: ScratchTreeStructureProvider.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull static Collection<AbstractTreeNode> getDirectoryChildrenImpl(@Nonnull Project project, @Nullable PsiDirectory directory, @Nonnull ViewSettings settings, @Nonnull PsiFileSystemItemFilter filter) { final List<AbstractTreeNode> result = new ArrayList<>(); PsiElementProcessor<PsiFileSystemItem> processor = new PsiElementProcessor<PsiFileSystemItem>() { @Override public boolean execute(@Nonnull PsiFileSystemItem element) { if (!filter.shouldShow(element)) { // skip } else if (element instanceof PsiDirectory) { result.add(new PsiDirectoryNode(project, (PsiDirectory)element, settings, filter) { @Override public Collection<AbstractTreeNode> getChildrenImpl() { //noinspection ConstantConditions return getDirectoryChildrenImpl(getProject(), getValue(), getSettings(), getFilter()); } }); } else if (element instanceof PsiFile) { result.add(new PsiFileNode(project, (PsiFile)element, settings) { @Override public Comparable<ExtensionSortKey> getTypeSortKey() { PsiFile value = getValue(); Language language = value == null ? null : value.getLanguage(); LanguageFileType fileType = language == null ? null : language.getAssociatedFileType(); return fileType == null ? null : new ExtensionSortKey(fileType.getDefaultExtension()); } }); } return true; } }; return AbstractTreeUi.calculateYieldingToWriteAction(() -> { if (directory == null || !directory.isValid()) return Collections.emptyList(); directory.processChildren(processor); return result; }); }
Example #11
Source File: PantsTreeStructureProvider.java From intellij-pants-plugin with Apache License 2.0 | 4 votes |
private boolean alreadyExists(Collection<AbstractTreeNode<?>> collection, VirtualFile buildFile) { Condition<AbstractTreeNode<?>> isBuildFile = node -> node instanceof PsiFileNode && buildFile.equals(((PsiFileNode) node).getVirtualFile()); return ContainerUtil.exists(collection, isBuildFile); }
Example #12
Source File: FileDecoration.java From SVNToolBox with Apache License 2.0 | 4 votes |
private String getName(ProjectViewNode node) { PsiFileNode fileNode = (PsiFileNode) node; return fileNode.getValue().getName(); }
Example #13
Source File: FileDecoration.java From SVNToolBox with Apache License 2.0 | 4 votes |
@Override protected VirtualFile getVirtualFile(ProjectViewNode node) { PsiFileNode fileNode = (PsiFileNode) node; return fileNode.getVirtualFile(); }
Example #14
Source File: FileDecoration.java From SVNToolBox with Apache License 2.0 | 4 votes |
@Override public boolean isForMe(ProjectViewNode node) { return (node instanceof PsiFileNode); }