added mobility directory to user core directory and a configuration option to change it

This commit is contained in:
Blake J. Harnden 2018-11-19 17:15:24 -08:00
parent 12681b6382
commit bee94456e0
5 changed files with 35 additions and 24 deletions

View file

@ -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);

View file

@ -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<ActionEvent> 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();
}

View file

@ -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());

View file

@ -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

View file

@ -8,19 +8,21 @@
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" spacing="10.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TitledPane animated="false" collapsible="false" text="XML">
<TitledPane animated="false" collapsible="false" text="File Paths">
<content>
<VBox spacing="5.0">
<VBox spacing="10.0">
<children>
<Label text="File Path" />
<Label text="Session XML Files" />
<JFXTextField fx:id="xmlFilePathTextField" />
<Label text="Mobility Files" />
<JFXTextField fx:id="mobilityFilePathTextField" />
</children>
</VBox>
</content>
</TitledPane>
<TitledPane animated="false" collapsible="false" text="Programs">
<content>
<VBox spacing="5.0">
<VBox spacing="10.0">
<children>
<Label text="Shell Command" />
<JFXTextField fx:id="shellCommandTextField" />