Search in sources :

Example 36 with AbstractTreeNode

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

the class CommanderPanel method getSelectedNodes.

@NotNull
private List<AbstractTreeNode> getSelectedNodes() {
    if (myBuilder == null)
        return Collections.emptyList();
    final int[] indices = myList.getSelectedIndices();
    ArrayList<AbstractTreeNode> result = new ArrayList<>();
    for (int index : indices) {
        if (index >= myModel.getSize())
            continue;
        Object elementAtIndex = myModel.getElementAt(index);
        AbstractTreeNode node = elementAtIndex instanceof AbstractTreeNode ? (AbstractTreeNode) elementAtIndex : null;
        if (node != null) {
            result.add(node);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with AbstractTreeNode

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

the class AbstractListBuilder method selectElement.

public final void selectElement(final Object element, VirtualFile virtualFile) {
    if (element == null) {
        return;
    }
    try {
        AbstractTreeNode node = goDownToElement(element, virtualFile);
        if (node == null)
            return;
        AbstractTreeNode parentElement = node.getParent();
        if (parentElement == null)
            return;
        buildList(parentElement);
        for (int i = 0; i < myModel.getSize(); i++) {
            if (myModel.getElementAt(i) instanceof AbstractTreeNode) {
                final AbstractTreeNode desc = (AbstractTreeNode) myModel.getElementAt(i);
                if (desc.getValue() instanceof StructureViewTreeElement) {
                    StructureViewTreeElement treeelement = (StructureViewTreeElement) desc.getValue();
                    if (element.equals(treeelement.getValue())) {
                        selectItem(i);
                        break;
                    }
                } else {
                    if (element.equals(desc.getValue())) {
                        selectItem(i);
                        break;
                    }
                }
            }
        }
    } finally {
        updateParentTitle();
    }
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement)

Example 38 with AbstractTreeNode

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

the class AbstractListBuilder method enterElement.

public final void enterElement(final PsiElement element, VirtualFile file) {
    try {
        AbstractTreeNode lastPathNode = goDownToElement(element, file);
        if (lastPathNode == null)
            return;
        buildList(lastPathNode);
        ensureSelectionExist();
    } finally {
        updateParentTitle();
    }
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 39 with AbstractTreeNode

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

the class AbstractListBuilder method updateList.

protected final void updateList() {
    if (myIsDisposed || myCurrentParent == null) {
        return;
    }
    if (myTreeStructure.hasSomethingToCommit()) {
        myTreeStructure.commit();
    }
    AbstractTreeNode parentDescriptor = myCurrentParent;
    while (true) {
        parentDescriptor.update();
        if (parentDescriptor.getValue() != null)
            break;
        parentDescriptor = parentDescriptor.getParent();
    }
    final Object[] children = getChildren(parentDescriptor);
    final HashMap<Object, Integer> elementToIndexMap = new HashMap<>();
    for (int i = 0; i < children.length; i++) {
        elementToIndexMap.put(children[i], Integer.valueOf(i));
    }
    final List<NodeDescriptor> resultDescriptors = new ArrayList<>();
    final Object[] listChildren = myModel.toArray();
    for (final Object child : listChildren) {
        if (!(child instanceof NodeDescriptor)) {
            continue;
        }
        final NodeDescriptor descriptor = (NodeDescriptor) child;
        descriptor.update();
        final Object newElement = descriptor.getElement();
        final Integer index = newElement != null ? elementToIndexMap.get(newElement) : null;
        if (index != null) {
            resultDescriptors.add(descriptor);
            descriptor.setIndex(index.intValue());
            elementToIndexMap.remove(newElement);
        }
    }
    for (final Object child : elementToIndexMap.keySet()) {
        final Integer index = elementToIndexMap.get(child);
        if (index != null) {
            final NodeDescriptor childDescr = myTreeStructure.createDescriptor(child, parentDescriptor);
            childDescr.setIndex(index.intValue());
            childDescr.update();
            resultDescriptors.add(childDescr);
        }
    }
    final SelectionInfo selection = storeSelection();
    if (myComparator != null) {
        Collections.sort(resultDescriptors, myComparator);
    } else {
        Collections.sort(resultDescriptors, IndexComparator.INSTANCE);
    }
    if (shouldAddTopElement()) {
        final List elems = new ArrayList();
        elems.add(new TopLevelNode(myProject, parentDescriptor.getValue()));
        elems.addAll(resultDescriptors);
        myModel.replaceElements(elems);
    } else {
        myModel.replaceElements(resultDescriptors);
    }
    restoreSelection(selection);
    updateParentTitle();
}
Also used : HashMap(com.intellij.util.containers.HashMap) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) List(java.util.List)

Example 40 with AbstractTreeNode

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

the class AbstractListBuilder method performDeepSearch.

private AbstractTreeNode performDeepSearch(Object[] nodes, Object element, Set<AbstractTreeNode> visited) {
    for (Object node1 : nodes) {
        AbstractTreeNode node = (AbstractTreeNode) node1;
        if (nodeIsAcceptableForElement(node, element))
            return node;
        Object[] children = getChildren(node);
        if (visited.add(node)) {
            AbstractTreeNode nodeResult = performDeepSearch(children, element, visited);
            if (nodeResult != null) {
                return nodeResult;
            }
        }
    }
    return null;
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

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