Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractTreeViewer do not auto-expand same nodes multiple times #2684

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

import org.eclipse.core.runtime.Assert;
Expand Down Expand Up @@ -1850,6 +1852,11 @@ protected Widget internalGetWidgetToSelect(Object elementOrTreePath) {
*/
private void internalConditionalExpandToLevel(Widget widget, int level,
Function<Widget, Boolean> shouldChildrenExpand) {
internalConditionalExpandToLevel(widget, level, shouldChildrenExpand, new HashSet<>());
}

private void internalConditionalExpandToLevel(Widget widget, int level,
Function<Widget, Boolean> shouldChildrenExpand, Set<Object> expanded) {
if (level == ALL_LEVELS || level > 0) {
Object data = widget.getData();
if (widget instanceof Item it && data != null && !isExpandable(it, null, data)) {
Expand All @@ -1858,6 +1865,9 @@ private void internalConditionalExpandToLevel(Widget widget, int level,
createChildren(widget, false);
// XXX for performance widget should be expanded after expanding children:
if (widget instanceof Item it) {
if (data != null && !expanded.add(data)) {
return;
}
setExpanded(it, true);
}
if (level == ALL_LEVELS || level > 1) {
Expand All @@ -1867,7 +1877,7 @@ private void internalConditionalExpandToLevel(Widget widget, int level,
: level - 1);
for (Item element : children) {
if (shouldChildrenExpand.apply(widget).booleanValue()) {
internalConditionalExpandToLevel(element, newLevel, shouldChildrenExpand);
internalConditionalExpandToLevel(element, newLevel, shouldChildrenExpand, expanded);
}
}
}
Expand Down
Loading