1010
1111import javafx .beans .value .ObservableValue ;
1212import javafx .css .PseudoClass ;
13+ import javafx .event .Event ;
14+ import javafx .event .EventType ;
1315import javafx .geometry .Bounds ;
1416import javafx .geometry .Point2D ;
1517import javafx .scene .control .ContextMenu ;
2729
2830public class ViewModelTreeTableRowFactory <S > implements Callback <TreeTableView <S >, TreeTableRow <S >> {
2931 private BiConsumer <S , ? super MouseEvent > onMouseClickedEvent ;
30-
31- // True if event capture should be at capture phase via an event filter, otherwise use default Node method to setup
32- // event handler (bubbling phase)
33- private boolean onMousePressedEventCapturePhase ;
34-
3532 private BiConsumer <S , ? super MouseEvent > onMousePressedEvent ;
3633 private Consumer <TreeTableRow <S >> toCustomInitializer ;
3734 private Function <S , ContextMenu > contextMenuFactory ;
@@ -41,6 +38,7 @@ public class ViewModelTreeTableRowFactory<S> implements Callback<TreeTableView<S
4138 private TriConsumer <TreeTableRow <S >, S , ? super DragEvent > toOnDragExited ;
4239 private TriConsumer <TreeTableRow <S >, S , ? super DragEvent > toOnDragOver ;
4340 private TriConsumer <TreeTableRow <S >, S , ? super MouseDragEvent > toOnMouseDragEntered ;
41+ private final Map <EventType <?>, BiConsumer <S , ? super Event >> eventFilters = new HashMap <>();
4442 private final Map <PseudoClass , Callback <TreeTableRow <S >, ObservableValue <Boolean >>> pseudoClasses = new HashMap <>();
4543
4644 public ViewModelTreeTableRowFactory <S > withOnMouseClickedEvent (BiConsumer <S , ? super MouseEvent > event ) {
@@ -49,12 +47,7 @@ public ViewModelTreeTableRowFactory<S> withOnMouseClickedEvent(BiConsumer<S, ? s
4947 }
5048
5149 public ViewModelTreeTableRowFactory <S > withOnMousePressedEvent (BiConsumer <S , ? super MouseEvent > event ) {
52- return withOnMousePressedEvent (event , false );
53- }
54-
55- public ViewModelTreeTableRowFactory <S > withOnMousePressedEvent (BiConsumer <S , ? super MouseEvent > event , boolean capturePhase ) {
5650 this .onMousePressedEvent = event ;
57- this .onMousePressedEventCapturePhase = capturePhase ;
5851 return this ;
5952 }
6053
@@ -124,6 +117,11 @@ public ViewModelTreeTableRowFactory<S> withPseudoClass(PseudoClass pseudoClass,
124117 return this ;
125118 }
126119
120+ public ViewModelTreeTableRowFactory <S > withEventFilter (EventType <?> event , BiConsumer <S , ? super Event > toCondition ) {
121+ this .eventFilters .putIfAbsent (event , toCondition );
122+ return this ;
123+ }
124+
127125 public void install (TreeTableView <S > table ) {
128126 table .setRowFactory (this );
129127 }
@@ -175,11 +173,7 @@ protected void updateItem(S row, boolean empty) {
175173 }
176174
177175 if (onMousePressedEvent != null ) {
178- if (onMousePressedEventCapturePhase ) {
179- addEventFilter (MouseEvent .MOUSE_PRESSED , event -> onMousePressedEvent .accept (getItem (), event ));
180- } else {
181- setOnMousePressed (event -> onMousePressedEvent .accept (getItem (), event ));
182- }
176+ setOnMousePressed (event -> onMousePressedEvent .accept (getItem (), event ));
183177 }
184178
185179 if (toCustomInitializer != null ) {
@@ -206,6 +200,10 @@ protected void updateItem(S row, boolean empty) {
206200 setOnMouseDragEntered (event -> toOnMouseDragEntered .accept (this , getItem (), event ));
207201 }
208202
203+ for (Map .Entry <EventType <?>, BiConsumer <S , ? super Event >> eventFilter : eventFilters .entrySet ()) {
204+ addEventFilter (eventFilter .getKey (), event -> eventFilter .getValue ().accept (getItem (), event ));
205+ }
206+
209207 for (Map .Entry <PseudoClass , Callback <TreeTableRow <S >, ObservableValue <Boolean >>> pseudoClassWithCondition : pseudoClasses .entrySet ()) {
210208 ObservableValue <Boolean > condition = pseudoClassWithCondition .getValue ().call (this );
211209 subscriptions .add (BindingsHelper .includePseudoClassWhen (
0 commit comments