99import java .util .ResourceBundle ;
1010
1111import org .apache .commons .configuration2 .PropertiesConfiguration ;
12+ import org .apache .commons .lang3 .StringUtils ;
1213import org .apache .log4j .Logger ;
1314
14- import com .jfoenix .controls .JFXButton ;
1515import com .jfoenix .controls .JFXComboBox ;
1616import com .jfoenix .controls .JFXToggleButton ;
1717
2424import javafx .scene .Node ;
2525import javafx .scene .control .Alert ;
2626import javafx .scene .control .Alert .AlertType ;
27- import javafx .scene .control .Button ;
2827import javafx .scene .control .ButtonBar .ButtonData ;
2928import javafx .scene .control .ButtonType ;
3029import javafx .scene .control .Label ;
4140import javafx .scene .text .TextAlignment ;
4241import javafx .stage .FileChooser ;
4342import javafx .stage .FileChooser .ExtensionFilter ;
44- import javafx .stage .Popup ;
4543import javafx .stage .Stage ;
4644import root .core .domain .AlertLogCommand ;
4745import root .core .domain .JdbcConnectionInfo ;
5149import root .javafx .CustomView .ConnectionInfoVBox ;
5250import root .javafx .CustomView .DBConnectionInfoAnchorPane ;
5351import root .javafx .CustomView .ServerConnectionInfoAnchorPane ;
52+ import root .utils .AlertUtils ;
5453import root .utils .PropertiesUtils ;
5554
5655public 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}
0 commit comments