2929import java .util .LinkedList ;
3030import java .util .List ;
3131import java .util .function .Function ;
32+ import java .util .function .Predicate ;
3233
3334import org .eclipse .core .runtime .Assert ;
3435import org .eclipse .core .runtime .IStatus ;
@@ -1850,12 +1851,40 @@ protected Widget internalGetWidgetToSelect(Object elementOrTreePath) {
18501851 */
18511852 private void internalConditionalExpandToLevel (Widget widget , int level ,
18521853 Function <Widget , Boolean > shouldChildrenExpand ) {
1854+ internalConditionalExpandToLevel (widget , level , getShouldWidgetExpand (), shouldChildrenExpand );
1855+ }
1856+
1857+ /**
1858+ * @return the predicate that determines if a widget should be expanded when
1859+ * expanding the tree.
1860+ * @since 3.36
1861+ */
1862+ protected Predicate <Widget > getShouldWidgetExpand () {
1863+ return w -> true ;
1864+ }
1865+
1866+ /**
1867+ * Same as
1868+ * {@link #internalConditionalExpandToLevel(Widget, int, Function, Function)}
1869+ * but with an extra parameter to determine if the widget itself should be
1870+ * expanded.
1871+ *
1872+ * @param shouldWidgetExpand evaluates if the widget itself needs to be
1873+ * expanded.
1874+ */
1875+ private void internalConditionalExpandToLevel (Widget widget , int level , Predicate <Widget > shouldWidgetExpand ,
1876+ Function <Widget , Boolean > shouldChildrenExpand ) {
18531877 if (level == ALL_LEVELS || level > 0 ) {
18541878 Object data = widget .getData ();
18551879 if (widget instanceof Item it && data != null && !isExpandable (it , null , data )) {
18561880 return ;
18571881 }
18581882 createChildren (widget , false );
1883+
1884+ if (!shouldWidgetExpand .test (widget )) {
1885+ return ;
1886+ }
1887+
18591888 // XXX for performance widget should be expanded after expanding children:
18601889 if (widget instanceof Item it ) {
18611890 setExpanded (it , true );
@@ -1866,7 +1895,7 @@ private void internalConditionalExpandToLevel(Widget widget, int level,
18661895 int newLevel = (level == ALL_LEVELS ? ALL_LEVELS
18671896 : level - 1 );
18681897 for (Item element : children ) {
1869- internalConditionalExpandToLevel (element , newLevel , shouldChildrenExpand );
1898+ internalConditionalExpandToLevel (element , newLevel , shouldWidgetExpand , shouldChildrenExpand );
18701899 }
18711900 }
18721901 }
0 commit comments