Skip to content

Commit 78020c5

Browse files
committed
Implement monitoring history navigator
1 parent 3b0af1c commit 78020c5

File tree

3 files changed

+70
-17
lines changed

3 files changed

+70
-17
lines changed

src/main/java/root/javafx/Controller/MonitoringAPController.java

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Map;
1212
import java.util.stream.Collectors;
1313

14+
import com.jfoenix.controls.JFXButton;
1415
import com.jfoenix.controls.JFXComboBox;
1516

1617
import javafx.event.ActionEvent;
@@ -44,6 +45,8 @@
4445

4546
public 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
/*

src/main/java/root/javafx/CustomView/MonitoringTableViewContainer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,7 @@ public void setUsageUIType(Class<? extends MonitoringResult> type, UsageUIType u
100100

101101
public void clearTableData(Class<? extends MonitoringResult> type) {
102102
tableDataListMap.get(type).clear();
103+
tableViewMap.get(type).getItems().clear();
104+
tableViewMap.get(type).refresh();
103105
}
104106
}

src/main/resources/fxml/MonitoringAP.fxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<items>
2929
<HBox alignment="CENTER_LEFT" maxWidth="350.0" spacing="10.0">
3030
<children>
31-
<JFXButton fx:id="prevHistoryBtn" ellipsisString="" graphicTextGap="8.0" maxWidth="80.0" minWidth="80.0" onAction="#showPrevHistory" ripplerFill="BLACK" style="-fx-border-color: #ddd; -fx-font-size: 12px; -fx-border-radius: 30px; -fx-text-fill: black;" styleClass="basic-font" text="이전기록">
31+
<JFXButton fx:id="prevHistoryBtn" disable="true" ellipsisString="" graphicTextGap="8.0" maxWidth="80.0" minWidth="80.0" onAction="#showPrevHistory" ripplerFill="BLACK" style="-fx-border-color: #ddd; -fx-font-size: 12px; -fx-border-radius: 30px; -fx-text-fill: black;" styleClass="basic-font" text="이전기록">
3232
<cursor>
3333
<Cursor fx:constant="HAND" />
3434
</cursor>
@@ -41,7 +41,7 @@
4141
<FontAwesomeIconView fill="#003b8e" glyphName="CLOCK_ALT" size="15" strokeWidth="0.0" />
4242
</graphic>
4343
</Label>
44-
<JFXButton fx:id="nextHistoryBtn" contentDisplay="RIGHT" ellipsisString="" graphicTextGap="8.0" maxWidth="80.0" minWidth="80.0" onAction="#showNextHistory" ripplerFill="BLACK" style="-fx-border-color: #ddd; -fx-font-size: 12px; -fx-border-radius: 30px; -fx-text-fill: black;" styleClass="basic-font" text="다음기록">
44+
<JFXButton fx:id="nextHistoryBtn" contentDisplay="RIGHT" disable="true" ellipsisString="" graphicTextGap="8.0" maxWidth="80.0" minWidth="80.0" onAction="#showNextHistory" ripplerFill="BLACK" style="-fx-border-color: #ddd; -fx-font-size: 12px; -fx-border-radius: 30px; -fx-text-fill: black;" styleClass="basic-font" text="다음기록">
4545
<cursor>
4646
<Cursor fx:constant="HAND" />
4747
</cursor>

0 commit comments

Comments
 (0)