use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class FavoritesTreeUtil method getLogicalPathTo.
/*private static int getIndex(Collection<AbstractTreeNode> children, AbstractTreeNode node) {
int idx = 0;
for (AbstractTreeNode child : children) {
if (child == node) {
return idx;
}
++ idx;
}
assert false;
return -1;
}*/
public static List<AbstractTreeNode> getLogicalPathTo(List<AbstractTreeNode> result, TreePath selectionPath) {
final Object component = selectionPath.getLastPathComponent();
if (component instanceof DefaultMutableTreeNode) {
final Object uo = ((DefaultMutableTreeNode) component).getUserObject();
if (uo instanceof FavoritesTreeNodeDescriptor) {
AbstractTreeNode treeNode = ((FavoritesTreeNodeDescriptor) uo).getElement();
while ((!(treeNode instanceof FavoritesListNode)) && treeNode != null) {
result.add(treeNode);
treeNode = treeNode.getParent();
}
Collections.reverse(result);
return result;
}
}
return Collections.emptyList();
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class FavoritesTreeUtil method extractParentList.
@Nullable
public static FavoritesListNode extractParentList(FavoritesTreeNodeDescriptor descriptor) {
final AbstractTreeNode node = descriptor.getElement();
AbstractTreeNode current = node;
while (current != null) {
if (current instanceof FavoritesListNode) {
return (FavoritesListNode) current;
}
current = current.getParent();
}
return null;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class FavoritesViewTreeBuilder method findSmartFirstLevelNodeByElement.
@Nullable
DefaultMutableTreeNode findSmartFirstLevelNodeByElement(final Object element) {
for (Object child : getRoot().getChildren()) {
AbstractTreeNode favorite = (AbstractTreeNode) child;
Object currentValue = favorite.getValue();
if (currentValue instanceof SmartPsiElementPointer) {
currentValue = ((SmartPsiElementPointer) favorite.getValue()).getElement();
}
/*else if (currentValue instanceof PsiJavaFile) {
final PsiClass[] classes = ((PsiJavaFile)currentValue).getClasses();
if (classes.length > 0) {
currentValue = classes[0];
}
}*/
if (Comparing.equal(element, currentValue)) {
final DefaultMutableTreeNode nodeWithObject = findFirstLevelNodeWithObject((DefaultMutableTreeNode) getTree().getModel().getRoot(), favorite);
if (nodeWithObject != null) {
return nodeWithObject;
}
}
}
return null;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class BaseProjectTreeBuilder method expandChild.
private void expandChild(@NotNull final List<AbstractTreeNode> kids, int i, @NotNull final Condition<AbstractTreeNode> nonStopCondition, final VirtualFile file, final Object element, @NotNull final AsyncResult<AbstractTreeNode> async, @NotNull final ProgressIndicator indicator, final Ref<Object> virtualSelectTarget) {
while (i < kids.size()) {
final AbstractTreeNode eachKid = kids.get(i);
final boolean[] nodeWasCollapsed = { true };
final DefaultMutableTreeNode nodeForElement = getNodeForElement(eachKid);
if (nodeForElement != null) {
nodeWasCollapsed[0] = getTree().isCollapsed(new TreePath(nodeForElement.getPath()));
}
if (nonStopCondition.value(eachKid)) {
final AsyncResult<AbstractTreeNode> result = expandPathTo(file, eachKid, element, nonStopCondition, indicator, virtualSelectTarget);
result.doWhenDone(new Consumer<AbstractTreeNode>() {
@Override
public void consume(AbstractTreeNode abstractTreeNode) {
indicator.checkCanceled();
async.setDone(abstractTreeNode);
}
});
if (!result.isProcessed()) {
final int next = i + 1;
result.doWhenRejected(() -> {
indicator.checkCanceled();
if (nodeWasCollapsed[0] && virtualSelectTarget == null) {
collapseChildren(eachKid, null);
}
expandChild(kids, next, nonStopCondition, file, element, async, indicator, virtualSelectTarget);
});
return;
} else {
if (result.isRejected()) {
indicator.checkCanceled();
if (nodeWasCollapsed[0] && virtualSelectTarget == null) {
collapseChildren(eachKid, null);
}
i++;
} else {
return;
}
}
} else {
//filter tells us to stop here (for instance, in case of module nodes)
break;
}
}
async.setRejected();
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class BaseProjectTreeBuilder method collectChildren.
@NotNull
private static List<AbstractTreeNode> collectChildren(@NotNull DefaultMutableTreeNode node) {
int childCount = node.getChildCount();
List<AbstractTreeNode> result = new ArrayList<>(childCount);
for (int i = 0; i < childCount; i++) {
TreeNode childAt = node.getChildAt(i);
DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) childAt;
if (defaultMutableTreeNode.getUserObject() instanceof AbstractTreeNode) {
AbstractTreeNode treeNode = (AbstractTreeNode) defaultMutableTreeNode.getUserObject();
result.add(treeNode);
} else if (defaultMutableTreeNode.getUserObject() instanceof FavoritesTreeNodeDescriptor) {
AbstractTreeNode treeNode = ((FavoritesTreeNodeDescriptor) defaultMutableTreeNode.getUserObject()).getElement();
result.add(treeNode);
}
}
return result;
}
Aggregations