Skip to content

Commit 8302bb6

Browse files
committed
Refactoring: Extract the duplicate portion of the monitoring query logic as a method
1 parent 35c8649 commit 8302bb6

File tree

1 file changed

+15
-43
lines changed

1 file changed

+15
-43
lines changed

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

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public MonitoringAPController(Class<T> clazz) {
142142
if (oldValue == null) {
143143
syncTableData(newValue, 0);
144144
} else {
145-
runMonitoring();
145+
showMonitoringHistory(0);
146146
}
147147
});
148148

@@ -153,7 +153,7 @@ public MonitoringAPController(Class<T> clazz) {
153153
unitComboBox.getSelectionModel().select(propService.getDefaultFileSizeUnit());
154154
unitComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
155155
if (oldValue != null) {
156-
runMonitoring();
156+
showMonitoringHistory(0);
157157
}
158158
});
159159

@@ -172,7 +172,7 @@ public RoundingDigits fromString(String digits) {
172172
});
173173
roundComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
174174
if (oldValue != null) {
175-
runMonitoring();
175+
showMonitoringHistory(0);
176176
}
177177
});
178178

@@ -327,16 +327,24 @@ public void setAnchor(Node node, double left, double top, double right, double b
327327
* @param e
328328
*/
329329
public void run(ActionEvent e) {
330-
runMonitoring();
330+
showMonitoringHistory(0);
331331
}
332332

333-
private void runMonitoring() {
333+
public void showPrevHistory(ActionEvent e) {
334+
showMonitoringHistory(-1);
335+
}
336+
337+
public void showNextHistory(ActionEvent e) {
338+
showMonitoringHistory(1);
339+
}
340+
341+
private void showMonitoringHistory(int type) {
334342
String selected = aliasComboBox.getSelectionModel().getSelectedItem();
335343

336344
// Clear data
337345
clearTableData(selected);
338-
339-
Map<String, List<T>> allDataList = inquiryMonitoringHistory(0);
346+
347+
Map<String, List<T>> allDataList = inquiryMonitoringHistory(type);
340348
if (allDataList == null || allDataList.size() == 0) {
341349
AlertUtils.showAlert(AlertType.INFORMATION, "조회결과 없음", "해당일자의 모니터링 기록이 없습니다.");
342350
historyDateTimeLabel.setText(MONITORING_HISTORY_DEFAULT_TEXT);
@@ -438,42 +446,6 @@ private void syncPrequency(String timeDiv) {
438446
}
439447
}
440448

441-
public void showPrevHistory(ActionEvent e) {
442-
String selected = aliasComboBox.getSelectionModel().getSelectedItem();
443-
444-
// Clear data
445-
clearTableData(selected);
446-
447-
Map<String, List<T>> allDataList = inquiryMonitoringHistory(-1);
448-
if (allDataList == null || allDataList.size() == 0) {
449-
AlertUtils.showAlert(AlertType.INFORMATION, "조회결과 없음", "해당일자의 모니터링 기록이 없습니다.");
450-
historyDateTimeLabel.setText(MONITORING_HISTORY_DEFAULT_TEXT);
451-
return;
452-
}
453-
454-
// Add and Sync data
455-
addTableDataSet(selected, allDataList);
456-
syncTableData(selected, 0);
457-
}
458-
459-
public void showNextHistory(ActionEvent e) {
460-
String selected = aliasComboBox.getSelectionModel().getSelectedItem();
461-
462-
// Clear data
463-
clearTableData(selected);
464-
465-
Map<String, List<T>> allDataList = inquiryMonitoringHistory(1);
466-
if (allDataList == null || allDataList.size() == 0) {
467-
AlertUtils.showAlert(AlertType.INFORMATION, "조회결과 없음", "해당일자의 모니터링 기록이 없습니다.");
468-
historyDateTimeLabel.setText(MONITORING_HISTORY_DEFAULT_TEXT);
469-
return;
470-
}
471-
472-
// Add and Sync data
473-
addTableDataSet(selected, allDataList);
474-
syncTableData(selected, 0);
475-
}
476-
477449
/*
478450
* =============================================================================
479451
*/

0 commit comments

Comments
 (0)