Skip to content

Commit a1bbb48

Browse files
committed
Create new property file
1 parent c0ef6ad commit a1bbb48

File tree

10 files changed

+162
-63
lines changed

10 files changed

+162
-63
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/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: 98 additions & 30 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
* - 뿐만 아니라, 패턴 객체에 이름을 부여하여 해당 객체의 의미가 명확해진다.
@@ -80,12 +79,6 @@ public class SettingMenuController implements Initializable {
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,16 +101,13 @@ 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 && propertyRepository.isFileExist(lastUsePropertiesFile)) {
110+
if (propertyRepository.isFileExist(lastUsePropertiesFile)) {
121111
loadSelectedConfigFile(lastUsePropertiesFile);
122112

123113
// [설정] - [모니터링 여부 설정] - Preset 변경 Event
@@ -126,8 +116,8 @@ public void initialize(URL location, ResourceBundle resources) {
126116
loadMonitoringConfigFile(monitoringPresetMap.get(newValue));
127117
});
128118
} else {
129-
noConnInfoConfigAP.toFront();
130-
noMonitoringConfigAP.toFront();
119+
setVisible(noConnInfoConfigAP, true);
120+
setVisible(noMonitoringConfigAP, true);
131121
}
132122
}
133123

@@ -137,7 +127,6 @@ public void initialize(URL location, ResourceBundle resources) {
137127
* @param e
138128
*/
139129
public void showMonitoringPresetPopup(ActionEvent e) {
140-
141130
// TextInputDialog 생성
142131
TextInputDialog presetInputDialog = new TextInputDialog();
143132
// ICON
@@ -167,7 +156,7 @@ public void showMonitoringPresetPopup(ActionEvent e) {
167156
String connInfoFileName = connInfoFile.getName().substring(0,
168157
connInfoFile.getName().indexOf(".properties"));
169158
String filePath = "./config/monitoring/" + connInfoFileName + "/" + input + ".properties";
170-
PropertiesUtils.createNewPropertiesFile(filePath);
159+
PropertiesUtils.createNewPropertiesFile(filePath, "Monitoring");
171160

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

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

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

249238
loadResult = true;
250239
} catch (Exception e1) {
251240
e1.printStackTrace();
252241
} finally {
253242

254-
// 7. 파일 load가 완료되었다는 메시지를 띄운다.
243+
// 6. 파일 load가 완료되었다는 메시지를 띄운다.
255244
if (loadResult) {
256245
Alert successAlert = new Alert(AlertType.INFORMATION);
257246
successAlert.setHeaderText("설정파일 불러오기");
@@ -268,6 +257,11 @@ private void loadSelectedConfigFile(String absoluteFilePath) {
268257
}
269258
}
270259

260+
/**
261+
* [설정] - [모니터링 여부 설정] - 모니터링 여부 설정파일을 불러온다.
262+
*
263+
* @param filePath
264+
*/
271265
private void loadMonitoringConfigFile(String filePath) {
272266
monitoringElementsVBox.getChildren().clear();
273267
dbMonitorings = propertyRepository.getDBMonitoringContents();
@@ -479,10 +473,18 @@ private void createSettingDynamicElements() {
479473
connInfoVBox.getChildren().add(dbConnVBox);
480474
}
481475

482-
for (JdbcConnectionInfo jdbc : jdbcConnInfoList) {
476+
if (jdbcConnInfoList.size() == 0) {
483477
DBConnectionInfoAnchorPane dbConnAP = new DBConnectionInfoAnchorPane();
484-
dbConnAP.setInitialValue(jdbc);
478+
dbConnAP.init();
479+
dbConnAP.setInitialValue(new JdbcConnectionInfo());
485480
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+
}
486488
}
487489

488490
ConnectionInfoVBox serverConnVBox = null;
@@ -496,11 +498,17 @@ private void createSettingDynamicElements() {
496498
serverConnVBox.setId("serverConnVBox");
497499
connInfoVBox.getChildren().add(serverConnVBox);
498500
}
499-
500-
for (JschConnectionInfo jsch : jschConnInfoList) {
501+
502+
if (jschConnInfoList.size() == 0) {
501503
ServerConnectionInfoAnchorPane serverConnAP = new ServerConnectionInfoAnchorPane();
502-
serverConnAP.setInitialValue(jsch);
504+
serverConnAP.setInitialValue(new JschConnectionInfo());
503505
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+
}
504512
}
505513

506514
// [설정] - [모니터링 여부 설정]
@@ -529,11 +537,11 @@ private void reloadingMonitoringSetting(String presetName) {
529537
monitoringPresetComboBox.getItems().addAll(monitoringPresetMap.keySet());
530538
logger.debug("monitoringPresetMap : " + monitoringPresetMap);
531539

532-
// 지정된 Preset이 없다면 최근 사용된 Preset으로 세팅한다. 만약 최근 사용된 Preset이 없다면 첫번째 Preset으로
533-
// 세팅한다.
540+
// 지정된 Preset이 없다면 최근 사용된 Preset으로 세팅한다.
541+
// 만약 최근 사용된 Preset이 없다면 첫번째 Preset으로 세팅한다.
534542
if (presetName.isEmpty()) {
535543
// 최근 사용된 모니터링 설정 읽기
536-
if (lastUsePresetName.isEmpty() && monitoringPresetComboBox.getItems().size() != 0) {
544+
if (StringUtils.isEmpty(lastUsePresetName) && monitoringPresetComboBox.getItems().size() != 0) {
537545
// 최근 사용된 설정이 없다면, 첫번째 설정 읽기
538546
readPresetName = monitoringPresetComboBox.getItems().get(0);
539547
logger.debug("첫번째 Preset: " + readPresetName);
@@ -550,9 +558,69 @@ private void reloadingMonitoringSetting(String presetName) {
550558
logger.debug("readPresetFilePath : " + readPresetFilePath);
551559

552560
// ComboBox 선택 및 Preset 파일 읽기
553-
if (!readPresetName.isEmpty()) {
561+
if (!StringUtils.isEmpty(readPresetName)) {
554562
monitoringPresetComboBox.getSelectionModel().select(readPresetName);
555563
loadMonitoringConfigFile(monitoringPresetMap.get(readPresetName));
556564
}
557565
}
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+
}
558626
}

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

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
1313
import javafx.scene.control.PasswordField;
1414
import javafx.scene.control.TextField;
1515
import javafx.scene.layout.AnchorPane;
16-
import lombok.Data;
17-
import lombok.EqualsAndHashCode;
1816
import root.core.domain.JdbcConnectionInfo;
1917
import root.core.repository.constracts.PropertyRepository;
2018
import root.core.repository.implement.PropertyRepositoryImpl;
2119

22-
@EqualsAndHashCode(callSuper = false)
23-
@Data
2420
public class DBConnectionInfoAnchorPane extends AnchorPane {
2521

2622
/* Dependency Injection */
@@ -62,27 +58,19 @@ public DBConnectionInfoAnchorPane() {
6258
}
6359
}
6460

65-
public void setInitialValue(JdbcConnectionInfo jdbc) {
61+
public void init() {
6662
driverCB.getItems().addAll(propertyRepository.getOracleDrivers());
6763

68-
hostTF.setText(jdbc.getJdbcHost());
69-
sidTF.setText(jdbc.getJdbcSID());
70-
userTF.setText(jdbc.getJdbcId());
71-
passwordPF.setText(jdbc.getJdbcPw());
72-
urlTF.setText(jdbc.getJdbcUrl());
73-
portTF.setText(jdbc.getJdbcPort());
74-
driverCB.getSelectionModel().select(jdbc.getJdbcOracleDriver());
75-
aliasTF.setText(jdbc.getJdbcDBName());
76-
7764
// DB Url Generate Event Setting
7865
String dbms = "oracle";
7966
DBUrlGenerateEvent urlEvent = new DBUrlGenerateEvent(dbms);
8067

81-
driverCB.setOnInputMethodTextChanged(urlEvent);
68+
driverCB.getSelectionModel().selectedItemProperty().addListener((options, oldValue, newValue) -> {
69+
urlEvent.handle(null);
70+
});
8271
hostTF.setOnKeyReleased(urlEvent);
8372
portTF.setOnKeyReleased(urlEvent);
8473
sidTF.setOnKeyReleased(urlEvent);
85-
8674
urlTF.setOnKeyReleased(s -> {
8775
String text = ((TextField) s.getSource()).getText();
8876
Pattern p = Pattern
@@ -98,6 +86,18 @@ public void setInitialValue(JdbcConnectionInfo jdbc) {
9886
});
9987
}
10088

89+
public void setInitialValue(JdbcConnectionInfo jdbc) {
90+
hostTF.setText(jdbc.getJdbcHost());
91+
sidTF.setText(jdbc.getJdbcSID());
92+
userTF.setText(jdbc.getJdbcId());
93+
passwordPF.setText(jdbc.getJdbcPw());
94+
urlTF.setText(jdbc.getJdbcUrl());
95+
portTF.setText(jdbc.getJdbcPort());
96+
// TODO
97+
driverCB.getSelectionModel().select("thin");
98+
aliasTF.setText(jdbc.getJdbcDBName());
99+
}
100+
101101
public JdbcConnectionInfo getInputValues() {
102102
JdbcConnectionInfo jdbc = new JdbcConnectionInfo();
103103
jdbc.setJdbcDBName(this.aliasTF.getText());
@@ -131,8 +131,10 @@ public DBUrlGenerateEvent(String dbms) {
131131
public void handle(Event event) {
132132
StringBuffer url = new StringBuffer();
133133
url.append("jdbc:").append(dbms).append(":").append(driverCB.getSelectionModel().getSelectedItem())
134-
.append(":@").append(hostTF.getText()).append(":").append(portTF.getText()).append("/")
135-
.append(sidTF.getText());
134+
.append(":@")
135+
.append(hostTF.getText() == null ? "" : hostTF.getText()).append(":")
136+
.append(portTF.getText() == null ? "" : portTF.getText()).append("/")
137+
.append(sidTF.getText() == null ? "" : sidTF.getText());
136138

137139
urlTF.setText(url.toString());
138140
}

0 commit comments

Comments
 (0)