2424import javafx .scene .text .Font ;
2525import javafx .scene .text .Text ;
2626import javafx .scene .text .TextFlow ;
27+ import net .engio .mbassy .bus .MBassador ;
28+ import net .engio .mbassy .listener .Handler ;
29+ import net .engio .mbassy .listener .Listener ;
30+ import net .engio .mbassy .listener .References ;
2731import org .controlsfx .control .NotificationPane ;
2832import org .stt .config .ReportConfig ;
2933import org .stt .gui .jfx .binding .MappedListBinding ;
3034import org .stt .gui .jfx .binding .ReportBinding ;
3135import org .stt .gui .jfx .binding .STTBindings ;
36+ import org .stt .model .ItemModified ;
3237import org .stt .query .TimeTrackingItemQueries ;
3338import org .stt .reporting .SummingReportGenerator .Report ;
3439import org .stt .text .ItemGrouper ;
@@ -89,6 +94,7 @@ public class ReportController {
8994
9095 private NotificationPane panel ;
9196 private Font fontaweSome ;
97+ private final MBassador <Object > eventBus ;
9298 private PauseTransition notificationPause = new PauseTransition (javafx .util .Duration .seconds (2 ));
9399 private TemporalField dayOfWeekField = WeekFields .of (Locale .getDefault ()).dayOfWeek ();
94100 private Set <LocalDate > trackedDays ;
@@ -99,13 +105,15 @@ public class ReportController {
99105 DurationRounder rounder ,
100106 ItemGrouper itemGrouper ,
101107 ReportConfig config ,
102- @ Named ("glyph" ) Font fontaweSome ) {
108+ @ Named ("glyph" ) Font fontaweSome ,
109+ MBassador <Object > eventBus ) {
103110 this .localization = requireNonNull (localization );
104111 this .config = requireNonNull (config );
105112 this .timeTrackingItemQueries = requireNonNull (searcher );
106113 this .rounder = requireNonNull (rounder );
107114 this .itemGrouper = requireNonNull (itemGrouper );
108115 this .fontaweSome = requireNonNull (fontaweSome );
116+ this .eventBus = requireNonNull (eventBus );
109117
110118 List <String > colorStrings = config .getGroupColors ();
111119 groupColors = new Color [colorStrings .size ()];
@@ -142,7 +150,8 @@ public void initialize() {
142150 tableForReport .getSelectionModel ().selectedIndexProperty ().addListener (i ->
143151 Platform .runLater (tableForReport .getSelectionModel ()::clearSelection ));
144152
145- final ObservableValue <Report > reportModel = createReportModel ();
153+ final ObjectBinding <Report > reportModel = createReportModel ();
154+ eventBus .subscribe (new OnItemChangeListener (reportModel ));
146155 final StringBinding startBinding = createBindingForStartOfReport (reportModel );
147156 final StringBinding endBinding = createBindingForEndOfReport (reportModel );
148157 final ObjectBinding <Duration > uncoveredTimeBinding = createBindingForUncoveredTimeOfReport (reportModel );
@@ -237,7 +246,7 @@ public void updateItem(LocalDate item, boolean empty) {
237246 toolbar .getItems ().add (oneWeekForward );
238247 }
239248
240- private ObservableValue <Report > createReportModel () {
249+ private ObjectBinding <Report > createReportModel () {
241250 ObservableValue <LocalDate > nextDay = Bindings .createObjectBinding (
242251 () -> datePicker .getValue () != null ? datePicker
243252 .getValue ().plusDays (1 ) : null , datePicker .valueProperty ());
@@ -467,4 +476,18 @@ public Duration getRoundedDuration() {
467476 return roundedDuration ;
468477 }
469478 }
479+
480+ @ Listener (references = References .Strong )
481+ private static class OnItemChangeListener {
482+ private final ObjectBinding <?> binding ;
483+
484+ private OnItemChangeListener (ObjectBinding <?> binding ) {
485+ this .binding = binding ;
486+ }
487+
488+ @ Handler
489+ public void onItemChanged (ItemModified changeEvent ) {
490+ binding .invalidate ();
491+ }
492+ }
470493}
0 commit comments