@@ -1850,12 +1850,32 @@ protected Widget internalGetWidgetToSelect(Object elementOrTreePath) {
18501850 */
18511851 private void internalConditionalExpandToLevel (Widget widget , int level ,
18521852 Function <Widget , Boolean > shouldChildrenExpand ) {
1853+ internalConditionalExpandToLevel (widget , level , __ -> Boolean .TRUE , shouldChildrenExpand );
1854+ }
1855+
1856+ /**
1857+ * Same as
1858+ * {@link #internalConditionalExpandToLevel(Widget, int, Function, Function)}
1859+ * but with an extra parameter to determine if the widget itself should be
1860+ * expanded.
1861+ *
1862+ * @param shouldWidgetExpand evaluates if the widget itself needs to be
1863+ * expanded.
1864+ * @since 3.36
1865+ */
1866+ protected void internalConditionalExpandToLevel (Widget widget , int level ,
1867+ Function <Widget , Boolean > shouldWidgetExpand , Function <Widget , Boolean > shouldChildrenExpand ) {
18531868 if (level == ALL_LEVELS || level > 0 ) {
18541869 Object data = widget .getData ();
18551870 if (widget instanceof Item it && data != null && !isExpandable (it , null , data )) {
18561871 return ;
18571872 }
18581873 createChildren (widget , false );
1874+
1875+ if (!shouldWidgetExpand .apply (widget ).booleanValue ()) {
1876+ return ;
1877+ }
1878+
18591879 // XXX for performance widget should be expanded after expanding children:
18601880 if (widget instanceof Item it ) {
18611881 setExpanded (it , true );
@@ -1866,7 +1886,7 @@ private void internalConditionalExpandToLevel(Widget widget, int level,
18661886 int newLevel = (level == ALL_LEVELS ? ALL_LEVELS
18671887 : level - 1 );
18681888 for (Item element : children ) {
1869- internalConditionalExpandToLevel (element , newLevel , shouldChildrenExpand );
1889+ internalConditionalExpandToLevel (element , newLevel , shouldWidgetExpand , shouldChildrenExpand );
18701890 }
18711891 }
18721892 }
0 commit comments