Skip to content

Commit

Permalink
Overload method AbstractTreeViewer::internalConditionalExpandToLevel
Browse files Browse the repository at this point in the history
Add function to determine if the widget itself must be expanded.
  • Loading branch information
fedejeanne committed Jan 14, 2025
1 parent 323f82d commit 532e4d8
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,21 @@ protected Widget internalGetWidgetToSelect(Object elementOrTreePath) {
*/
private void internalConditionalExpandToLevel(Widget widget, int level,
Function<Widget, Boolean> shouldChildrenExpand) {
internalConditionalExpandToLevel(widget, level, __ -> Boolean.TRUE, shouldChildrenExpand);
}

/**
* Same as
* {@link #internalConditionalExpandToLevel(Widget, int, Function, Function)}
* but with an extra parameter to determine if the widget itself should be
* expanded.
*
* @param shouldWidgetExpand evaluates if the widget itself needs to be
* expanded.
* @since 3.36
*/
protected void internalConditionalExpandToLevel(Widget widget, int level,
Function<Widget, Boolean> shouldWidgetExpand, Function<Widget, Boolean> shouldChildrenExpand) {
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 +1873,10 @@ 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 (!shouldWidgetExpand.apply(widget).booleanValue()) {
return;
}

setExpanded(it, true);
}
if (level == ALL_LEVELS || level > 1) {
Expand All @@ -1866,7 +1885,7 @@ private void internalConditionalExpandToLevel(Widget widget, int level,
int newLevel = (level == ALL_LEVELS ? ALL_LEVELS
: level - 1);
for (Item element : children) {
internalConditionalExpandToLevel(element, newLevel, shouldChildrenExpand);
internalConditionalExpandToLevel(element, newLevel, shouldWidgetExpand, shouldChildrenExpand);
}
}
}
Expand Down

0 comments on commit 532e4d8

Please sign in to comment.