Search in sources :

Example 21 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class GradleTreeStructureProvider method getProjectNodeChildren.

@NotNull
private static Collection<AbstractTreeNode> getProjectNodeChildren(@NotNull Project project, @NotNull Collection<AbstractTreeNode> children) {
    Collection<AbstractTreeNode> modifiedChildren = ContainerUtil.newSmartList();
    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    for (AbstractTreeNode child : children) {
        Pair<VirtualFile, PsiDirectoryNode> parentNodePair = null;
        if (child instanceof ProjectViewModuleGroupNode) {
            final ProjectViewModuleGroupNode groupNode = (ProjectViewModuleGroupNode) child;
            final Collection<AbstractTreeNode> groupNodeChildren = groupNode.getChildren();
            for (final AbstractTreeNode node : groupNodeChildren) {
                if (node instanceof PsiDirectoryNode) {
                    final PsiDirectoryNode psiDirectoryNode = (PsiDirectoryNode) node;
                    final PsiDirectory psiDirectory = psiDirectoryNode.getValue();
                    if (psiDirectory == null) {
                        parentNodePair = null;
                        break;
                    }
                    final VirtualFile virtualFile = psiDirectory.getVirtualFile();
                    final Module module = fileIndex.getModuleForFile(virtualFile);
                    if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) {
                        parentNodePair = null;
                        break;
                    }
                    if (parentNodePair == null || VfsUtilCore.isAncestor(virtualFile, parentNodePair.first, false)) {
                        parentNodePair = Pair.pair(virtualFile, psiDirectoryNode);
                    } else if (!VfsUtilCore.isAncestor(parentNodePair.first, virtualFile, false)) {
                        parentNodePair = null;
                        break;
                    }
                } else {
                    parentNodePair = null;
                    break;
                }
            }
        }
        modifiedChildren.add(parentNodePair != null ? parentNodePair.second : child);
    }
    return modifiedChildren;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class SummaryNode method getChildren.

