|
1 | 1 | package root.javafx.Controller; |
2 | 2 |
|
3 | 3 | import java.net.URL; |
| 4 | +import java.sql.SQLException; |
4 | 5 | import java.util.ArrayList; |
5 | | -import java.util.Arrays; |
6 | 6 | import java.util.List; |
7 | 7 | import java.util.ResourceBundle; |
8 | 8 |
|
| 9 | +import org.apache.commons.lang.StringUtils; |
| 10 | +import org.apache.commons.lang3.ArrayUtils; |
| 11 | + |
| 12 | +import com.jfoenix.controls.JFXComboBox; |
| 13 | + |
9 | 14 | import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon; |
| 15 | +import javafx.beans.value.ChangeListener; |
| 16 | +import javafx.beans.value.ObservableValue; |
10 | 17 | import javafx.fxml.FXML; |
11 | 18 | import javafx.fxml.Initializable; |
12 | 19 | import javafx.scene.Node; |
|
20 | 27 | import root.core.domain.MonitoringResult; |
21 | 28 | import root.core.domain.OSDiskUsage; |
22 | 29 | import root.core.domain.TableSpaceUsage; |
| 30 | +import root.core.repository.implement.PropertyRepositoryImpl; |
| 31 | +import root.core.service.contracts.PropertyService; |
| 32 | +import root.core.service.implement.FilePropertyService; |
23 | 33 | import root.javafx.CustomView.CustomTreeTableView; |
24 | 34 | import root.javafx.CustomView.CustomTreeView; |
25 | 35 | import root.javafx.CustomView.MonitoringTableView; |
|
28 | 38 |
|
29 | 39 | public class RunMenuController implements Initializable { |
30 | 40 |
|
| 41 | + /* Dependency Injection */ |
| 42 | + PropertyService propService = new FilePropertyService(PropertyRepositoryImpl.getInstance()); |
| 43 | + |
31 | 44 | @FXML |
32 | 45 | AnchorPane connInfoSettingAP; |
33 | 46 |
|
| 47 | + @FXML |
| 48 | + JFXComboBox<String> connInfoFileListComboBox; |
| 49 | + |
34 | 50 | @FXML |
35 | 51 | AnchorPane presetSettingAP; |
36 | 52 |
|
@@ -70,13 +86,32 @@ public class RunMenuController implements Initializable { |
70 | 86 | @Override |
71 | 87 | public void initialize(URL location, ResourceBundle resources) { |
72 | 88 |
|
73 | | - // 접속정보 리스트 TreeView |
74 | | - CustomTreeView connInfoCtv = new CustomTreeView("접속정보 리스트", FontAwesomeIcon.LIST, true); |
75 | | - connInfoCtv.addTreeItem("DB", new ArrayList<>(Arrays.asList("DB1", "DB2", "DB3")), FontAwesomeIcon.DATABASE); |
76 | | - connInfoCtv.addTreeItem("Server", new ArrayList<>(Arrays.asList("Server1", "Server2", "Server3", "Server4")), |
77 | | - FontAwesomeIcon.SERVER); |
78 | | - setAnchorPaneAnchor(connInfoCtv, 80, 0, 0, 0); |
79 | | - connInfoSettingAP.getChildren().add(connInfoCtv); |
| 89 | + /* 1. 모니터링 접속정보 설정 */ |
| 90 | + // 1-1. 모니터링 접속정보 설정파일 콤보박스 아이템 설정 |
| 91 | + List<String> connInfoFileList = propService.getConnectionInfoList(); |
| 92 | + if (connInfoFileList == null || ArrayUtils.isEmpty(connInfoFileList.toArray())) { |
| 93 | + // TODO 접속정보 설정파일이 없는 경우 |
| 94 | + addMonitoringConnInfoPreview(new ArrayList<>(), new ArrayList<>()); |
| 95 | + } else { |
| 96 | + connInfoFileListComboBox.getItems().addAll(connInfoFileList); |
| 97 | + } |
| 98 | + |
| 99 | + // 1-2. 모니터링 접속정보 설정파일 콤보박스 아이템 변경 리스너 설정 |
| 100 | + connInfoFileListComboBox.valueProperty().addListener((observable, oldValue, newValue) -> { |
| 101 | + propService.loadConnectionInfoConfig(newValue); |
| 102 | + List<String> dbNames = propService.getMonitoringDBNameList(); |
| 103 | + List<String> serverNames = propService.getMonitoringServerNameList(); |
| 104 | + addMonitoringConnInfoPreview(dbNames, serverNames); |
| 105 | + }); |
| 106 | + |
| 107 | + // 1-3. 모니터링 접속정보 설정파일 콤보박스 초기값 설정 |
| 108 | + String lastUseConnInfoFile = propService.getLastUseConnectionInfo(); |
| 109 | + if (StringUtils.isEmpty(lastUseConnInfoFile) || !connInfoFileList.contains(lastUseConnInfoFile)) { |
| 110 | + // 최근 사용된 접속정보 설정파일이 없거나 현재 존재하지 않는 경우, 첫 번째 설정파일 선택 |
| 111 | + connInfoFileListComboBox.getSelectionModel().selectFirst(); |
| 112 | + } else { |
| 113 | + connInfoFileListComboBox.getSelectionModel().select(lastUseConnInfoFile); |
| 114 | + } |
80 | 115 |
|
81 | 116 | // 모니터링 여부 리스트 TreeTableView |
82 | 117 | List<DBMonitoringYN> list1 = new ArrayList<>(); |
@@ -174,4 +209,19 @@ private <T> MonitoringTableView<T> addMonitoringTableView(AnchorPane parent, |
174 | 209 | parent.getChildren().add(tableView); |
175 | 210 | return tableView; |
176 | 211 | } |
| 212 | + |
| 213 | + /** |
| 214 | + * 모니터링 접속정보를 보여주는 TreeView를 생성 및 추가한다. |
| 215 | + * |
| 216 | + * @param dbNameList |
| 217 | + * @param serverNameList |
| 218 | + */ |
| 219 | + private void addMonitoringConnInfoPreview(List<String> dbNameList, List<String> serverNameList) { |
| 220 | + // 접속정보 리스트 TreeView |
| 221 | + CustomTreeView connInfoCtv = new CustomTreeView("접속정보 리스트", FontAwesomeIcon.LIST, true); |
| 222 | + connInfoCtv.addTreeItem("DB", dbNameList, FontAwesomeIcon.DATABASE); |
| 223 | + connInfoCtv.addTreeItem("Server", serverNameList, FontAwesomeIcon.SERVER); |
| 224 | + setAnchorPaneAnchor(connInfoCtv, 80, 0, 0, 0); |
| 225 | + connInfoSettingAP.getChildren().add(connInfoCtv); |
| 226 | + } |
177 | 227 | } |
0 commit comments