diff --git a/corefx/src/main/java/com/core/Controller.java b/corefx/src/main/java/com/core/Controller.java index 5418fef6..3f7f1060 100644 --- a/corefx/src/main/java/com/core/Controller.java +++ b/corefx/src/main/java/com/core/Controller.java @@ -191,7 +191,7 @@ public class Controller implements Initializable { private void onOpenXmlAction() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open Session"); - String xmlPath = properties.getProperty(ConfigUtils.CORE_XML_PATH); + String xmlPath = properties.getProperty(ConfigUtils.XML_PATH); fileChooser.setInitialDirectory(new File(xmlPath)); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml")); File file = fileChooser.showOpenDialog(window); @@ -210,7 +210,7 @@ public class Controller implements Initializable { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Save Session"); fileChooser.setInitialFileName("session.xml"); - String xmlPath = properties.getProperty(ConfigUtils.CORE_XML_PATH); + String xmlPath = properties.getProperty(ConfigUtils.XML_PATH); fileChooser.setInitialDirectory(new File(xmlPath)); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml")); File file = fileChooser.showSaveDialog(window); @@ -277,7 +277,7 @@ public class Controller implements Initializable { coreClient = new CoreRestClient(this); coreWebSocket = new CoreWebSocket(this); properties = ConfigUtils.load(); - String coreUrl = properties.getProperty(ConfigUtils.CORE_REST); + String coreUrl = properties.getProperty(ConfigUtils.REST_URL); logger.info("core rest: {}", coreUrl); connectDialog.setCoreUrl(coreUrl); connectToCore(coreUrl); diff --git a/corefx/src/main/java/com/core/ui/dialogs/GuiPreferencesDialog.java b/corefx/src/main/java/com/core/ui/dialogs/GuiPreferencesDialog.java index 0d75a2f7..4c2d3480 100644 --- a/corefx/src/main/java/com/core/ui/dialogs/GuiPreferencesDialog.java +++ b/corefx/src/main/java/com/core/ui/dialogs/GuiPreferencesDialog.java @@ -17,6 +17,7 @@ import java.util.Properties; public class GuiPreferencesDialog extends StageDialog { private static final Logger logger = LogManager.getLogger(); private @FXML JFXTextField xmlFilePathTextField; + private @FXML JFXTextField mobilityFilePathTextField; private @FXML JFXTextField shellCommandTextField; private @FXML JFXButton saveButton; @@ -30,7 +31,8 @@ public class GuiPreferencesDialog extends StageDialog { private EventHandler onSave = event -> { Properties properties = getController().getProperties(); - properties.setProperty(ConfigUtils.CORE_XML_PATH, xmlFilePathTextField.getText()); + properties.setProperty(ConfigUtils.XML_PATH, xmlFilePathTextField.getText()); + properties.setProperty(ConfigUtils.MOBILITY_PATH, mobilityFilePathTextField.getText()); properties.setProperty(ConfigUtils.SHELL_COMMAND, shellCommandTextField.getText()); try { ConfigUtils.save(properties); @@ -43,7 +45,8 @@ public class GuiPreferencesDialog extends StageDialog { public void showDialog() { Properties properties = getController().getProperties(); - xmlFilePathTextField.setText(properties.getProperty(ConfigUtils.CORE_XML_PATH)); + xmlFilePathTextField.setText(properties.getProperty(ConfigUtils.XML_PATH)); + mobilityFilePathTextField.setText(properties.getProperty(ConfigUtils.MOBILITY_PATH)); shellCommandTextField.setText(properties.getProperty(ConfigUtils.SHELL_COMMAND)); show(); } diff --git a/corefx/src/main/java/com/core/ui/dialogs/MobilityDialog.java b/corefx/src/main/java/com/core/ui/dialogs/MobilityDialog.java index c22d3306..d2705702 100644 --- a/corefx/src/main/java/com/core/ui/dialogs/MobilityDialog.java +++ b/corefx/src/main/java/com/core/ui/dialogs/MobilityDialog.java @@ -4,6 +4,7 @@ import com.core.Controller; import com.core.data.CoreNode; import com.core.data.MobilityConfig; import com.core.ui.Toast; +import com.core.utils.ConfigUtils; import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXTextField; import com.jfoenix.controls.JFXToggleButton; @@ -72,7 +73,8 @@ public class MobilityDialog extends StageDialog { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Select File"); - fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); + String mobilityPath = getController().getProperties().getProperty(ConfigUtils.MOBILITY_PATH); + fileChooser.setInitialDirectory(new File(mobilityPath)); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Mobility", "*.mobility")); File file = fileChooser.showOpenDialog(getController().getWindow()); diff --git a/corefx/src/main/java/com/core/utils/ConfigUtils.java b/corefx/src/main/java/com/core/utils/ConfigUtils.java index e357d3c2..48c9d43f 100644 --- a/corefx/src/main/java/com/core/utils/ConfigUtils.java +++ b/corefx/src/main/java/com/core/utils/ConfigUtils.java @@ -14,12 +14,14 @@ import java.util.Properties; public final class ConfigUtils { private static final Logger logger = LogManager.getLogger(); private static final String DEFAULT_CONFIG = "/config.properties"; - private static final Path CORE_HOME = Paths.get(System.getProperty("user.home"), ".core"); - private static final Path CORE_PROPERTIES = Paths.get(CORE_HOME.toString(), "config.properties"); - private static final Path CORE_XML_DIR = Paths.get(CORE_HOME.toString(), "xml"); + private static final Path HOME = Paths.get(System.getProperty("user.home"), ".core"); + private static final Path PROPERTIES_FILE = Paths.get(HOME.toString(), "config.properties"); + private static final Path XML_DIR = Paths.get(HOME.toString(), "xml"); + private static final Path MOBILITY_DIR = Paths.get(HOME.toString(), "mobility"); // config fields - public static final String CORE_REST = "core-rest"; - public static final String CORE_XML_PATH = "xml-path"; + public static final String REST_URL = "core-rest"; + public static final String XML_PATH = "xml-path"; + public static final String MOBILITY_PATH = "mobility-path"; public static final String SHELL_COMMAND = "shell-command"; @@ -28,26 +30,28 @@ public final class ConfigUtils { } public static void save(Properties properties) throws IOException { - properties.store(new FileOutputStream(CORE_PROPERTIES.toFile()), null); + properties.store(new FileOutputStream(PROPERTIES_FILE.toFile()), null); } public static Properties load() { try { - if (!CORE_HOME.toFile().exists()) { + if (!HOME.toFile().exists()) { logger.info("creating core home directory"); - Files.createDirectory(CORE_HOME); - Files.createDirectory(CORE_XML_DIR); + Files.createDirectory(HOME); + Files.createDirectory(XML_DIR); + Files.createDirectory(MOBILITY_DIR); } Properties properties = new Properties(); - if (!CORE_PROPERTIES.toFile().exists()) { + if (!PROPERTIES_FILE.toFile().exists()) { logger.info("creating default configuration"); - Files.copy(ConfigUtils.class.getResourceAsStream(DEFAULT_CONFIG), CORE_PROPERTIES); - properties.load(new FileInputStream(CORE_PROPERTIES.toFile())); - properties.setProperty(CORE_XML_PATH, CORE_XML_DIR.toString()); + Files.copy(ConfigUtils.class.getResourceAsStream(DEFAULT_CONFIG), PROPERTIES_FILE); + properties.load(new FileInputStream(PROPERTIES_FILE.toFile())); + properties.setProperty(XML_PATH, XML_DIR.toString()); + properties.setProperty(MOBILITY_PATH, MOBILITY_DIR.toString()); save(properties); } else { - properties.load(new FileInputStream(CORE_PROPERTIES.toFile())); + properties.load(new FileInputStream(PROPERTIES_FILE.toFile())); } // override values if provided diff --git a/corefx/src/main/resources/fxml/gui_preferences.fxml b/corefx/src/main/resources/fxml/gui_preferences.fxml index ce006bf5..33ba5e57 100644 --- a/corefx/src/main/resources/fxml/gui_preferences.fxml +++ b/corefx/src/main/resources/fxml/gui_preferences.fxml @@ -8,19 +8,21 @@ - + - + - - +