@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
    ArrayList<AbstractTreeNode> children = new ArrayList<>();
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(getProject()).getFileIndex();
    if (myToDoSettings.isModulesShown()) {
        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();
            createModuleTodoNodeForFile(children, projectFileIndex, virtualFile);
        }
    } else {
        if (myToDoSettings.getIsPackagesShown()) {
            if (myBuilder instanceof CurrentFileTodosTreeBuilder) {
                final Iterator allFiles = myBuilder.getAllFiles();
                if (allFiles.hasNext()) {
                    children.add(new TodoFileNode(myProject, (PsiFile) allFiles.next(), myBuilder, false));
                }
            } else {
                TodoTreeHelper.getInstance(getProject()).addPackagesToChildren(children, null, myBuilder);
            }
        } else {
            for (Iterator i = myBuilder.getAllFiles(); i.hasNext(); ) {
                final PsiFile psiFile = (PsiFile) i.next();
                if (psiFile == null) {
                    // skip invalid PSI files
                    continue;
                }
                TodoFileNode fileNode = new TodoFileNode(getProject(), psiFile, myBuilder, false);
                if (getTreeStructure().accept(psiFile) && !children.contains(fileNode)) {
                    children.add(fileNode);
                }
            }
        }
    }
    Collections.sort(children, TodoFileDirAndModuleComparator.INSTANCE);
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) CurrentFileTodosTreeBuilder(com.intellij.ide.todo.CurrentFileTodosTreeBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class TodoFileNode method createListForSingleFile.

private Collection<AbstractTreeNode> createListForSingleFile() {
    PsiFile psiFile = getValue();
    TodoItem[] items = findAllTodos(psiFile, myBuilder.getTodoTreeStructure().getSearchHelper());
    ArrayList<AbstractTreeNode> children = new ArrayList<>(items.length);
    Document document = PsiDocumentManager.getInstance(getProject()).getDocument(psiFile);
    if (document != null) {
        for (TodoItem todoItem : items) {
            if (todoItem.getTextRange().getEndOffset() < document.getTextLength() + 1) {
                SmartTodoItemPointer pointer = new SmartTodoItemPointer(todoItem, document);
                TodoFilter toDoFilter = getToDoFilter();
                if (toDoFilter != null) {
                    TodoItemNode itemNode = new TodoItemNode(getProject(), pointer, myBuilder);
                    if (toDoFilter.contains(todoItem.getPattern())) {
                        children.add(itemNode);
                    }
                } else {
                    children.add(new TodoItemNode(getProject(), pointer, myBuilder));
                }
            }
        }
    }
    Collections.sort(children, SmartTodoItemPointerComparator.ourInstance);
    return children;
}
Also used : TodoItem(com.intellij.psi.search.TodoItem) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Document(com.intellij.openapi.editor.Document)

Example 24 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class FileStructureDialog method addCheckbox.

private void addCheckbox(final JPanel panel, final TreeAction action) {
    String text = action instanceof FileStructureFilter ? ((FileStructureFilter) action).getCheckBoxText() : action instanceof FileStructureNodeProvider ? ((FileStructureNodeProvider) action).getCheckBoxText() : null;
    if (text == null)
        return;
    Shortcut[] shortcuts = FileStructurePopup.extractShortcutFor(action);
    final JCheckBox chkFilter = new JCheckBox();
    chkFilter.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            ProjectListBuilder builder = (ProjectListBuilder) myCommanderPanel.getBuilder();
            PsiElement currentParent = null;
            if (builder != null) {
                final AbstractTreeNode parentNode = builder.getParentNode();
                final Object value = parentNode.getValue();
                if (value instanceof StructureViewTreeElement) {
                    final Object elementValue = ((StructureViewTreeElement) value).getValue();
                    if (elementValue instanceof PsiElement) {
                        currentParent = (PsiElement) elementValue;
                    }
                }
            }
            final boolean state = chkFilter.isSelected();
            myTreeActionsOwner.setActionIncluded(action, action instanceof FileStructureFilter ? !state : state);
            myTreeStructure.rebuildTree();
            if (builder != null) {
                if (currentParent != null) {
                    boolean oldNarrowDown = myShouldNarrowDown;
                    myShouldNarrowDown = false;
                    try {
                        builder.enterElement(currentParent, PsiUtilCore.getVirtualFile(currentParent));
                    } finally {
                        myShouldNarrowDown = oldNarrowDown;
                    }
                }
                builder.updateList(true);
            }
            if (SpeedSearchBase.hasActiveSpeedSearch(myCommanderPanel.getList())) {
                final SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myCommanderPanel.getList());
                if (supply != null && supply.isPopupActive())
                    supply.refreshSelection();
            }
        }
    });
    chkFilter.setFocusable(false);
    if (shortcuts.length > 0) {
        text += " (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")";
        new AnAction() {

            @Override
            public void actionPerformed(final AnActionEvent e) {
                chkFilter.doClick();
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(shortcuts), myCommanderPanel);
    }
    chkFilter.setText(text);
    panel.add(chkFilter);
//,new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
}
Also used : ProjectListBuilder(com.intellij.ide.commander.ProjectListBuilder) ActionEvent(java.awt.event.ActionEvent) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ActionListener(java.awt.event.ActionListener) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) PsiElement(com.intellij.psi.PsiElement)

