22
33import java .io .File ;
44import java .net .URL ;
5- import java .util .ArrayList ;
6- import java .util .Arrays ;
75import java .util .HashMap ;
86import java .util .List ;
97import java .util .Map ;
108import java .util .Optional ;
119import java .util .ResourceBundle ;
12- import java .util .Set ;
13- import java .util .regex .Matcher ;
1410import java .util .regex .Pattern ;
1511
1612import org .apache .commons .configuration2 .PropertiesConfiguration ;
3329import javafx .scene .control .ButtonBar .ButtonData ;
3430import javafx .scene .control .ButtonType ;
3531import javafx .scene .control .Label ;
36- import javafx .scene .control .PasswordField ;
3732import javafx .scene .control .Separator ;
3833import javafx .scene .control .SplitPane ;
3934import javafx .scene .control .TextField ;
@@ -63,9 +58,11 @@ public class SettingMenuController implements Initializable {
6358 private static Logger logger = Logger .getLogger (SettingMenuController .class );
6459
6560 /**
66- * Pattern 객체를 정적필드로 선언한 이유 - Pattern 객체는 입력받은 정규표현식에 해당하는 유한상태머신(finite state
67- * machine)을 생성하기 때문에 인스턴스 생성비용이 높다. - 따라서, 한 번 생성하두고 이를 재사용하는 것이 효과적이다. - 뿐만
68- * 아니라, 패턴 객체에 이름을 부여하여 해당 객체의 의미가 명확해진다.
61+ * Pattern 객체를 정적필드로 선언한 이유
62+ * - Pattern 객체는 입력받은 정규표현식에 해당하는 유한상태머신(finite statemachine)을
63+ * 생성하기 때문에 인스턴스 생성비용이 높다.
64+ * - 따라서, 한 번 생성하두고 이를 재사용하는 것이 효과적이다.
65+ * - 뿐만 아니라, 패턴 객체에 이름을 부여하여 해당 객체의 의미가 명확해진다.
6966 */
7067 private static Pattern DB_CONNINFO_AP_NAME_PATTERN = Pattern .compile ("dbConnInfo(.*)AP" );
7168 private static Pattern SERVER_CONNINFO_AP_NAME_PATTERN = Pattern .compile ("serverConnInfo(.*)AP" );
@@ -101,29 +98,17 @@ public class SettingMenuController implements Initializable {
10198 @ FXML
10299 JFXComboBox <String > monitoringPresetComboBox ; // 모니터링여부 설정 Preset ComboBox
103100
104- @ FXML
105- JFXButton dbConnTestBtn ;
106-
107101 /* Common Data */
108102 String [] dbMonitorings ;
109103 String [] serverMonitorings ;
110104
111105 String [] dbNames ;
112106 String [] serverNames ;
113107
114- // dbConnInfo
115108 List <JdbcConnectionInfo > jdbcConnInfoList ;
116109 List <JschConnectionInfo > jschConnInfoList ;
117110 Map <String , AlertLogCommand > alcMap ;
118111
119- // dbConnInfo Index 배열
120- Map <Integer , AnchorPane > dbConnInfoIdxMap = new HashMap <>();
121- int dbConnInfoIdx = 0 ;
122-
123- // serverConnInfo Index 배열
124- Map <Integer , AnchorPane > serverConnInfoIdxMap = new HashMap <>();
125- int serverConnInfoIdx = 0 ;
126-
127112 Map <String , String > monitoringPresetMap = new HashMap <>();
128113
129114 // 모니터링 여부 설정 Preset Popup
@@ -253,10 +238,6 @@ private void loadSelectedConfigFile(String absoluteFilePath) {
253238 // 3. 프로퍼티파일에 작성된 내용에 따라 동적 요소를 생성한다.
254239 createSettingDynamicElements ();
255240
256- // 4. 첫번째 접속정보를 맨 앞으로 가져온다.
257- // bringFrontConnInfoAnchorPane(dbConnInfoIdxMap, 0, dbInfoCntText);
258- // bringFrontConnInfoAnchorPane(serverConnInfoIdxMap, 0, serverInfoCntText);
259-
260241 // 5. remember.properties 파일에 최근 사용된 설정파일 경로를 저장한다.
261242 PropertiesConfiguration rememberConfig = propertyRepository .getConfiguration ("rememberConfig" );
262243 rememberConfig .setProperty ("filepath.config.lastuse" , filePath .replace ("\\ " , "/" ));
@@ -312,97 +293,8 @@ public void saveConnInfoSettings(ActionEvent e) {
312293 String configFilePath = fileChooserText .getText ();
313294 PropertiesConfiguration config = PropertiesUtils .connInfoConfig ;
314295
315- /*
316- * DB 접속정보 StackPane에서 얻어내야 할 데이터
317- *
318- * (TextField) {dbName}HostTextField {dbName}.jdbc.host (TextField)
319- * {dbName}PortTextField {dbName}.jdbc.port (TextField) {dbName}SIDTextField
320- * {dbName} (TextField) {dbName}UrlTextField {dbName}.jdbc.url (TextField)
321- * {dbName}AliasTextField {dbName}.jdbc.alias (TextField) {dbName}UserTextField
322- * {dbName}.jdbc.id (PasswordField) {dbName}PasswordTextField {dbName}.jdbc.pw
323- * (JFXComboBox) {dbName}DriverComboBox {dbName}.jdbc.driver
324- */
325-
326- List <String > dbNames = new ArrayList <String >(Arrays .asList (propertyRepository .getMonitoringDBNames ()));
327- for (AnchorPane ap : dbConnInfoIdxMap .values ()) {
328- String apId = ap .getId ();
329-
330- Matcher m = DB_CONNINFO_AP_NAME_PATTERN .matcher (apId );
331- if (m .matches ()) {
332- String elementId = m .group (1 );
333- String newElementId = elementId ;
334- boolean isNewConnInfo = false ;
335-
336- // 새로 추가된 접속정보
337- if (!dbNames .contains (elementId )) {
338- Set <Node > textFields = ap .lookupAll ("TextField" );
339- for (Node n : textFields ) {
340- if (((TextField ) n ).getId ().equals (elementId + "AliasTextField" )) {
341- isNewConnInfo = true ;
342- newElementId = ((TextField ) n ).getText ();
343- logger .debug ("NEW dbName : " + newElementId );
344- break ;
345- }
346- }
347- }
348-
349- String elementIdLower = newElementId .toLowerCase ();
350-
351- // dbNames 추가
352- if (isNewConnInfo ) {
353- dbNames .add (newElementId );
354- config .setProperty ("#DB" , newElementId );
355- config .setProperty (elementIdLower + ".jdbc.validation" , "select 1 from dual" );
356- config .setProperty (elementIdLower + ".jdbc.connections" , 10 );
357- }
358-
359- // TextField Value Update
360- Set <Node > textFields = ap .lookupAll ("TextField" );
361- for (Node n : textFields ) {
362- TextField tf = (TextField ) n ;
363- String tfId = tf .getId ();
364- String tfText = tf .getText ();
365-
366- if (tfId .equals (elementId + "UserTextField" )) {
367- config .setProperty (elementIdLower + ".jdbc.id" , tfText );
368- } else if (tfId .equals (elementId + "UrlTextField" )) {
369- config .setProperty (elementIdLower + ".jdbc.url" , tfText );
370- } else if (tfId .equals (elementId + "AliasTextField" )) {
371- config .setProperty (elementIdLower + ".jdbc.alias" , tfText );
372- }
373- }
374-
375- // PasswordField Value Update
376- Set <Node > passwordFields = ap .lookupAll ("PasswordField" );
377- for (Node n : passwordFields ) {
378- PasswordField pf = (PasswordField ) n ;
379- String pfId = pf .getId ();
380- String pfText = pf .getText ();
381-
382- if (pfId .equals (elementId + "PasswordTextField" )) {
383- config .setProperty (elementIdLower + ".jdbc.pw" , pfText );
384- }
385- }
386-
387- // JFXComboBox Value Update
388- Set <Node > comboBoxs = ap .lookupAll ("JFXComboBox" );
389- for (Node n : comboBoxs ) {
390- @ SuppressWarnings ("unchecked" )
391- JFXComboBox <String > cb = (JFXComboBox <String >) n ;
392- String cbId = cb .getId ();
393- String cbSelectedItem = cb .getSelectionModel ().getSelectedItem ();
394-
395- if (cbId .equals (elementId + "DriverComboBox" )) {
396- if (cbSelectedItem .equals ("thin" )) {
397- // TODO 선택된 Oracle Driver Type에 따라서, Driver 값 변경하기, 현재는 임시로 모두 동일한 값 입력
398- config .setProperty (elementIdLower + ".jdbc.driver" , "oracle.jdbc.driver.OracleDriver" );
399- }
400- }
401- }
402- }
403- }
404- // dbNames Update
405- config .setProperty ("dbnames" , dbNames );
296+ ConnectionInfoVBox dbConnVBox = (ConnectionInfoVBox ) connInfoVBox .lookup ("#dbConnVBox" );
297+ dbConnVBox .saveConnInfoSettings ("configFilePath" );
406298
407299 /*
408300 * 서버 접속정보 StackPane에서 얻어내야 할 데이터
@@ -416,8 +308,11 @@ public void saveConnInfoSettings(ActionEvent e) {
416308 * (JFXComboBox) {ServerName}AlertLogDateFormatComboBox
417309 * {ServerName}.server.alertlog.dateformat
418310 */
311+
312+ /*
419313 List<String> serverNames = new ArrayList<String>(Arrays.asList(config.getStringArray("servernames")));
420- for (AnchorPane ap : serverConnInfoIdxMap .values ()) {
314+ ConnectionInfoVBox serverConnVBox = (ConnectionInfoVBox) connInfoVBox.lookup("#serverConnVBox");
315+ for (AnchorPane ap : serverConnVBox.getConnInfoAPMap().values()) {
421316 String apId = ap.getId();
422317
423318 Matcher m = SERVER_CONNINFO_AP_NAME_PATTERN.matcher(apId);
@@ -503,7 +398,8 @@ public void saveConnInfoSettings(ActionEvent e) {
503398 }
504399 // ServerNames Update
505400 config.setProperty("servernames", serverNames);
506-
401+ */
402+
507403 // 변경사항 저장
508404 propertyRepository .save (configFilePath , config );
509405 // 설정파일 ReLoading
@@ -678,6 +574,7 @@ private void createSettingDynamicElements() {
678574 // DB 접속정보 UI
679575 ConnectionInfoVBox dbConnVBox = new ConnectionInfoVBox (DBConnectionInfoAnchorPane .class );
680576 dbConnVBox .setMenuTitle ("DB 접속정보" , FontAwesomeIcon .DATABASE );
577+ dbConnVBox .setId ("dbConnVBox" );
681578 connInfoVBox .getChildren ().add (dbConnVBox );
682579
683580 for (JdbcConnectionInfo jdbc : jdbcConnInfoList ) {
@@ -689,6 +586,7 @@ private void createSettingDynamicElements() {
689586 // Server 접속정보 UI
690587 ConnectionInfoVBox serverConnVBox = new ConnectionInfoVBox (ServerConnectionInfoAnchorPane .class );
691588 serverConnVBox .setMenuTitle ("서버 접속정보" , FontAwesomeIcon .SERVER );
589+ serverConnVBox .setId ("serverConnVBox" );
692590 connInfoVBox .getChildren ().add (serverConnVBox );
693591
694592 for (JschConnectionInfo jsch : jschConnInfoList ) {
0 commit comments