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