11package life .jlu .osgi .packagetool .controller ;
22
33
4+ import javafx .beans .property .BooleanProperty ;
5+ import javafx .beans .property .SimpleBooleanProperty ;
46import javafx .event .ActionEvent ;
57import javafx .fxml .FXML ;
68import javafx .scene .control .*;
79import javafx .scene .layout .GridPane ;
810import javafx .stage .FileChooser ;
911import javafx .stage .Stage ;
12+
1013import life .jlu .osgi .packagetool .application .AppPreferences ;
1114import life .jlu .osgi .packagetool .util .StringToIntegerConverter ;
1215
1316import java .io .File ;
17+ import java .nio .file .Files ;
18+ import java .nio .file .Paths ;
1419
1520/**
1621 * Adds the functionality to the preferences.fxml scene.
@@ -36,14 +41,28 @@ public class PreferencesController {
3641 @ FXML
3742 private CheckBox dynamic_include ;
3843
44+ @ FXML
45+ private Button save_btn ;
46+
47+
48+ /* ----------------------------------------------------------------------------------------- */
49+ /* ----- Validation Properties ------------------------------------------------------------- */
50+ /* ----------------------------------------------------------------------------------------- */
51+ private final BooleanProperty valid_path = new SimpleBooleanProperty (false );
52+
3953
4054 /* ----------------------------------------------------------------------------------------- */
4155 /* ----- Initialization -------------------------------------------------------------------- */
4256 /* ----------------------------------------------------------------------------------------- */
4357 @ FXML
4458 public void initialize () {
45- container_path .setText ( AppPreferences .getStringPreference (container_path .getId ()) );
46- container_path .setTooltip ( new Tooltip ("Path to the OSGi Container Distro JAR." ) );
59+ addValidationListener ();
60+ addValidationBinding ();
61+
62+ container_path .setText (
63+ AppPreferences .getStringPreference (container_path .getId ()) );
64+ container_path .setTooltip (
65+ new Tooltip ("Full path to the directory in which the OSGi container distro JAR will be created." ) );
4766
4867 container_host .setText ( AppPreferences .getStringPreference (container_host .getId ()) );
4968 container_host .setTooltip ( new Tooltip ("Either machine name or IP v4/v6 address of the host." ));
@@ -75,6 +94,23 @@ public void initialize() {
7594 task_timeout .getValueFactory ().setValue (AppPreferences .getIntegerPreference (task_timeout .getId ()));
7695 }
7796
97+ private void addValidationListener () {
98+ container_path .textProperty ().addListener (event -> {
99+ valid_path .setValue ( Files .exists (Paths .get (container_path .getText ())) );
100+
101+ if (!valid_path .getValue ()) {
102+ if (!container_path .getStyleClass ().contains ("invalid-pref" ))
103+ container_path .getStyleClass ().add ("invalid-pref" );
104+ } else {
105+ container_path .getStyleClass ().remove ("invalid-pref" );
106+ }
107+ });
108+ }
109+
110+ private void addValidationBinding () {
111+ save_btn .disableProperty ().bind ( valid_path .not () );
112+ }
113+
78114
79115 /* ----------------------------------------------------------------------------------------- */
80116 /* ----- FXML defined actions -------------------------------------------------------------- */
0 commit comments