@@ -108,20 +108,19 @@ public class ReportController {
108108
109109 private ColorTimeLine colorTimeLine ;
110110
111+ private LocalDate currentReportDate ;
112+
111113 @ FXML
112114 private void initialize () {
113115 LOG .info ("Init reportController" );
114-
115- this .datePicker = new DatePicker (LocalDate .now ());
116- this .datePicker .valueProperty ().addListener ((observable , oldvalue , newvalue ) -> {
117- LOG .info ("Datepicker selected value changed to {}" , newvalue );
118- updateReport (newvalue );
119- });
116+ currentReportDate = LocalDate .now ();
120117
121118 colorTimeLine = new ColorTimeLine (colorTimeLineCanvas );
122119 }
123120
124121 private void updateReport (final LocalDate dateToShow ) {
122+ this .currentReportDate = dateToShow ;
123+ this .loadCalenderWidget ();
125124 reportRoot .requestFocus ();
126125
127126 this .currentDayLabel .setText (DateFormatter .toDayDateString (dateToShow ));
@@ -211,6 +210,7 @@ private void updateReport(final LocalDate dateToShow) {
211210
212211 result .ifPresent (editedWork -> {
213212 controller .editWork (work , editedWork );
213+
214214 this .update ();
215215 });
216216 });
@@ -233,6 +233,34 @@ private void updateReport(final LocalDate dateToShow) {
233233
234234 }
235235
236+ private void loadCalenderWidget () {
237+ final DatePicker myDatePicker = new DatePicker (this .currentReportDate );
238+ myDatePicker .valueProperty ().addListener ((observable , oldvalue , newvalue ) -> {
239+ LOG .info ("Datepicker selected value changed to {}" , newvalue );
240+ updateReport (newvalue );
241+ });
242+
243+ // HACK to show calendar from datepicker
244+ // https://stackoverflow.com/questions/34681975/javafx-extract-calendar-popup-from-datepicker-only-show-popup
245+ final DatePickerSkin datePickerSkin = new DatePickerSkin (myDatePicker );
246+ final Callback <DatePicker , DateCell > dayCellFactory = callback -> new DateCell () {
247+ @ Override
248+ public void updateItem (final LocalDate item , final boolean empty ) {
249+ super .updateItem (item , empty );
250+ if (model .getWorkRepository ().findByCreationDate (item ).isEmpty ()) {
251+ setDisable (true );
252+ setStyle (FX_BACKGROUND_COLOR_NOT_WORKED );
253+ }
254+ }
255+
256+ };
257+
258+ myDatePicker .setDayCellFactory (dayCellFactory );
259+ final Node popupContent = datePickerSkin .getPopupContent ();
260+ this .topBorderPane .setRight (popupContent );
261+
262+ }
263+
236264 private Dialog <Work > setupEditWorkDialog (final String title , final String headerText , final Work work ) {
237265 final Dialog <Work > dialog = new Dialog <>();
238266
@@ -295,27 +323,11 @@ public void handle(final ActionEvent event) {
295323 public void setModel (final Model model ) {
296324 this .model = model ;
297325
298- // HACK to show calendar from datepicker
299- // https://stackoverflow.com/questions/34681975/javafx-extract-calendar-popup-from-datepicker-only-show-popup
300- final DatePickerSkin datePickerSkin = new DatePickerSkin (datePicker );
301- final Callback <DatePicker , DateCell > dayCellFactory = callback -> new DateCell () {
302- @ Override
303- public void updateItem (final LocalDate item , final boolean empty ) {
304- super .updateItem (item , empty );
305- if (model .getWorkRepository ().findByCreationDate (item ).isEmpty ()) {
306- setDisable (true );
307- setStyle (FX_BACKGROUND_COLOR_NOT_WORKED );
308- }
309- }
310- };
311-
312- this .datePicker .setDayCellFactory (dayCellFactory );
313- final Node popupContent = datePickerSkin .getPopupContent ();
314- this .topBorderPane .setRight (popupContent );
326+ this .loadCalenderWidget ();
315327 }
316328
317329 public void update () {
318- updateReport (this .datePicker . getValue () );
330+ updateReport (this .currentReportDate );
319331 }
320332
321333 public void setController (final Controller controller ) {
0 commit comments