Skip to content

Commit 54cf2ab

Browse files
authored
Merge pull request #136 from Dokyeongyun/ft-220130-newPropertyFile
Ft 220130 new property file
2 parents 41a45e3 + 68104ac commit 54cf2ab

File tree

12 files changed

+233
-81
lines changed

12 files changed

+233
-81
lines changed

src/main/java/root/common/server/implement/JschServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public void init() {
2525
session = null;
2626

2727
try {
28-
session = jsch.getSession(jschConnectionInfo.getUserName(), jschConnectionInfo.getHost(), jschConnectionInfo.getPort());
28+
session = jsch.getSession(jschConnectionInfo.getUserName(), jschConnectionInfo.getHost(),
29+
Integer.valueOf(jschConnectionInfo.getPort()));
2930
session.setPassword(jschConnectionInfo.getPassword());
3031

3132
Properties config = new Properties();

src/main/java/root/core/domain/JschConnectionInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public class JschConnectionInfo {
77
private String serverName;
88
private String host;
9-
private int port;
9+
private String port;
1010
private String userName;
1111
private String password;
1212
private AlertLogCommand alc;
@@ -15,7 +15,7 @@ public JschConnectionInfo() {
1515
this.alc = new AlertLogCommand();
1616
}
1717

18-
public JschConnectionInfo(String serverName, String host, int port, String userName, String password) {
18+
public JschConnectionInfo(String serverName, String host, String port, String userName, String password) {
1919
this.serverName = serverName;
2020
this.host = host;
2121
this.port = port;
@@ -24,7 +24,7 @@ public JschConnectionInfo(String serverName, String host, int port, String userN
2424
this.alc = new AlertLogCommand();
2525
}
2626

27-
public JschConnectionInfo(String serverName, String host, int port, String userName, String password,
27+
public JschConnectionInfo(String serverName, String host, String port, String userName, String password,
2828
AlertLogCommand alc) {
2929
this.serverName = serverName;
3030
this.host = host;

src/main/java/root/core/repository/constracts/PropertyRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
public interface PropertyRepository {
1212

13+
boolean isFileExist(String filePath);
14+
1315
PropertiesConfiguration getConfiguration(String config);
1416

1517
void save(String filePath, PropertiesConfiguration config);

src/main/java/root/core/repository/implement/PropertyRepositoryImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public static PropertyRepository getInstance() {
3939

4040
/****************************************************************************/
4141

42+
@Override
43+
public boolean isFileExist(String filePath) {
44+
return new File(filePath).exists();
45+
}
46+
4247
/**
4348
* Configuration 객체를 반환한다.
4449
* TODO 굳이 메서드를 Wrapping 해서 호출할 필요가 있을까..? Controller와 의존성 제거목적으로 일단 이렇게 함..

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void initialize(URL location, ResourceBundle resources) {
109109
runConnInfoFileComboBox.getSelectionModel().selectFirst();
110110
// remember.properties 파일에서, 최근 사용된 설정파일 경로가 있다면 해당 설정파일을 불러온다.
111111
lastUseConnInfoFilePath = propertyRepository.getLastUseConnInfoFilePath();
112-
if(lastUseConnInfoFilePath != null) {
112+
if(propertyRepository.isFileExist(lastUseConnInfoFilePath)) {
113113
runConnInfoFileComboBox.getSelectionModel().select(lastUseConnInfoFilePath);
114114
loadConnectionInfoProperties(lastUseConnInfoFilePath);
115115
}

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

Lines changed: 107 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import java.util.ResourceBundle;
1010

1111
import org.apache.commons.configuration2.PropertiesConfiguration;
12+
import org.apache.commons.lang3.StringUtils;
1213
import org.apache.log4j.Logger;
1314

14-
import com.jfoenix.controls.JFXButton;
1515
import com.jfoenix.controls.JFXComboBox;
1616
import com.jfoenix.controls.JFXToggleButton;
1717

@@ -24,7 +24,6 @@
2424
import javafx.scene.Node;
2525
import javafx.scene.control.Alert;
2626
import javafx.scene.control.Alert.AlertType;
27-
import javafx.scene.control.Button;
2827
import javafx.scene.control.ButtonBar.ButtonData;
2928
import javafx.scene.control.ButtonType;
3029
import javafx.scene.control.Label;
@@ -41,7 +40,6 @@
4140
import javafx.scene.text.TextAlignment;
4241
import javafx.stage.FileChooser;
4342
import javafx.stage.FileChooser.ExtensionFilter;
44-
import javafx.stage.Popup;
4543
import javafx.stage.Stage;
4644
import root.core.domain.AlertLogCommand;
4745
import root.core.domain.JdbcConnectionInfo;
@@ -51,14 +49,15 @@
5149
import root.javafx.CustomView.ConnectionInfoVBox;
5250
import root.javafx.CustomView.DBConnectionInfoAnchorPane;
5351
import root.javafx.CustomView.ServerConnectionInfoAnchorPane;
52+
import root.utils.AlertUtils;
5453
import root.utils.PropertiesUtils;
5554

5655
public class SettingMenuController implements Initializable {
5756
private static Logger logger = Logger.getLogger(SettingMenuController.class);
5857

5958
/**
6059
* Pattern 객체를 정적필드로 선언한 이유
61-
* - Pattern 객체는 입력받은 정규표현식에 해당하는 유한상태머신(finite statemachine)을
60+
* - Pattern 객체는 입력받은 정규표현식에 해당하는 유한상태머신(finite state machine)을
6261
* 생성하기 때문에 인스턴스 생성비용이 높다.
6362
* - 따라서, 한 번 생성하두고 이를 재사용하는 것이 효과적이다.
6463
* - 뿐만 아니라, 패턴 객체에 이름을 부여하여 해당 객체의 의미가 명확해진다.
@@ -72,20 +71,14 @@ public class SettingMenuController implements Initializable {
7271
SplitPane rootSplitPane;
7372

7473
@FXML
75-
AnchorPane noPropertiesFileAP1; // [설정] - [모니터링 여부 설정] 설정파일이 지정되지 않았을 때 보여줄 AnchorPane
74+
AnchorPane noConnInfoConfigAP; // [설정] - [접속정보 설정] 설정파일이 지정되지 않았을 때 보여줄 AnchorPane
7675

7776
@FXML
78-
AnchorPane noPropertiesFileAP2; // [설정] - [접속정보 설정] 설정파일이 지정되지 않았을 때 보여줄 AnchorPane
77+
AnchorPane noMonitoringConfigAP; // [설정] - [모니터링 여부 설정] 설정파일이 지정되지 않았을 때 보여줄 AnchorPane
7978

8079
@FXML
8180
VBox monitoringElementsVBox;
8281

83-
@FXML
84-
JFXButton settingSaveBtn;
85-
86-
@FXML
87-
Button fileChooserBtn; // 설정파일을 선택하기 위한 FileChooser
88-
8982
@FXML
9083
TextField fileChooserText; // 설정파일 경로를 입력/출력하는 TextField
9184

@@ -108,24 +101,24 @@ public class SettingMenuController implements Initializable {
108101

109102
Map<String, String> monitoringPresetMap = new HashMap<>();
110103

111-
// 모니터링 여부 설정 Preset Popup
112-
Popup presetInputPopup = new Popup();
113-
114104
@Override
115105
public void initialize(URL location, ResourceBundle resources) {
116106

117107
// remember.properties 파일에서, 최근 사용된 설정파일 경로가 있다면 해당 설정파일을 불러온다.
118108
String lastUsePropertiesFile = propertyRepository.getLastUseConnInfoFilePath();
119109
logger.debug("최근 사용된 프로퍼티파일: " + lastUsePropertiesFile);
120-
if (lastUsePropertiesFile != null) {
110+
if (propertyRepository.isFileExist(lastUsePropertiesFile)) {
121111
loadSelectedConfigFile(lastUsePropertiesFile);
122-
}
123112

124-
// [설정] - [모니터링 여부 설정] - Preset 변경 Event
125-
monitoringPresetComboBox.getSelectionModel().selectedItemProperty()
126-
.addListener((options, oldValue, newValue) -> {
127-
loadMonitoringConfigFile(monitoringPresetMap.get(newValue));
128-
});
113+
// [설정] - [모니터링 여부 설정] - Preset 변경 Event
114+
monitoringPresetComboBox.getSelectionModel().selectedItemProperty()
115+
.addListener((options, oldValue, newValue) -> {
116+
loadMonitoringConfigFile(monitoringPresetMap.get(newValue));
117+
});
118+
} else {
119+
setVisible(noConnInfoConfigAP, true);
120+
setVisible(noMonitoringConfigAP, true);
121+
}
129122
}
130123

131124
/**
@@ -134,7 +127,6 @@ public void initialize(URL location, ResourceBundle resources) {
134127
* @param e
135128
*/
136129
public void showMonitoringPresetPopup(ActionEvent e) {
137-
138130
// TextInputDialog 생성
139131
TextInputDialog presetInputDialog = new TextInputDialog();
140132
// ICON
@@ -164,7 +156,7 @@ public void showMonitoringPresetPopup(ActionEvent e) {
164156
String connInfoFileName = connInfoFile.getName().substring(0,
165157
connInfoFile.getName().indexOf(".properties"));
166158
String filePath = "./config/monitoring/" + connInfoFileName + "/" + input + ".properties";
167-
PropertiesUtils.createNewPropertiesFile(filePath);
159+
PropertiesUtils.createNewPropertiesFile(filePath, "Monitoring");
168160

169161
// 2. 접속정보설정파일에 Preset 추가
170162
PropertiesConfiguration config = PropertiesUtils.connInfoConfig;
@@ -235,20 +227,20 @@ private void loadSelectedConfigFile(String absoluteFilePath) {
235227
// 3. 프로퍼티파일에 작성된 내용에 따라 동적 요소를 생성한다.
236228
createSettingDynamicElements();
237229

238-
// 5. remember.properties 파일에 최근 사용된 설정파일 경로를 저장한다.
230+
// 4. remember.properties 파일에 최근 사용된 설정파일 경로를 저장한다.
239231
PropertiesConfiguration rememberConfig = propertyRepository.getConfiguration("rememberConfig");
240232
rememberConfig.setProperty("filepath.config.lastuse", filePath.replace("\\", "/"));
241233
propertyRepository.save(rememberConfig.getString("filepath.config.remember"), rememberConfig);
242234

243-
// 6. fileChooserText의 텍스트를 현재 선택된 파일경로로 변경한다.
235+
// 5. fileChooserText의 텍스트를 현재 선택된 파일경로로 변경한다.
244236
fileChooserText.setText(filePath);
245237

246238
loadResult = true;
247239
} catch (Exception e1) {
248240
e1.printStackTrace();
249241
} finally {
250242

251-
// 7. 파일 load가 완료되었다는 메시지를 띄운다.
243+
// 6. 파일 load가 완료되었다는 메시지를 띄운다.
252244
if (loadResult) {
253245
Alert successAlert = new Alert(AlertType.INFORMATION);
254246
successAlert.setHeaderText("설정파일 불러오기");
@@ -265,6 +257,11 @@ private void loadSelectedConfigFile(String absoluteFilePath) {
265257
}
266258
}
267259

260+
/**
261+
* [설정] - [모니터링 여부 설정] - 모니터링 여부 설정파일을 불러온다.
262+
*
263+
* @param filePath
264+
*/
268265
private void loadMonitoringConfigFile(String filePath) {
269266
monitoringElementsVBox.getChildren().clear();
270267
dbMonitorings = propertyRepository.getDBMonitoringContents();
@@ -476,10 +473,18 @@ private void createSettingDynamicElements() {
476473
connInfoVBox.getChildren().add(dbConnVBox);
477474
}
478475

479-
for (JdbcConnectionInfo jdbc : jdbcConnInfoList) {
476+
if (jdbcConnInfoList.size() == 0) {
480477
DBConnectionInfoAnchorPane dbConnAP = new DBConnectionInfoAnchorPane();
481-
dbConnAP.setInitialValue(jdbc);
478+
dbConnAP.init();
479+
dbConnAP.setInitialValue(new JdbcConnectionInfo());
482480
dbConnVBox.addConnectionInfoAP(1, dbConnAP);
481+
} else {
482+
for (JdbcConnectionInfo jdbc : jdbcConnInfoList) {
483+
DBConnectionInfoAnchorPane dbConnAP = new DBConnectionInfoAnchorPane();
484+
dbConnAP.init();
485+
dbConnAP.setInitialValue(jdbc);
486+
dbConnVBox.addConnectionInfoAP(1, dbConnAP);
487+
}
483488
}
484489

485490
ConnectionInfoVBox serverConnVBox = null;
@@ -493,11 +498,17 @@ private void createSettingDynamicElements() {
493498
serverConnVBox.setId("serverConnVBox");
494499
connInfoVBox.getChildren().add(serverConnVBox);
495500
}
496-
497-
for (JschConnectionInfo jsch : jschConnInfoList) {
501+
502+
if (jschConnInfoList.size() == 0) {
498503
ServerConnectionInfoAnchorPane serverConnAP = new ServerConnectionInfoAnchorPane();
499-
serverConnAP.setInitialValue(jsch);
504+
serverConnAP.setInitialValue(new JschConnectionInfo());
500505
serverConnVBox.addConnectionInfoAP(1, serverConnAP);
506+
} else {
507+
for (JschConnectionInfo jsch : jschConnInfoList) {
508+
ServerConnectionInfoAnchorPane serverConnAP = new ServerConnectionInfoAnchorPane();
509+
serverConnAP.setInitialValue(jsch);
510+
serverConnVBox.addConnectionInfoAP(1, serverConnAP);
511+
}
501512
}
502513

503514
// [설정] - [모니터링 여부 설정]
@@ -526,11 +537,11 @@ private void reloadingMonitoringSetting(String presetName) {
526537
monitoringPresetComboBox.getItems().addAll(monitoringPresetMap.keySet());
527538
logger.debug("monitoringPresetMap : " + monitoringPresetMap);
528539

529-
// 지정된 Preset이 없다면 최근 사용된 Preset으로 세팅한다. 만약 최근 사용된 Preset이 없다면 첫번째 Preset으로
530-
// 세팅한다.
540+
// 지정된 Preset이 없다면 최근 사용된 Preset으로 세팅한다.
541+
// 만약 최근 사용된 Preset이 없다면 첫번째 Preset으로 세팅한다.
531542
if (presetName.isEmpty()) {
532543
// 최근 사용된 모니터링 설정 읽기
533-
if (lastUsePresetName.isEmpty() && monitoringPresetComboBox.getItems().size() != 0) {
544+
if (StringUtils.isEmpty(lastUsePresetName) && monitoringPresetComboBox.getItems().size() != 0) {
534545
// 최근 사용된 설정이 없다면, 첫번째 설정 읽기
535546
readPresetName = monitoringPresetComboBox.getItems().get(0);
536547
logger.debug("첫번째 Preset: " + readPresetName);
@@ -547,9 +558,69 @@ private void reloadingMonitoringSetting(String presetName) {
547558
logger.debug("readPresetFilePath : " + readPresetFilePath);
548559

549560
// ComboBox 선택 및 Preset 파일 읽기
550-
if (!readPresetName.isEmpty()) {
561+
if (!StringUtils.isEmpty(readPresetName)) {
551562
monitoringPresetComboBox.getSelectionModel().select(readPresetName);
552563
loadMonitoringConfigFile(monitoringPresetMap.get(readPresetName));
553564
}
554565
}
566+
567+
private void setVisible(Node node, boolean isVisible) {
568+
node.setVisible(isVisible);
569+
if (isVisible) {
570+
node.toFront();
571+
} else {
572+
node.toBack();
573+
}
574+
}
575+
576+
/**
577+
* [설정] - [접속정보 설정] - 새로운 접속정보 설정파일을 생성한다.
578+
* @param e
579+
*/
580+
public void createNewConfigFile(ActionEvent e) {
581+
// TextInputDialog 생성
582+
TextInputDialog configInputDialog = new TextInputDialog();
583+
// ICON
584+
configInputDialog.setGraphic(new FontAwesomeIconView(FontAwesomeIcon.PENCIL, "30"));
585+
// CSS
586+
configInputDialog.getDialogPane().getStylesheets()
587+
.add(getClass().getResource("/css/dialog.css").toExternalForm());
588+
configInputDialog.getDialogPane().getStyleClass().add("textInputDialog");
589+
// Dialog ICON
590+
Stage stage = (Stage) configInputDialog.getDialogPane().getScene().getWindow();
591+
stage.getIcons().add(new Image(this.getClass().getResource("/image/add_icon.png").toString()));
592+
// Button Custom
593+
ButtonType okButton = new ButtonType("입력", ButtonData.OK_DONE);
594+
configInputDialog.getDialogPane().getButtonTypes().removeAll(ButtonType.OK, ButtonType.CANCEL);
595+
configInputDialog.getDialogPane().getButtonTypes().addAll(okButton, ButtonType.CANCEL);
596+
// Content
597+
configInputDialog.setTitle("접속정보 설정파일 생성");
598+
configInputDialog.setHeaderText("새로운 접속정보 설정파일의 이름을 입력해주세요.");
599+
configInputDialog.setContentText("설정파일명: ");
600+
// Result
601+
Optional<String> result = configInputDialog.showAndWait();
602+
result.ifPresent(input -> {
603+
if (input.length() == 0) {
604+
AlertUtils.showAlert(AlertType.ERROR, "접속정보 설정파일 생성", "설정파일명을 입력해주세요.");
605+
return;
606+
}
607+
608+
// TODO 입력값 검사 (영어만)
609+
610+
// 1. 접속정보 설정파일 생성 (./config/connectioninfo/{접속정보설정파일명}.properties
611+
String filePath = "./config/connectioninfo/" + input + ".properties";
612+
PropertiesUtils.createNewPropertiesFile(filePath, "ConnectionInfo");
613+
614+
// 2. 모니터링여부 Preset 설정파일 생성 (./config/monitoring/{접속정보설정파일명}/{default}.properties
615+
String presetConfigPath = "./config/monitoring/" + input + "/default.properties";
616+
PropertiesUtils.createNewPropertiesFile(presetConfigPath, "Monitoring");
617+
618+
// 3. Set Node Visible
619+
setVisible(noConnInfoConfigAP, false);
620+
setVisible(noMonitoringConfigAP, false);
621+
622+
// 4. 생성된 설정파일 Load
623+
loadSelectedConfigFile(filePath);
624+
});
625+
}
555626
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public void testConnection(ActionEvent e) {
170170
public void addNewConnInfo(ActionEvent e) {
171171
if (childAPClazz == DBConnectionInfoAnchorPane.class) {
172172
DBConnectionInfoAnchorPane dbConnAP = new DBConnectionInfoAnchorPane();
173+
dbConnAP.init();
173174
dbConnAP.setInitialValue(new JdbcConnectionInfo());
174175
addConnectionInfoAP(2, dbConnAP);
175176

0 commit comments

Comments
 (0)