com.intellij.ide.util.treeView.AbstractTreeNode Java Examples
The following examples show how to use
com.intellij.ide.util.treeView.AbstractTreeNode.
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: RTMergerTreeStructureProvider.java From react-templates-plugin with MIT License | 6 votes |
private static PsiElement[] collectFormPsiElements(Collection<AbstractTreeNode> selected) { Set<PsiElement> result = new HashSet<PsiElement>(); for (AbstractTreeNode node : selected) { if (node.getValue() instanceof RTFile) { RTFile form = (RTFile) node.getValue(); result.add(form.getRtjsFile()); if (form.getController() != null) { result.add(form.getController()); } ContainerUtil.addAll(result, form.getRtFile()); } else if (node.getValue() instanceof PsiElement) { result.add((PsiElement) node.getValue()); } } return PsiUtilCore.toPsiElementArray(result); }
Example #2
Source File: ProjectViewTestUtil.java From consulo with Apache License 2.0 | 6 votes |
public static void checkContainsMethod(final Object rootElement, final AbstractTreeStructure structure, Function<AbstractTreeNode, VirtualFile[]> converterFunction) { MultiValuesMap<VirtualFile, AbstractTreeNode> map = new MultiValuesMap<VirtualFile, AbstractTreeNode>(); collect((AbstractTreeNode)rootElement, map, structure, converterFunction); for (VirtualFile eachFile : map.keySet()) { Collection<AbstractTreeNode> nodes = map.values(); for (final AbstractTreeNode node : nodes) { ProjectViewNode eachNode = (ProjectViewNode)node; boolean actual = eachNode.contains(eachFile); boolean expected = map.get(eachFile).contains(eachNode); if (actual != expected) { boolean actual1 = eachNode.contains(eachFile); boolean expected1 = map.get(eachFile).contains(eachNode); Assert.assertTrue("file=" + eachFile + " node=" + eachNode.getTestPresentation() + " expected:" + expected, false); } } } }
Example #3
Source File: ModuleListNode.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nonnull public Collection<AbstractTreeNode> getChildren() { Module module = getValue(); final Module[] deps = ModuleRootManager.getInstance(module).getDependencies(true); final List<AbstractTreeNode> children = new ArrayList<AbstractTreeNode>(); for (Module dependency : deps) { children.add(new ProjectViewModuleNode(myProject, dependency, getSettings()) { @Override protected boolean showModuleNameInBold() { return false; } }); } return children; }
Example #4
Source File: TreeStructureWrappenModel.java From consulo with Apache License 2.0 | 6 votes |
@Override public void fetchChildren(@Nonnull Function<T, TreeNode<T>> nodeFactory, @Nullable T parentValue) { ThrowableComputable<Object[],RuntimeException> action = () -> myStructure.getChildElements(parentValue); for (Object o : AccessRule.read(action)) { T element = (T)o; TreeNode<T> apply = nodeFactory.apply(element); apply.setLeaf(o instanceof AbstractTreeNode && !((AbstractTreeNode)o).isAlwaysShowPlus()); apply.setRender((fileElement, itemPresentation) -> { NodeDescriptor descriptor = myStructure.createDescriptor(element, null); descriptor.update(); itemPresentation.append(descriptor.toString()); try { AccessRule.read(() -> itemPresentation.setIcon(descriptor.getIcon())); } catch (Exception e) { e.printStackTrace(); } }); } }
Example #5
Source File: TodoFileNode.java From consulo with Apache License 2.0 | 6 votes |
private Collection<AbstractTreeNode> createGeneralList() { ArrayList<AbstractTreeNode> children = new ArrayList<>(); PsiFile psiFile = getValue(); final TodoItem[] items = findAllTodos(psiFile, myBuilder.getTodoTreeStructure().getSearchHelper()); final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(psiFile); if (document != null) { for (final TodoItem todoItem : items) { if (todoItem.getTextRange().getEndOffset() < document.getTextLength() + 1) { final SmartTodoItemPointer pointer = new SmartTodoItemPointer(todoItem, document); TodoFilter todoFilter = getToDoFilter(); if (todoFilter != null) { if (todoFilter.contains(todoItem.getPattern())) { children.add(new TodoItemNode(getProject(), pointer, myBuilder)); } } else { children.add(new TodoItemNode(getProject(), pointer, myBuilder)); } } } } Collections.sort(children, SmartTodoItemPointerComparator.ourInstance); return children; }
Example #6
Source File: ModuleToDoNode.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nonnull public Collection<AbstractTreeNode> getChildren() { ArrayList<AbstractTreeNode> children = new ArrayList<>(); if (myToDoSettings.getIsPackagesShown()) { TodoTreeHelper.addPackagesToChildren(children, getProject(), getValue(), myBuilder); } else { for (Iterator i = myBuilder.getAllFiles(); i.hasNext(); ) { final PsiFile psiFile = (PsiFile)i.next(); if (psiFile == null) { // skip invalid PSI files continue; } final VirtualFile virtualFile = psiFile.getVirtualFile(); final boolean isInContent = ModuleRootManager.getInstance(getValue()).getFileIndex().isInContent(virtualFile); if (!isInContent) continue; TodoFileNode fileNode = new TodoFileNode(getProject(), psiFile, myBuilder, false); if (getTreeStructure().accept(psiFile) && !children.contains(fileNode)) { children.add(fileNode); } } } return children; }
Example #7
Source File: ImagesProjectViewPane.java From intellij-sdk-docs with Apache License 2.0 | 6 votes |
@NotNull @Override protected ProjectAbstractTreeStructureBase createStructure() { return new ProjectTreeStructure(myProject, ID) { @Override protected AbstractTreeNode createRoot(@NotNull Project project, @NotNull ViewSettings settings) { return new ImagesProjectNode(project); } @NotNull @Override public Object[] getChildElements(@NotNull Object element) { return super.getChildElements(element); } }; }
Example #8
Source File: CommanderPanel.java From consulo with Apache License 2.0 | 6 votes |
public void drillDown() { if (topElementIsSelected()) { goUp(); return; } if (getSelectedValue() == null) { return; } final AbstractTreeNode element = getSelectedNode(); if (element.getChildren().isEmpty()) { if (!shouldDrillDownOnEmptyElement(element)) { navigateSelectedElement(); return; } } if (myBuilder == null) { return; } updateHistory(false); myBuilder.drillDown(); updateHistory(true); }
Example #9
Source File: FavoritesManager.java From consulo with Apache License 2.0 | 6 votes |
public boolean addRoots(final String name, final Collection<AbstractTreeNode> nodes) { final Collection<TreeItem<Pair<AbstractUrl, String>>> list = getFavoritesListRootUrls(name); final HashSet<AbstractUrl> set = new HashSet<AbstractUrl>(ContainerUtil.map(list, new Function<TreeItem<Pair<AbstractUrl, String>>, AbstractUrl>() { @Override public AbstractUrl fun(TreeItem<Pair<AbstractUrl, String>> item) { return item.getData().getFirst(); } })); for (AbstractTreeNode node : nodes) { final Pair<AbstractUrl, String> pair = createPairForNode(node); if (pair != null) { if (set.contains(pair.getFirst())) continue; final TreeItem<Pair<AbstractUrl, String>> treeItem = new TreeItem<Pair<AbstractUrl, String>>(pair); list.add(treeItem); set.add(pair.getFirst()); appendChildNodes(node, treeItem); } } rootsChanged(); return true; }
Example #10
Source File: FileStructurePopup.java From consulo with Apache License 2.0 | 5 votes |
public void show() { JComponent panel = createCenterPanel(); MnemonicHelper.init(panel); myTree.addTreeSelectionListener(__ -> { if (myPopup.isVisible()) { PopupUpdateProcessor updateProcessor = myPopup.getUserData(PopupUpdateProcessor.class); if (updateProcessor != null) { AbstractTreeNode node = getSelectedNode(); updateProcessor.updatePopup(node); } } }); myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, myTree).setTitle(myTitle).setResizable(true).setModalContext(false).setFocusable(true).setRequestFocus(true) .setMovable(true).setBelongsToGlobalPopupStack(true) //.setCancelOnClickOutside(false) //for debug and snapshots .setCancelOnOtherWindowOpen(true).setCancelKeyEnabled(false).setDimensionServiceKey(null, getDimensionServiceKey(), true).setCancelCallback(() -> myCanClose).setNormalWindowLevel(true) .createPopup(); Disposer.register(myPopup, this); Disposer.register(myPopup, () -> { if (!myTreeHasBuilt.isDone()) { myTreeHasBuilt.setRejected(); } }); myTree.getEmptyText().setText("Loading..."); myPopup.showCenteredInCurrentWindow(myProject); ((AbstractPopup)myPopup).setShowHints(true); IdeFocusManager.getInstance(myProject).requestFocus(myTree, true); rebuildAndSelect(false, myInitialElement).onProcessed(path -> UIUtil.invokeLaterIfNeeded(() -> { TreeUtil.ensureSelection(myTree); myTreeHasBuilt.setDone(); installUpdater(); })); }
Example #11
Source File: CachingChildrenTreeNode.java From consulo with Apache License 2.0 | 5 votes |
protected void groupChildren(Grouper[] groupers) { for (Grouper grouper : groupers) { groupElements(grouper); } Collection<AbstractTreeNode> children = getChildren(); for (AbstractTreeNode child : children) { if (child instanceof GroupWrapper) { ((GroupWrapper)child).groupChildren(groupers); } } }
Example #12
Source File: FavoritesManager.java From consulo with Apache License 2.0 | 5 votes |
List<AbstractTreeNode> createRootNodes() { List<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>(); for (String listName : myName2FavoritesRoots.keySet()) { result.add(new FavoritesListNode(myProject, listName, myDescriptions.get(listName))); } ArrayList<FavoritesListProvider> providers = new ArrayList<FavoritesListProvider>(myProviders.values()); Collections.sort(providers); for (FavoritesListProvider provider : providers) { result.add(provider.createFavoriteListNode(myProject)); } return result; }
Example #13
Source File: FavoritesTreeViewPanel.java From consulo with Apache License 2.0 | 5 votes |
static FavoritesListNode getListNodeFromPath(TreePath path) { if (path != null && path.getPathCount() > 1) { final Object o = path.getPath()[1]; if (o instanceof DefaultMutableTreeNode) { final Object obj = ((DefaultMutableTreeNode)o).getUserObject(); if (obj instanceof FavoritesTreeNodeDescriptor) { final AbstractTreeNode node = ((FavoritesTreeNodeDescriptor)obj).getElement(); if (node instanceof FavoritesListNode) { return (FavoritesListNode)node; } } } } return null; }
Example #14
Source File: AbstractListBuilder.java From consulo with Apache License 2.0 | 5 votes |
private Object[] getChildren(final AbstractTreeNode parentElement) { if (parentElement == null) { return new Object[]{myTreeStructure.getRootElement()}; } else { return myTreeStructure.getChildElements(parentElement); } }
Example #15
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 #16
Source File: ServersToolWindowContent.java From consulo with Apache License 2.0 | 5 votes |
private void onSelectionChanged() { Set<AbstractTreeNode> nodes = myBuilder.getSelectedElements(AbstractTreeNode.class); if (nodes.size() != 1) { showMessageLabel(EMPTY_SELECTION_MESSAGE); myLastSelection = null; return; } AbstractTreeNode<?> node = nodes.iterator().next(); if (Comparing.equal(node, myLastSelection)) { return; } myLastSelection = node; if (node instanceof ServersTreeStructure.LogProvidingNode) { ServersTreeStructure.LogProvidingNode logNode = (ServersTreeStructure.LogProvidingNode)node; LoggingHandlerImpl loggingHandler = logNode.getLoggingHandler(); if (loggingHandler != null) { String cardName = logNode.getLogId(); JComponent oldComponent = myLogComponents.get(cardName); JComponent logComponent = loggingHandler.getConsole().getComponent(); if (!logComponent.equals(oldComponent)) { myLogComponents.put(cardName, logComponent); if (oldComponent != null) { myPropertiesPanel.remove(oldComponent); } myPropertiesPanel.add(cardName, logComponent); } myPropertiesPanelLayout.show(myPropertiesPanel, cardName); } } else if (node instanceof ServersTreeStructure.RemoteServerNode) { updateServerDetails((ServersTreeStructure.RemoteServerNode)node); } else { showMessageLabel(""); } }
Example #17
Source File: FavoritesTreeUtil.java From consulo with Apache License 2.0 | 5 votes |
static FavoritesListProvider getProvider(@Nonnull FavoritesManager manager, @Nonnull FavoritesTreeNodeDescriptor descriptor) { AbstractTreeNode treeNode = descriptor.getElement(); while (treeNode != null && (!(treeNode instanceof FavoritesListNode))) { treeNode = treeNode.getParent(); } if (treeNode != null) { final String name = ((FavoritesListNode)treeNode).getValue(); return manager.getListProvider(name); } return null; }
Example #18
Source File: PsiFileNode.java From consulo with Apache License 2.0 | 5 votes |
@Override public Collection<AbstractTreeNode> getChildrenImpl() { Project project = getProject(); VirtualFile jarRoot = getArchiveRoot(); if (project != null && jarRoot != null) { PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(jarRoot); if (psiDirectory != null) { return BaseProjectViewDirectoryHelper.getDirectoryChildren(psiDirectory, getSettings(), true); } } return ContainerUtil.emptyList(); }
Example #19
Source File: CoverageView.java From consulo with Apache License 2.0 | 5 votes |
private boolean topElementIsSelected(final CoverageViewTreeStructure treeStructure) { if (myTable == null) return false; if (myModel.getSize() >= 1) { final AbstractTreeNode rootElement = (AbstractTreeNode)treeStructure.getRootElement(); final AbstractTreeNode node = (AbstractTreeNode)myModel.getElementAt(0); if (node.getParent() == rootElement) { return true; } } return false; }
Example #20
Source File: CachingChildrenTreeNode.java From consulo with Apache License 2.0 | 5 votes |
protected void filterChildren(Filter[] filters) { Collection<AbstractTreeNode> children = getChildren(); for (Filter filter : filters) { for (Iterator<AbstractTreeNode> eachNode = children.iterator(); eachNode.hasNext();) { TreeElementWrapper eachChild = (TreeElementWrapper)eachNode.next(); if (!filter.isVisible(eachChild.getValue())) { eachNode.remove(); } } } setChildren(children); }
Example #21
Source File: PackageNodeUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static Collection<AbstractTreeNode> createPackageViewChildrenOnFiles(@Nonnull List<VirtualFile> sourceRoots, @Nonnull Project project, @Nonnull ViewSettings settings, @Nullable Module module, final boolean inLibrary) { final PsiManager psiManager = PsiManager.getInstance(project); final List<AbstractTreeNode> children = new ArrayList<AbstractTreeNode>(); final Set<PsiPackage> topLevelPackages = new HashSet<PsiPackage>(); for (final VirtualFile root : sourceRoots) { final PsiDirectory directory = psiManager.findDirectory(root); if (directory == null) { continue; } final PsiPackage directoryPackage = PsiPackageManager.getInstance(project).findAnyPackage(directory); if (directoryPackage == null || isPackageDefault(directoryPackage)) { // add subpackages final PsiDirectory[] subdirectories = directory.getSubdirectories(); for (PsiDirectory subdirectory : subdirectories) { final PsiPackage aPackage = PsiPackageManager.getInstance(project).findAnyPackage(subdirectory); if (aPackage != null && !isPackageDefault(aPackage)) { topLevelPackages.add(aPackage); } } // add non-dir items children.addAll(BaseProjectViewDirectoryHelper.getDirectoryChildren(directory, settings, false)); } else { topLevelPackages.add(directoryPackage); } } for (final PsiPackage topLevelPackage : topLevelPackages) { addPackageAsChild(children, topLevelPackage, module, settings, inLibrary); } return children; }
Example #22
Source File: FavoritesListNode.java From consulo with Apache License 2.0 | 5 votes |
private static void processUrls(Project project, Collection<TreeItem<Pair<AbstractUrl, String>>> urls, Collection<AbstractTreeNode> result, final AbstractTreeNode me) { for (TreeItem<Pair<AbstractUrl, String>> pair : urls) { AbstractUrl abstractUrl = pair.getData().getFirst(); final Object[] path = abstractUrl.createPath(project); if (path == null || path.length < 1 || path[0] == null) { continue; } try { final String className = pair.getData().getSecond(); @SuppressWarnings("unchecked") final Class<? extends AbstractTreeNode> nodeClass = (Class<? extends AbstractTreeNode>)Class.forName(className); final AbstractTreeNode node = ProjectViewNode .createTreeNode(nodeClass, project, path[path.length - 1], FavoritesManager.getInstance(project).getViewSettings()); node.setParent(me); node.setIndex(result.size()); result.add(node); if (node instanceof ProjectViewNodeWithChildrenList) { final List<TreeItem<Pair<AbstractUrl, String>>> children = pair.getChildren(); if (children != null && !children.isEmpty()) { Collection<AbstractTreeNode> childList = new ArrayList<AbstractTreeNode>(); processUrls(project, children, childList, node); for (AbstractTreeNode treeNode : childList) { ((ProjectViewNodeWithChildrenList)node).addChild(treeNode); } } } } catch (Exception ignored) { } } }
Example #23
Source File: AbstractListBuilder.java From consulo with Apache License 2.0 | 5 votes |
private AbstractTreeNode findInChildren(AbstractTreeNode rootElement, VirtualFile file, Object element) { Object[] childElements = getChildren(rootElement); List<AbstractTreeNode> nodes = getAllAcceptableNodes(childElements, file); if (nodes.size() == 1) return nodes.get(0); if (nodes.isEmpty()) return null; if (file.isDirectory()) { return nodes.get(0); } else { return performDeepSearch(nodes.toArray(), element, new THashSet<AbstractTreeNode>()); } }
Example #24
Source File: ProjectViewTestUtil.java From consulo with Apache License 2.0 | 5 votes |
public static VirtualFile[] getFiles(AbstractTreeNode kid, Function<AbstractTreeNode, VirtualFile[]> converterFunction) { if (kid instanceof BasePsiNode) { Object value = kid.getValue(); VirtualFile virtualFile = PsiUtilBase.getVirtualFile((PsiElement)value); return new VirtualFile[]{virtualFile}; } if (converterFunction != null) { final VirtualFile[] result = converterFunction.fun(kid); if (result != null) { return result; } } return new VirtualFile[0]; }
Example #25
Source File: CommanderPanel.java From consulo with Apache License 2.0 | 5 votes |
public boolean navigateSelectedElement() { final AbstractTreeNode selectedNode = getSelectedNode(); if (selectedNode != null) { if (selectedNode.canNavigateToSource()) { selectedNode.navigate(true); return true; } } return false; }
Example #26
Source File: RunDashboardTreeStructure.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public Collection<? extends AbstractTreeNode> getChildren() { List<RunConfigurationNode> nodes = RunDashboardManager.getInstance(myProject).getRunConfigurations().stream() .map(value -> new RunConfigurationNode(myProject, value)).collect(Collectors.toList()); return group(myProject, this, myGroupers.stream().filter(DashboardGrouper::isEnabled).map(DashboardGrouper::getRule).collect(Collectors.toList()), nodes); }
Example #27
Source File: ScratchTreeStructureProvider.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public Collection<? extends AbstractTreeNode<?>> getChildren() { List<AbstractTreeNode<?>> list = new ArrayList<>(); Project project = Objects.requireNonNull(getProject()); for (RootType rootType : RootType.getAllRootTypes()) { ContainerUtil.addIfNotNull(list, createRootTypeNode(project, rootType, getSettings())); } return list; }
Example #28
Source File: FolderDashboardGroupingRule.java From consulo with Apache License 2.0 | 5 votes |
@Nullable @Override public DashboardGroup getGroup(AbstractTreeNode<?> node) { if (node instanceof DashboardRunConfigurationNode) { RunnerAndConfigurationSettings configurationSettings = ((DashboardRunConfigurationNode)node).getConfigurationSettings(); String folderName = configurationSettings.getFolderName(); if (folderName != null) { return new DashboardGroupImpl<>(folderName, folderName, AllIcons.Nodes.Folder); } } return null; }
Example #29
Source File: FileStructureDialog.java From consulo with Apache License 2.0 | 5 votes |
@Override public Object[] getChildElements(Object element) { Object[] childElements = super.getChildElements(element); if (!myShouldNarrowDown) { return childElements; } String enteredPrefix = myCommanderPanel.getEnteredPrefix(); if (enteredPrefix == null) { return childElements; } ArrayList<Object> filteredElements = new ArrayList<Object>(childElements.length); SpeedSearchComparator speedSearchComparator = createSpeedSearchComparator(); for (Object child : childElements) { if (child instanceof AbstractTreeNode) { Object value = ((AbstractTreeNode)child).getValue(); if (value instanceof TreeElement) { String name = ((TreeElement)value).getPresentation().getPresentableText(); if (name == null) { continue; } if (speedSearchComparator.matchingFragments(enteredPrefix, name) == null) { continue; } } } filteredElements.add(child); } return ArrayUtil.toObjectArray(filteredElements); }
Example #30
Source File: PackageViewPane.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private PackageElement getSelectedPackageElement() { PackageElement result = null; final DefaultMutableTreeNode selectedNode = getSelectedNode(); if (selectedNode != null) { Object o = selectedNode.getUserObject(); if (o instanceof AbstractTreeNode) { Object selected = ((AbstractTreeNode)o).getValue(); result = selected instanceof PackageElement ? (PackageElement)selected : null; } } return result; }