Skip to content

Commit 2e14d88

Browse files
authored
Merge pull request #189 from Dokyeongyun/ft-220313-tableViewReuse
Ft 220313 table view reuse
2 parents 1e35e50 + c919321 commit 2e14d88

File tree

7 files changed

+304
-300
lines changed

7 files changed

+304
-300
lines changed

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

Lines changed: 86 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.net.URL;
44
import java.time.LocalDate;
55
import java.util.HashMap;
6-
import java.util.LinkedHashMap;
76
import java.util.List;
87
import java.util.Map;
98
import java.util.ResourceBundle;
@@ -48,56 +47,65 @@
4847
import root.core.usecase.implement.ServerCheckUsecaseImpl;
4948
import root.javafx.CustomView.AlertLogListViewCell;
5049
import root.javafx.CustomView.DisableAfterTodayDateCell;
51-
import root.javafx.Model.TypeAndFieldName;
5250
import root.utils.AlertUtils;
5351

5452
public class HistoryMenuController implements Initializable {
5553

56-
5754
/* Dependency Injection */
5855
PropertyRepository propRepo = PropertyRepositoryImpl.getInstance();
5956
ReportRepository reportRepository = ReportFileRepo.getInstance();
6057
PropertyService propService = new FilePropertyService(propRepo);
6158

6259
/* View Binding */
63-
@FXML JFXComboBox<String> runConnInfoFileComboBox;
64-
@FXML JFXComboBox<String> runMonitoringPresetComboBox;
65-
@FXML JFXComboBox<String> alertLogServerComboBox;
66-
67-
@FXML DatePicker alertLogStartDayDP;
68-
@FXML DatePicker alertLogEndDayDP;
69-
70-
@FXML AnchorPane archiveUsageTabAP;
71-
@FXML AnchorPane tableSpaceUsageTabAP;
72-
@FXML AnchorPane asmDiskUsageTabAP;
73-
@FXML AnchorPane osDiskUsageTabAP;
74-
@FXML AnchorPane alertLogUsageTabAP;
75-
76-
@FXML JFXListView<Log> alertLogLV;
77-
60+
@FXML
61+
JFXComboBox<String> runConnInfoFileComboBox;
62+
@FXML
63+
JFXComboBox<String> runMonitoringPresetComboBox;
64+
@FXML
65+
JFXComboBox<String> alertLogServerComboBox;
66+
67+
@FXML
68+
DatePicker alertLogStartDayDP;
69+
@FXML
70+
DatePicker alertLogEndDayDP;
71+
72+
@FXML
73+
AnchorPane archiveUsageTabAP;
74+
@FXML
75+
AnchorPane tableSpaceUsageTabAP;
76+
@FXML
77+
AnchorPane asmDiskUsageTabAP;
78+
@FXML
79+
AnchorPane osDiskUsageTabAP;
80+
@FXML
81+
AnchorPane alertLogUsageTabAP;
82+
83+
@FXML
84+
JFXListView<Log> alertLogLV;
85+
7886
/* Custom View */
7987
MonitoringAPController<ArchiveUsage> archiveUsageMAP;
8088
MonitoringAPController<TableSpaceUsage> tableSpaceUsageMAP;
8189
MonitoringAPController<ASMDiskUsage> asmDiskUsageMAP;
8290
MonitoringAPController<OSDiskUsage> osDiskUsageMAP;
8391
Map<String, AlertLog> alertLogMonitoringResultMap;
84-
92+
8593
/* Common Data */
8694
String lastUseConnInfoFilePath = null;
8795
String lastUseMonitoringPresetName = null;
8896
String[] dbNames = null;
89-
String[] serverNames = null;
97+
String[] serverNames = null;
9098
String[] connInfoFiles = null;
9199
List<String> presetList = null;
92-
100+
93101
public HistoryMenuController() {
94102
archiveUsageMAP = new MonitoringAPController<>(ArchiveUsage.class);
95103
tableSpaceUsageMAP = new MonitoringAPController<>(TableSpaceUsage.class);
96104
asmDiskUsageMAP = new MonitoringAPController<>(ASMDiskUsage.class);
97105
osDiskUsageMAP = new MonitoringAPController<>(OSDiskUsage.class);
98106
alertLogMonitoringResultMap = new HashMap<>();
99107
}
100-
108+
101109
/**
102110
* 실행메뉴 화면 진입시 초기화를 수행한다.
103111
*/
@@ -112,86 +120,50 @@ public void initialize(URL location, ResourceBundle resources) {
112120
* 3-1. 있으면 해당 파일을 Load한다.
113121
* 3-2. 없으면 첫 번째 파일을 Load한다.
114122
*/
115-
// 접속정보 설정 프로퍼티 파일
123+
// 접속정보 설정 프로퍼티 파일
116124
connInfoFiles = propRepo.getConnectionInfoFileNames();
117-
if(connInfoFiles != null && connInfoFiles.length != 0) {
125+
if (connInfoFiles != null && connInfoFiles.length != 0) {
118126
// Connection Info ComboBox
119127
runConnInfoFileComboBox.getItems().addAll(connInfoFiles);
120-
runConnInfoFileComboBox.getSelectionModel().selectFirst();
128+
runConnInfoFileComboBox.getSelectionModel().selectFirst();
121129
// remember.properties 파일에서, 최근 사용된 설정파일 경로가 있다면 해당 설정파일을 불러온다.
122130
lastUseConnInfoFilePath = propRepo.getLastUseConnInfoFilePath();
123-
if(propRepo.isFileExist(lastUseConnInfoFilePath)) {
124-
runConnInfoFileComboBox.getSelectionModel().select(lastUseConnInfoFilePath);
131+
if (propRepo.isFileExist(lastUseConnInfoFilePath)) {
132+
runConnInfoFileComboBox.getSelectionModel().select(lastUseConnInfoFilePath);
125133
loadConnectionInfoProperties(lastUseConnInfoFilePath);
126134
}
127135
} else {
128136
AlertUtils.showAlert(AlertType.INFORMATION, "접속정보 설정", "설정된 DB/Server 접속정보가 없습니다.\n[설정]메뉴로 이동합니다.");
129137
return;
130138
}
131-
139+
132140
// ComboBox 변경 이벤트
133-
runConnInfoFileComboBox.getSelectionModel().selectedItemProperty().addListener((options, oldValue, newValue) -> {
134-
loadConnectionInfoProperties(newValue);
135-
});
141+
runConnInfoFileComboBox.getSelectionModel().selectedItemProperty()
142+
.addListener((options, oldValue, newValue) -> {
143+
loadConnectionInfoProperties(newValue);
144+
});
136145

137146
String dbComboBoxLabel = "DB 선택";
138147
String[] dbComboBoxItems = dbNames;
139148
String serverComboBoxLabel = "Server 선택";
140149
String[] serverComboBoxItems = serverNames;
141-
150+
142151
// Archive Usage TableView Setting
143-
Map<String, TypeAndFieldName> archiveUsageTCM = new LinkedHashMap<>(); // LinkedHashMap은 순서가 보장된다.
144-
archiveUsageTCM.put("Archive명", new TypeAndFieldName(String.class, "archiveName"));
145-
archiveUsageTCM.put("파일 개수", new TypeAndFieldName(Integer.class, "numberOfFiles"));
146-
archiveUsageTCM.put("전체 공간", new TypeAndFieldName(Double.class, "totalSpace"));
147-
archiveUsageTCM.put("가용 공간", new TypeAndFieldName(Double.class, "reclaimableSpace"));
148-
archiveUsageTCM.put("사용중인 공간", new TypeAndFieldName(Double.class, "usedSpace"));
149-
archiveUsageTCM.put("사용량(%)", new TypeAndFieldName(Double.class, "usedPercent"));
150-
archiveUsageTCM.put("모니터링일시", new TypeAndFieldName(String.class, "monitoringDateTime"));
151-
initAndAddMonitoringAnchorPane(archiveUsageMAP, archiveUsageTabAP, dbComboBoxLabel, dbComboBoxItems, archiveUsageTCM);
152-
153-
// TableSpace Usage TableView Setting
154-
Map<String, TypeAndFieldName> tableSpaceUsageTCM = new LinkedHashMap<>();
155-
tableSpaceUsageTCM.put("테이블스페이스명", new TypeAndFieldName(String.class, "tableSpaceName"));
156-
tableSpaceUsageTCM.put("전체 공간", new TypeAndFieldName(Double.class, "totalSpace"));
157-
tableSpaceUsageTCM.put("가용 공간", new TypeAndFieldName(Double.class, "freeSpace"));
158-
tableSpaceUsageTCM.put("사용중인 공간", new TypeAndFieldName(Double.class, "usedSpace"));
159-
tableSpaceUsageTCM.put("사용량(%)", new TypeAndFieldName(Double.class, "usedPercent"));
160-
tableSpaceUsageTCM.put("모니터링일시", new TypeAndFieldName(String.class, "monitoringDateTime"));
161-
initAndAddMonitoringAnchorPane(tableSpaceUsageMAP, tableSpaceUsageTabAP, dbComboBoxLabel, dbComboBoxItems, tableSpaceUsageTCM);
162-
163-
// ASM Disk USage TableView Setting
164-
Map<String, TypeAndFieldName> asmDiskUsageTCM = new LinkedHashMap<>();
165-
asmDiskUsageTCM.put("디스크 그룹", new TypeAndFieldName(String.class, "asmDiskGroupName"));
166-
asmDiskUsageTCM.put("디스크 타입", new TypeAndFieldName(String.class, "asmDiskGroupType"));
167-
asmDiskUsageTCM.put("전체 공간(Raw)", new TypeAndFieldName(Double.class, "totalRawSpace"));
168-
asmDiskUsageTCM.put("전체 공간(Actual)", new TypeAndFieldName(Double.class, "totalFreeSpace"));
169-
asmDiskUsageTCM.put("가용 공간", new TypeAndFieldName(Double.class, "freeSpace"));
170-
asmDiskUsageTCM.put("사용중인 공간", new TypeAndFieldName(Double.class, "usedSpace"));
171-
asmDiskUsageTCM.put("사용량(%)", new TypeAndFieldName(Double.class, "usedPercent"));
172-
asmDiskUsageTCM.put("모니터링일시", new TypeAndFieldName(String.class, "monitoringDateTime"));
173-
initAndAddMonitoringAnchorPane(asmDiskUsageMAP, asmDiskUsageTabAP, dbComboBoxLabel, dbComboBoxItems, asmDiskUsageTCM);
174-
175-
// OS Disk Usage TableView Setting
176-
Map<String, TypeAndFieldName> osDiskUsageTCM = new LinkedHashMap<>();
177-
osDiskUsageTCM.put("파일 시스템", new TypeAndFieldName(String.class, "fileSystem"));
178-
osDiskUsageTCM.put("마운트 위치", new TypeAndFieldName(String.class, "mountedOn"));
179-
osDiskUsageTCM.put("전체 공간", new TypeAndFieldName(Double.class, "totalSpace"));
180-
osDiskUsageTCM.put("가용 공간", new TypeAndFieldName(Double.class, "freeSpace"));
181-
osDiskUsageTCM.put("사용중인 공간", new TypeAndFieldName(Double.class, "usedSpace"));
182-
osDiskUsageTCM.put("사용량(%)", new TypeAndFieldName(Double.class, "usedPercent"));
183-
osDiskUsageTCM.put("모니터링일시", new TypeAndFieldName(String.class, "monitoringDateTime"));
184-
initAndAddMonitoringAnchorPane(osDiskUsageMAP, osDiskUsageTabAP, serverComboBoxLabel, serverComboBoxItems, osDiskUsageTCM);
152+
initAndAddMonitoringAnchorPane(archiveUsageMAP, archiveUsageTabAP, dbComboBoxLabel, dbComboBoxItems);
153+
initAndAddMonitoringAnchorPane(tableSpaceUsageMAP, tableSpaceUsageTabAP, dbComboBoxLabel, dbComboBoxItems);
154+
initAndAddMonitoringAnchorPane(asmDiskUsageMAP, asmDiskUsageTabAP, dbComboBoxLabel, dbComboBoxItems);
155+
initAndAddMonitoringAnchorPane(osDiskUsageMAP, osDiskUsageTabAP, serverComboBoxLabel, serverComboBoxItems);
185156

186157
// TODO TableColumn 속성을 설정하는 메서드를 따로 구분해보자. 객체를 생성해서 전달하는 방법도 고려하기
187158
// ex) TableColumnHeaderText, Width, Align
188-
159+
189160
// AlertLog 화면의 UI 요소를 초기화한다.
190161
initAlertLogMonitoringElements();
191162
}
192-
163+
193164
/**
194165
* 모니터링 AnchorPane 추가하고 요소를 초기화한다.
166+
*
195167
* @param <T>
196168
* @param monitoringAP
197169
* @param parentAP
@@ -200,26 +172,21 @@ public void initialize(URL location, ResourceBundle resources) {
200172
* @param tableColumns
201173
*/
202174
private <T extends MonitoringResult> void initAndAddMonitoringAnchorPane(MonitoringAPController<T> monitoringAP,
203-
AnchorPane parentAP, String labelText, String[] comboBoxItems, Map<String, TypeAndFieldName> tableColumns) {
175+
AnchorPane parentAP, String labelText, String[] comboBoxItems) {
204176

205-
monitoringAP.setAnchor(0, 0, 0, 0); // Anchor Constraint 설정
206177
monitoringAP.setAliasComboBoxLabelText(labelText); // ComboBox 좌측 Lebel Text 설정
207178
monitoringAP.setAliasComboBoxItems(comboBoxItems); // ComboBox Items 설정
208-
for (String key : tableColumns.keySet()) { // TableView에 출력할 Column 설정
209-
monitoringAP.addAndSetPropertyTableColumn(tableColumns.get(key).getClazz(),
210-
tableColumns.get(key).getFieldName(), key);
211-
}
212179
parentAP.getChildren().add(monitoringAP); // Monitoring AnchorPane을 부모 Node에 추가
213180
}
214-
181+
215182
private void changeAlertLogListViewData(String serverID) {
216183
alertLogLV.getItems().clear();
217184
AlertLog al = alertLogMonitoringResultMap.get(serverID);
218-
if(al != null) {
219-
alertLogLV.getItems().addAll(al.getAlertLogs());
185+
if (al != null) {
186+
alertLogLV.getItems().addAll(al.getAlertLogs());
220187
}
221188
}
222-
189+
223190
/**
224191
* AlertLog AnchorPane의 UI 요소들의 값을 초기화한다.
225192
*/
@@ -234,29 +201,30 @@ private void initAlertLogMonitoringElements() {
234201
// AlertLog 조회기간 기본값 설정
235202
alertLogStartDayDP.setValue(LocalDate.now().minusDays(1));
236203
alertLogEndDayDP.setValue(LocalDate.now());
237-
204+
238205
// AlertLog 조회기간 오늘 이후 날짜 선택 불가
239206
alertLogStartDayDP.setDayCellFactory(picker -> new DisableAfterTodayDateCell());
240207
alertLogEndDayDP.setDayCellFactory(picker -> new DisableAfterTodayDateCell());
241-
208+
242209
// AlertLog 조회기간 변경 이벤트
243210
alertLogStartDayDP.valueProperty().addListener((ov, oldValue, newValue) -> {
244-
if(alertLogEndDayDP.getValue().isBefore(newValue)) {
211+
if (alertLogEndDayDP.getValue().isBefore(newValue)) {
245212
alertLogEndDayDP.setValue(newValue);
246213
}
247214
});
248215
alertLogEndDayDP.valueProperty().addListener((ov, oldValue, newValue) -> {
249-
if(alertLogStartDayDP.getValue().isAfter(newValue)) {
216+
if (alertLogStartDayDP.getValue().isAfter(newValue)) {
250217
alertLogStartDayDP.setValue(newValue);
251218
}
252219
});
253-
220+
254221
// AlertLog ListView
255222
alertLogLV.setCellFactory(categoryList -> new AlertLogListViewCell());
256223
}
257224

258225
/**
259226
* [실행] - 접속정보 설정파일을 읽고, 모니터링설정 Preset을 읽는다.
227+
*
260228
* @param connInfoConfigFilePath
261229
*/
262230
private void loadConnectionInfoProperties(String connInfoConfigFilePath) {
@@ -268,21 +236,25 @@ private void loadConnectionInfoProperties(String connInfoConfigFilePath) {
268236
// DB/Server Names
269237
dbNames = propRepo.getMonitoringDBNames();
270238
serverNames = propRepo.getMonitoringServerNames();
271-
// Monitoring Preset ComboBox
239+
// Monitoring Preset ComboBox
272240
runMonitoringPresetComboBox.getItems().clear();
273241
runMonitoringPresetComboBox.getItems().addAll(presetList);
274242
runMonitoringPresetComboBox.getSelectionModel().selectFirst();
275-
if(lastUseMonitoringPresetName != null) {
243+
if (lastUseMonitoringPresetName != null) {
276244
runMonitoringPresetComboBox.getSelectionModel().select(lastUseMonitoringPresetName);
277245
}
278246
}
279-
247+
280248
/**
281249
* [실행] - 모니터링을 시작한다.
250+
*
282251
* @param e
283252
*/
284253
public void runMonitoring(ActionEvent e) {
285-
if(!validateInput()) return;
254+
if (!validateInput()) {
255+
return;
256+
}
257+
286258

287259
// DB Usage Check
288260
List<JdbcConnectionInfo> jdbcConnectionList = propService
@@ -309,29 +281,34 @@ public void runMonitoring(ActionEvent e) {
309281
server.init();
310282
ServerCheckRepository repo = new ServerCheckRepositoryImpl(server);
311283
ServerCheckUsecase usecase = new ServerCheckUsecaseImpl(repo, ReportFileRepo.getInstance());
312-
284+
313285
PropertiesConfiguration config = propRepo.getConfiguration("connInfoConfig");
314-
String alertLogFilePath = config.getString(jsch.getServerName().toLowerCase() + ".server.alertlog.filepath");
315-
String alertLogReadLine = config.getString(jsch.getServerName().toLowerCase() + ".server.alertlog.readline");
316-
String alertLogDateFormat = config.getString(jsch.getServerName().toLowerCase() + ".server.alertlog.dateformat");
317-
String alertLogDateFormatRegex = config.getString(jsch.getServerName().toLowerCase() + ".server.alertlog.dateformatregex");
318-
AlertLogCommand alc = new AlertLogCommand("tail", alertLogReadLine, alertLogFilePath, alertLogDateFormat, alertLogDateFormatRegex);
286+
String alertLogFilePath = config
287+
.getString(jsch.getServerName().toLowerCase() + ".server.alertlog.filepath");
288+
String alertLogReadLine = config
289+
.getString(jsch.getServerName().toLowerCase() + ".server.alertlog.readline");
290+
String alertLogDateFormat = config
291+
.getString(jsch.getServerName().toLowerCase() + ".server.alertlog.dateformat");
292+
String alertLogDateFormatRegex = config
293+
.getString(jsch.getServerName().toLowerCase() + ".server.alertlog.dateformatregex");
294+
AlertLogCommand alc = new AlertLogCommand("tail", alertLogReadLine, alertLogFilePath, alertLogDateFormat,
295+
alertLogDateFormatRegex);
319296
AlertLogCommandPeriod alcp = new AlertLogCommandPeriod(alc, alertLogStartDay, alertLogEndDay);
320297

321298
osDiskUsageMAP.addTableData(server.getServerName(), usecase.getCurrentOSDiskUsage());
322299
alertLogMonitoringResultMap.put(server.getServerName(), usecase.getAlertLogDuringPeriod(alcp));
323300
}
324-
301+
325302
archiveUsageMAP.syncTableData(archiveUsageMAP.getSelectedAliasComboBoxItem(), 0);
326303
tableSpaceUsageMAP.syncTableData(tableSpaceUsageMAP.getSelectedAliasComboBoxItem(), 0);
327304
asmDiskUsageMAP.syncTableData(asmDiskUsageMAP.getSelectedAliasComboBoxItem(), 0);
328305
osDiskUsageMAP.syncTableData(osDiskUsageMAP.getSelectedAliasComboBoxItem(), 0);
329306
changeAlertLogListViewData(alertLogServerComboBox.getSelectionModel().getSelectedItem());
330307
}
331-
332-
308+
333309
/**
334310
* [실행] - 모니터링 실행 시, 입력값 검사
311+
*
335312
* @return
336313
*/
337314
private boolean validateInput() {
@@ -340,27 +317,27 @@ private boolean validateInput() {
340317

341318
// 1. AlertLog 조회기간
342319
alertHeaderText = "AlertLog 조회기간";
343-
320+
344321
LocalDate alertLogStartDay = alertLogStartDayDP.getValue();
345322
LocalDate alertLogEndDay = alertLogEndDayDP.getValue();
346-
if(alertLogStartDay == null || alertLogEndDay == null) {
323+
if (alertLogStartDay == null || alertLogEndDay == null) {
347324
alertContentText = "조회기간을 입력해주세요.";
348325
AlertUtils.showAlert(AlertType.ERROR, alertHeaderText, alertContentText);
349326
return false;
350327
}
351328

352329
try {
353-
if(!alertLogStartDay.isBefore(alertLogEndDay) && !alertLogStartDay.isEqual(alertLogEndDay)) {
330+
if (!alertLogStartDay.isBefore(alertLogEndDay) && !alertLogStartDay.isEqual(alertLogEndDay)) {
354331
alertContentText = "조회시작일은 조회종료일보다 이전 날짜여야 합니다.";
355332
AlertUtils.showAlert(AlertType.ERROR, alertHeaderText, alertContentText);
356333
return false;
357-
}
334+
}
358335
} catch (Exception e) {
359336
alertContentText = "조회기간이 올바르지 않습니다.";
360337
AlertUtils.showAlert(AlertType.ERROR, alertHeaderText, alertContentText);
361338
return false;
362339
}
363-
340+
364341
return true;
365342
}
366343

0 commit comments

Comments
 (0)