File tree Expand file tree Collapse file tree
modules/core/src/main/java/io/github/palexdev/mfxcore Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -173,6 +173,10 @@ public CheckMenuBuilder onSelectionChanged(Consumer<Boolean> onSelectionChanged)
173173 return this ;
174174 }
175175
176+ public CheckMenuBuilder onSelected (Runnable onSelected ) {
177+ return onSelectionChanged (s -> {if (s ) onSelected .run ();});
178+ }
179+
176180 public CheckMenuBuilder closeOnAction (boolean closeOnAction ) {
177181 this .closeOnAction = closeOnAction ;
178182 return this ;
Original file line number Diff line number Diff line change @@ -70,6 +70,13 @@ default void setSelectionGroup(SelectionGroup group) {
7070
7171 /// Allows specifying a callback to invoke when the selection state of this `Selectable` changes.
7272 ///
73- /// **This is an optional API. By default, does nothing.**
74- default void onSelectionChanged (Consumer <Boolean > action ) {}
73+ /// **This is an optional API. By default, throws an `UnsupportedOperationException`.**
74+ default void onSelectionChanged (Consumer <Boolean > action ) {
75+ throw new UnsupportedOperationException ("API not implemented by " + getClass ());
76+ }
77+
78+ /// Delegate to [#onSelectionChanged(Consumer)] that runs the given action only when selection state is `true`.
79+ default void onSelected (Runnable action ) {
80+ onSelectionChanged (s -> {if (s ) action .run ();});
81+ }
7582}
You can’t perform that action at this time.
0 commit comments