1919import de .doubleslash .keeptime .model .Work ;
2020import javafx .fxml .FXML ;
2121import javafx .scene .Node ;
22+ import javafx .scene .control .Button ;
2223import javafx .scene .control .DateCell ;
2324import javafx .scene .control .DatePicker ;
2425import javafx .scene .control .Label ;
26+ import javafx .scene .control .TextArea ;
2527import javafx .scene .control .ScrollPane ;
2628import javafx .scene .layout .BorderPane ;
2729import javafx .scene .layout .GridPane ;
3133
3234public class ReportController {
3335
36+ public static final String NOTE_DELIMETER = "; " ;
37+
38+ public static final String EMPTY_NOTE = "- No notes -" ;
39+
3440 private static final String FX_BACKGROUND_COLOR_NOT_WORKED = "-fx-background-color: #BBBBBB;" ;
3541
3642 @ FXML
@@ -59,23 +65,23 @@ public class ReportController {
5965 private void initialize () {
6066 LOG .info ("Init reportController" );
6167
62- datePicker = new DatePicker (LocalDate .now ());
63- datePicker .valueProperty ().addListener ((observable , oldvalue , newvalue ) -> {
68+ this . datePicker = new DatePicker (LocalDate .now ());
69+ this . datePicker .valueProperty ().addListener ((observable , oldvalue , newvalue ) -> {
6470 LOG .info ("Datepicker selected value changed to {}" , newvalue );
6571 updateReport (newvalue );
6672 });
6773 }
6874
6975 private void updateReport (final LocalDate newvalue ) {
70- currentDayLabel .setText (DateFormatter .toDayDateString (newvalue ));
71- final List <Work > currentWorkItems = model .workRepository .findByCreationDate (newvalue );
76+ this . currentDayLabel .setText (DateFormatter .toDayDateString (newvalue ));
77+ final List <Work > currentWorkItems = this . model .workRepository .findByCreationDate (newvalue );
7278
7379 final SortedSet <Project > workedProjectsSet = currentWorkItems .stream ().map (m -> {
7480 return m .getProject ();
7581 }).collect (Collectors .toCollection (() -> new TreeSet <>(Comparator .comparing (Project ::getName ))));
7682
77- gridPane .getChildren ().clear ();
78- gridPane .getRowConstraints ().clear ();
83+ this . gridPane .getChildren ().clear ();
84+ this . gridPane .getRowConstraints ().clear ();
7985
8086 int rowIndex = 0 ;
8187 long currentWorkSeconds = 0 ;
@@ -84,7 +90,7 @@ private void updateReport(final LocalDate newvalue) {
8490 final Label projectName = new Label (project .getName ());
8591 final Font labelFont = Font .font ("System" , FontWeight .BOLD , 15 );
8692 projectName .setFont (labelFont );
87- gridPane .add (projectName , 0 , rowIndex );
93+ this . gridPane .add (projectName , 0 , rowIndex );
8894
8995 final List <Work > onlyCurrentProjectWork = currentWorkItems .stream ().filter (w -> w .getProject () == project )
9096 .collect (Collectors .toList ());
@@ -100,36 +106,48 @@ private void updateReport(final LocalDate newvalue) {
100106
101107 final Label workedTimeLabel = new Label (DateFormatter .secondsToHHMMSS (todaysWorkSeconds ));
102108 workedTimeLabel .setFont (labelFont );
103- gridPane .add (workedTimeLabel , 2 , rowIndex );
109+ this .gridPane .add (workedTimeLabel , 2 , rowIndex );
110+
111+ // text will be set later
112+ final TextArea textArea = new TextArea ();
113+ textArea .setMaxHeight (20 );
114+ textArea .setFont (Font .font ("System" , FontWeight .NORMAL , 15 ));
115+ textArea .setWrapText (true );
116+ this .gridPane .add (textArea , 1 , rowIndex );
117+
104118 rowIndex ++;
105119
120+ final ProjectReport pr = new ProjectReport (onlyCurrentProjectWork .size ());
106121 for (int j = 0 ; j < onlyCurrentProjectWork .size (); j ++) {
107122 final Work work = onlyCurrentProjectWork .get (j );
108123 final String workedHours = DateFormatter
109124 .secondsToHHMMSS (DateFormatter .getSecondsBewtween (work .getStartTime (), work .getEndTime ()));
110125
111- final Label commentLabel = new Label (work .getNotes ());
126+ final String currentWorkNote = work .getNotes ();
127+ pr .appendToWorkNotes (currentWorkNote );
128+ final Label commentLabel = new Label (currentWorkNote );
112129 commentLabel .setFont (Font .font ("System" , FontWeight .NORMAL , 15 ));
113130 commentLabel .setWrapText (true );
114- gridPane .add (commentLabel , 0 , rowIndex );
131+ this . gridPane .add (commentLabel , 0 , rowIndex );
115132
116133 final Label fromTillLabel = new Label (DateFormatter .toTimeString (work .getStartTime ()) + " - "
117134 + DateFormatter .toTimeString (work .getEndTime ()));
118135 fromTillLabel .setFont (Font .font ("System" , FontWeight .NORMAL , 15 ));
119136 fromTillLabel .setWrapText (true );
120- gridPane .add (fromTillLabel , 1 , rowIndex );
137+ this . gridPane .add (fromTillLabel , 1 , rowIndex );
121138
122139 final Label workedHoursLabel = new Label (workedHours );
123140 workedHoursLabel .setFont (Font .font ("System" , FontWeight .NORMAL , 15 ));
124- gridPane .add (workedHoursLabel , 2 , rowIndex );
141+ this . gridPane .add (workedHoursLabel , 2 , rowIndex );
125142
126143 rowIndex ++;
127144 }
145+ textArea .setText (pr .getNotes (true ));
128146 }
129- scrollPane .setVvalue (0 ); // scroll to the top
147+ this . scrollPane .setVvalue (0 ); // scroll to the top
130148
131- currentDayTimeLabel .setText (DateFormatter .secondsToHHMMSS (currentSeconds ));
132- currentDayWorkTimeLabel .setText (DateFormatter .secondsToHHMMSS (currentWorkSeconds ));
149+ this . currentDayTimeLabel .setText (DateFormatter .secondsToHHMMSS (currentSeconds ));
150+ this . currentDayWorkTimeLabel .setText (DateFormatter .secondsToHHMMSS (currentWorkSeconds ));
133151 }
134152
135153 public void setModelAndController (final Model model , final Controller controller ) {
@@ -138,7 +156,7 @@ public void setModelAndController(final Model model, final Controller controller
138156
139157 // HACK to show calendar from datepicker
140158 // https://stackoverflow.com/questions/34681975/javafx-extract-calendar-popup-from-datepicker-only-show-popup
141- final DatePickerSkin datePickerSkin = new DatePickerSkin (datePicker );
159+ final DatePickerSkin datePickerSkin = new DatePickerSkin (this . datePicker );
142160 final Callback <DatePicker , DateCell > dayCellFactory = new Callback <DatePicker , DateCell >() {
143161 @ Override
144162 public DateCell call (final DatePicker datePicker ) {
@@ -154,12 +172,12 @@ public void updateItem(final LocalDate item, final boolean empty) {
154172 };
155173 }
156174 };
157- datePicker .setDayCellFactory (dayCellFactory );
175+ this . datePicker .setDayCellFactory (dayCellFactory );
158176 final Node popupContent = datePickerSkin .getPopupContent ();
159- topBorderPane .setRight (popupContent );
177+ this . topBorderPane .setRight (popupContent );
160178 }
161179
162180 public void update () {
163- updateReport (datePicker .getValue ());
181+ updateReport (this . datePicker .getValue ());
164182 }
165183}
0 commit comments