1111import java .util .Map ;
1212import java .util .stream .Collectors ;
1313
14+ import com .jfoenix .controls .JFXButton ;
1415import com .jfoenix .controls .JFXComboBox ;
1516
1617import javafx .event .ActionEvent ;
4445
4546public class MonitoringAPController <T extends MonitoringResult > extends BorderPane {
4647
48+ private static final String MONITORING_HISTORY_DEFAULT_TEXT = "기록을 조회해주세요." ;
49+
4750 private ReportUsecase reportUsecase ;
4851
4952 private PropertyService propService = new FilePropertyService (PropertyRepositoryImpl .getInstance ());
@@ -68,6 +71,12 @@ public class MonitoringAPController<T extends MonitoringResult> extends BorderPa
6871
6972 @ FXML
7073 Label historyDateTimeLabel ;
74+
75+ @ FXML
76+ JFXButton prevHistoryBtn ;
77+
78+ @ FXML
79+ JFXButton nextHistoryBtn ;
7180
7281 @ FXML
7382 Pagination pagination ;
@@ -155,6 +164,18 @@ public RoundingDigits fromString(String digits) {
155164 String amOrPm = Integer .valueOf (DateUtils .getToday ("HH" )) < 12 ? "AM" : "PM" ;
156165 prequencyTimeDivBtn .setText (amOrPm );
157166
167+ // Set historyDateTimeLabel change listener
168+ historyDateTimeLabel .setText (MONITORING_HISTORY_DEFAULT_TEXT );
169+ historyDateTimeLabel .textProperty ().addListener ((observable , oldValue , newValue ) -> {
170+ if (oldValue == null || newValue .equals (MONITORING_HISTORY_DEFAULT_TEXT )) {
171+ prevHistoryBtn .setDisable (true );
172+ nextHistoryBtn .setDisable (true );
173+ } else {
174+ prevHistoryBtn .setDisable (false );
175+ nextHistoryBtn .setDisable (false );
176+ }
177+ });
178+
158179 initMonitoringTableView ();
159180 } catch (IOException e ) {
160181 e .printStackTrace ();
@@ -178,6 +199,7 @@ private void initMonitoringTableView() {
178199 * @param id
179200 */
180201 public void clearTableData (String id ) {
202+ tableViewContainer .clearTableData (clazz );
181203 if (tableDataMap .get (id ) != null ) {
182204 tableDataMap .get (id ).clear ();
183205 }
@@ -236,22 +258,19 @@ public void syncTableData(String id, int index) {
236258
237259 // Add tableView items
238260 Map <String , List <T >> data = tableDataMap .get (id );
239- List <String > times = new ArrayList <>(data .keySet ());
240- Collections .sort (times );
241-
242- List <T > tableData = data .get (times .get (index ));
261+ List <T > tableData = data .get (new ArrayList <>(data .keySet ()).get (index ));
243262 tableViewContainer .setTableData (clazz , tableData );
244263
245264 // Sync monitoring prequency UI
246265 syncPrequency (prequencyTimeDivBtn .getText ());
247-
266+
248267 // Sync history monitoring datetime
249- if (tableData != null && !tableData .isEmpty ()) {
268+ if (tableData != null && !tableData .isEmpty ()) {
250269 String monitoringDateTime = tableData .get (0 ).getMonitoringDateTime ();
251270 historyDateTimeLabel .setText (DateUtils .convertDateFormat ("yyyyMMddHHmmss" , "yyyy-MM-dd HH:mm:ss" ,
252271 monitoringDateTime , Locale .KOREA ));
253272 } else {
254- historyDateTimeLabel .setText ("기록을 조회해주세요." );
273+ historyDateTimeLabel .setText (MONITORING_HISTORY_DEFAULT_TEXT );
255274 }
256275 }
257276
@@ -288,16 +307,17 @@ public void setAnchor(Node node, double left, double top, double right, double b
288307 public void run (ActionEvent e ) {
289308 runMonitoring ();
290309 }
291-
310+
292311 private void runMonitoring () {
293312 String selected = aliasComboBox .getSelectionModel ().getSelectedItem ();
294313
295314 // Clear data
296315 clearTableData (selected );
297-
298- Map <String , List <T >> allDataList = inquiryMonitoringHistory ();
316+
317+ Map <String , List <T >> allDataList = inquiryMonitoringHistory (0 );
299318 if (allDataList == null || allDataList .size () == 0 ) {
300319 AlertUtils .showAlert (AlertType .INFORMATION , "조회결과 없음" , "해당일자의 모니터링 기록이 없습니다." );
320+ historyDateTimeLabel .setText (MONITORING_HISTORY_DEFAULT_TEXT );
301321 return ;
302322 }
303323
@@ -306,7 +326,7 @@ private void runMonitoring() {
306326 syncTableData (selected , 0 );
307327 }
308328
309- private Map <String , List <T >> inquiryMonitoringHistory () {
329+ private Map <String , List <T >> inquiryMonitoringHistory (int type ) {
310330 // Get selected inquiry condition
311331 String inquiryDate = this .inquiryDatePicker .getValue ().format (DateTimeFormatter .ofPattern ("yyyyMMdd" ));
312332 String selected = aliasComboBox .getSelectionModel ().getSelectedItem ();
@@ -316,8 +336,24 @@ private Map<String, List<T>> inquiryMonitoringHistory() {
316336 // TODO Show Progress UI
317337
318338 // Acquire data on inquiry date
319- return reportUsecase .getMonitoringReportDataByTime (this .clazz , selected , selectedUnit ,
320- selectedRoundingDigit .getDigits (), inquiryDate );
339+ if (type == 0 ) {
340+ return reportUsecase .getMonitoringReportDataByTime (this .clazz , selected , selectedUnit ,
341+ selectedRoundingDigit .getDigits (), inquiryDate );
342+ }
343+
344+ String current = historyDateTimeLabel .getText ();
345+ if (current .equals (MONITORING_HISTORY_DEFAULT_TEXT )) {
346+ return null ;
347+ }
348+ String currentDateTime = DateUtils .convertDateFormat ("yyyy-MM-dd HH:mm:ss" , "yyyyMMddHHmmss" , current ,
349+ Locale .KOREA );
350+ if (type == -1 ) {
351+ return reportUsecase .getPrevMonitoringReportDataByTime (this .clazz , selected , selectedUnit ,
352+ selectedRoundingDigit .getDigits (), currentDateTime );
353+ } else {
354+ return reportUsecase .getNextMonitoringReportDataByTime (this .clazz , selected , selectedUnit ,
355+ selectedRoundingDigit .getDigits (), currentDateTime );
356+ }
321357 }
322358
323359 private Map <Integer , List <String >> inquiryMonitoringHistoryTimesByTime () {
@@ -379,16 +415,17 @@ private void syncPrequency(String timeDiv) {
379415 prequencyHBox .getChildren ().add (new PrequencyButton (countByTime .get (i )));
380416 }
381417 }
382-
418+
383419 public void showPrevHistory (ActionEvent e ) {
384420 String selected = aliasComboBox .getSelectionModel ().getSelectedItem ();
385421
386422 // Clear data
387423 clearTableData (selected );
388424
389- Map <String , List <T >> allDataList = inquiryMonitoringHistory ();
425+ Map <String , List <T >> allDataList = inquiryMonitoringHistory (- 1 );
390426 if (allDataList == null || allDataList .size () == 0 ) {
391427 AlertUtils .showAlert (AlertType .INFORMATION , "조회결과 없음" , "해당일자의 모니터링 기록이 없습니다." );
428+ historyDateTimeLabel .setText (MONITORING_HISTORY_DEFAULT_TEXT );
392429 return ;
393430 }
394431
@@ -398,7 +435,21 @@ public void showPrevHistory(ActionEvent e) {
398435 }
399436
400437 public void showNextHistory (ActionEvent e ) {
438+ String selected = aliasComboBox .getSelectionModel ().getSelectedItem ();
439+
440+ // Clear data
441+ clearTableData (selected );
401442
443+ Map <String , List <T >> allDataList = inquiryMonitoringHistory (1 );
444+ if (allDataList == null || allDataList .size () == 0 ) {
445+ AlertUtils .showAlert (AlertType .INFORMATION , "조회결과 없음" , "해당일자의 모니터링 기록이 없습니다." );
446+ historyDateTimeLabel .setText (MONITORING_HISTORY_DEFAULT_TEXT );
447+ return ;
448+ }
449+
450+ // Add and Sync data
451+ addTableDataSet (selected , allDataList );
452+ syncTableData (selected , 0 );
402453 }
403454
404455 /*
0 commit comments