1717package de .doubleslash .keeptime .view ;
1818
1919import java .io .File ;
20+ import java .io .FileInputStream ;
2021import java .io .FileOutputStream ;
2122import java .io .IOException ;
2223import java .io .InputStream ;
@@ -166,7 +167,7 @@ public class SettingsController {
166167 private TextField authName ;
167168
168169 @ FXML
169- private PasswordField authPassword1 ;
170+ private PasswordField authPassword ;
170171
171172 private ToggleGroup toggleGroup ;
172173
@@ -185,6 +186,15 @@ public class SettingsController {
185186 @ FXML
186187 private TextField authPort ;
187188
189+ @ FXML
190+ private Label labelPassword ;
191+
192+ @ FXML
193+ private Label labelPort ;
194+
195+ @ FXML
196+ private Label labelUsername ;
197+
188198 private String propertiesFilePath = "application.properties" ;
189199
190200 private static final String GITHUB_PAGE = "https://www.github.com/doubleSlashde/KeepTime" ;
@@ -246,8 +256,41 @@ private void initialize() {
246256 radioApiOff .setToggleGroup (toggleGroup );
247257 radioApiOn .setToggleGroup (toggleGroup );
248258
249- LOG .debug ("saveButton.setOnAction" );
259+ Properties properties = new Properties ();
260+ User user ;
261+ try (FileInputStream input = new FileInputStream (propertiesFilePath )) {
262+ properties .load (input );
263+ String apistatus = properties .getProperty ("api" );
264+ System .err .println (apistatus );
265+
266+ if (apistatus .equals ("ON" )) {
267+ radioApiOn .setSelected (true );
268+ radioApiOff .setSelected (false );
269+ authPort .setText (properties .getProperty ("server.port" ));
270+ authName .setText (properties .getProperty ("authUsername" ));
271+ // labelPort.setDisable(false);
272+ // labelUsername.setDisable(false);
273+ // labelPassword.setDisable(false);
274+ // authPort.setDisable(false);
275+ // authName.setDisable(false);
276+ // authPassword.setDisable(false);
277+ System .err .println ("--------" );
278+ } else if (apistatus .equals ("OFF" )) {
279+ radioApiOn .setSelected (false );
280+ radioApiOff .setSelected (true );
281+ // labelPort.setDisable(true);
282+ // labelUsername.setDisable(true);
283+ // labelPassword.setDisable(true);
284+ // authPort.setDisable(true);
285+ // authName.setDisable(true);
286+ // authPassword.setDisable(true);
287+ System .err .println ("+++++++++" );
288+ }
289+ } catch (IOException e ) {
290+ e .printStackTrace ();
291+ }
250292
293+ LOG .debug ("saveButton.setOnAction" );
251294 saveButton .setOnAction (ae -> {
252295 LOG .info ("Save clicked" );
253296
@@ -586,18 +629,24 @@ private void showLicense(final Licenses license) {
586629 }
587630
588631 private void handleApiOff () {
632+ Map <String , String > propertiesToUpdate = new HashMap <>();
589633 setWebApplicationType ("none" );
634+ propertiesToUpdate .put ("api" , "OFF" );
635+ propertyWrite (propertiesToUpdate );
636+
590637 }
591638
592639 private void handleApiOn () {
593640 username = authName .getText ();
594- password = authPassword1 .getText ();
641+ password = authPassword .getText ();
595642
596643 createAndSaveUser (username , password );
597644
598645 Map <String , String > propertiesToUpdate = new HashMap <>();
599646 propertiesToUpdate .put ("spring.main.web-application-type" , "" );
600647 propertiesToUpdate .put ("server.port" , authPort .getText ());
648+ propertiesToUpdate .put ("api" , "ON" );
649+ propertiesToUpdate .put ("authUsername" , username );
601650
602651 propertyWrite (propertiesToUpdate );
603652 }
0 commit comments