Example 25 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class FileStructureDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myCommanderPanel = new MyCommanderPanel(myProject);
    myTreeStructure = new MyStructureTreeStructure();
    List<FileStructureFilter> fileStructureFilters = new ArrayList<>();
    List<FileStructureNodeProvider> fileStructureNodeProviders = new ArrayList<>();
    if (myTreeActionsOwner != null) {
        for (Filter filter : myBaseTreeModel.getFilters()) {
            if (filter instanceof FileStructureFilter) {
                final FileStructureFilter fsFilter = (FileStructureFilter) filter;
                myTreeActionsOwner.setActionIncluded(fsFilter, true);
                fileStructureFilters.add(fsFilter);
            }
        }
        if (myBaseTreeModel instanceof ProvidingTreeModel) {
            for (NodeProvider provider : ((ProvidingTreeModel) myBaseTreeModel).getNodeProviders()) {
                if (provider instanceof FileStructureNodeProvider) {
                    fileStructureNodeProviders.add((FileStructureNodeProvider) provider);
                }
            }
        }
    }
    PsiFile psiFile = getPsiFile(myProject);
    boolean showRoot = isShowRoot(psiFile);
    ProjectListBuilder projectListBuilder = new ProjectListBuilder(myProject, myCommanderPanel, myTreeStructure, null, showRoot) {

        @Override
        protected boolean shouldEnterSingleTopLevelElement(Object rootChild) {
            Object element = ((StructureViewTreeElement) ((AbstractTreeNode) rootChild).getValue()).getValue();
            return myBaseTreeModel.shouldEnterElement(element);
        }

        @Override
        protected boolean nodeIsAcceptableForElement(AbstractTreeNode node, Object element) {
            return Comparing.equal(((StructureViewTreeElement) node.getValue()).getValue(), element);
        }

        @Override
        protected void refreshSelection() {
            myCommanderPanel.scrollSelectionInView();
            if (myShouldNarrowDown) {
                myCommanderPanel.updateSpeedSearch();
            }
        }

        @Override
        protected List<AbstractTreeNode> getAllAcceptableNodes(final Object[] childElements, VirtualFile file) {
            ArrayList<AbstractTreeNode> result = new ArrayList<>();
            for (Object childElement : childElements) {
                result.add((AbstractTreeNode) childElement);
            }
            return result;
        }
    };
    myCommanderPanel.setBuilder(projectListBuilder);
    myCommanderPanel.setTitlePanelVisible(false);
    new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final boolean succeeded = myCommanderPanel.navigateSelectedElement();
            if (succeeded) {
                unregisterCustomShortcutSet(myCommanderPanel);
            }
        }
    }.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getShortcutSet(), myCommanderPanel);
    myCommanderPanel.setPreferredSize(JBUI.size(400, 500));
    JPanel panel = new JPanel(new BorderLayout());
    JPanel comboPanel = new JPanel(new GridLayout(0, 2, 0, 0));
    addNarrowDownCheckbox(comboPanel);
    for (FileStructureFilter filter : fileStructureFilters) {
        addCheckbox(comboPanel, filter);
    }
    for (FileStructureNodeProvider provider : fileStructureNodeProviders) {
        addCheckbox(comboPanel, provider);
    }
    myCommanderPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
    panel.add(comboPanel, BorderLayout.NORTH);
    panel.add(myCommanderPanel, BorderLayout.CENTER);
    return panel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectListBuilder(com.intellij.ide.commander.ProjectListBuilder) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement)

Aggregations

AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)154 NotNull (org.jetbrains.annotations.NotNull)69 ArrayList (java.util.ArrayList)52 VirtualFile (com.intellij.openapi.vfs.VirtualFile)43 Project (com.intellij.openapi.project.Project)36 PsiFile (com.intellij.psi.PsiFile)31 Module (com.intellij.openapi.module.Module)29 PsiDirectory (com.intellij.psi.PsiDirectory)27 PsiElement (com.intellij.psi.PsiElement)17 Nullable (org.jetbrains.annotations.Nullable)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 PsiManager (com.intellij.psi.PsiManager)11 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)10 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)10 List (java.util.List)10 PresentationData (com.intellij.ide.projectView.PresentationData)6 ViewSettings (com.intellij.ide.projectView.ViewSettings)6 PsiFileNode (com.intellij.ide.projectView.impl.nodes.PsiFileNode)6 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)5 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)5