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;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class BaseProjectTreeBuilder method _select.
private void _select(final Object element, final VirtualFile file, final boolean requestFocus, final Condition<AbstractTreeNode> nonStopCondition, final ActionCallback result, @NotNull final ProgressIndicator indicator, @Nullable final Ref<Object> virtualSelectTarget, final FocusRequestor focusRequestor, final boolean isSecondAttempt) {
final AbstractTreeNode alreadySelected = alreadySelectedNode(element);
final Runnable onDone = () -> {
if (requestFocus && virtualSelectTarget == null && getUi().isReady()) {
focusRequestor.requestFocus(getTree(), true);
}
result.setDone();
};
final Condition<AbstractTreeNode> condition = abstractTreeNode -> !result.isProcessed() && nonStopCondition.value(abstractTreeNode);
if (alreadySelected == null) {
expandPathTo(file, (AbstractTreeNode) getTreeStructure().getRootElement(), element, condition, indicator, virtualSelectTarget).doWhenDone(new Consumer<AbstractTreeNode>() {
@Override
public void consume(AbstractTreeNode node) {
if (virtualSelectTarget == null) {
select(node, onDone);
} else {
onDone.run();
}
}
}).doWhenRejected(() -> {
if (isSecondAttempt) {
result.setRejected();
} else {
_select(file, file, requestFocus, nonStopCondition, result, indicator, virtualSelectTarget, focusRequestor, true);
}
});
} else if (virtualSelectTarget == null) {
scrollTo(alreadySelected, onDone);
} else {
onDone.run();
}
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class BaseProjectTreeBuilder method expandPathTo.
@NotNull
private AsyncResult<AbstractTreeNode> expandPathTo(final VirtualFile file, @NotNull final AbstractTreeNode root, final Object element, @NotNull final Condition<AbstractTreeNode> nonStopCondition, @NotNull final ProgressIndicator indicator, @Nullable final Ref<Object> target) {
final AsyncResult<AbstractTreeNode> async = new AsyncResult<>();
if (root.canRepresent(element)) {
if (target == null) {
expand(root, () -> async.setDone(root));
} else {
target.set(root);
async.setDone(root);
}
return async;
}
if (!canExpandPathTo(root, element)) {
async.setRejected();
return async;
}
if (root instanceof ProjectViewNode && file != null && !((ProjectViewNode) root).contains(file)) {
async.setRejected();
return async;
}
if (target == null) {
expand(root, () -> {
indicator.checkCanceled();
final DefaultMutableTreeNode rootNode = getNodeForElement(root);
if (rootNode != null) {
final List<AbstractTreeNode> kids = collectChildren(rootNode);
expandChild(kids, 0, nonStopCondition, file, element, async, indicator, target);
} else {
async.setRejected();
}
});
} else {
if (indicator.isCanceled()) {
async.setRejected();
} else {
final DefaultMutableTreeNode rootNode = getNodeForElement(root);
final ArrayList<AbstractTreeNode> kids = new ArrayList<>();
if (rootNode != null && getTree().isExpanded(new TreePath(rootNode.getPath()))) {
kids.addAll(collectChildren(rootNode));
} else {
List<Object> list = Arrays.asList(getTreeStructure().getChildElements(root));
for (Object each : list) {
kids.add((AbstractTreeNode) each);
}
}
yield(() -> {
if (isDisposed())
return;
expandChild(kids, 0, nonStopCondition, file, element, async, indicator, target);
});
}
}
return async;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class StructureViewModuleNode method getChildren.
@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
final Module module = getValue();
if (module == null) {
// just deleted a module from project view
return Collections.emptyList();
}
final List<AbstractTreeNode> children = new ArrayList<>(2);
children.add(new LibraryGroupNode(getProject(), new LibraryGroupElement(module), getSettings()) {
@Override
public boolean isAlwaysExpand() {
return true;
}
});
children.add(new ModuleListNode(getProject(), module, getSettings()));
return children;
}
Aggregations