From 24157e7be514637cf6f59d08331c034793aad972 Mon Sep 17 00:00:00 2001 From: "Blake J. Harnden" Date: Tue, 16 Oct 2018 10:08:19 -0700 Subject: [PATCH] corefx added FileConfigItem back in for dynamic config dialogs --- .../com/core/ui/config/BaseConfigItem.java | 5 +- .../com/core/ui/config/BooleanConfigItem.java | 5 +- .../com/core/ui/config/ConfigItemUtils.java | 23 ++++---- .../com/core/ui/config/DefaultConfigItem.java | 5 +- .../com/core/ui/config/FileConfigItem.java | 56 +++++++++++++++++++ .../com/core/ui/config/SelectConfigItem.java | 5 +- 6 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 corefx/src/main/java/com/core/ui/config/FileConfigItem.java diff --git a/corefx/src/main/java/com/core/ui/config/BaseConfigItem.java b/corefx/src/main/java/com/core/ui/config/BaseConfigItem.java index 1a9deb29..90929c30 100644 --- a/corefx/src/main/java/com/core/ui/config/BaseConfigItem.java +++ b/corefx/src/main/java/com/core/ui/config/BaseConfigItem.java @@ -2,14 +2,17 @@ package com.core.ui.config; import com.core.client.rest.ConfigOption; import javafx.scene.control.Label; +import javafx.stage.Stage; import lombok.Data; @Data public abstract class BaseConfigItem implements IConfigItem { + private final Stage stage; private final Label label; private final ConfigOption option; - public BaseConfigItem(ConfigOption option) { + public BaseConfigItem(Stage stage, ConfigOption option) { + this.stage = stage; this.option = option; this.label = new Label(option.getLabel()); } diff --git a/corefx/src/main/java/com/core/ui/config/BooleanConfigItem.java b/corefx/src/main/java/com/core/ui/config/BooleanConfigItem.java index 817ea7f0..dcc6c196 100644 --- a/corefx/src/main/java/com/core/ui/config/BooleanConfigItem.java +++ b/corefx/src/main/java/com/core/ui/config/BooleanConfigItem.java @@ -3,12 +3,13 @@ package com.core.ui.config; import com.core.client.rest.ConfigOption; import com.jfoenix.controls.JFXToggleButton; import javafx.scene.Node; +import javafx.stage.Stage; public class BooleanConfigItem extends BaseConfigItem { private JFXToggleButton button = new JFXToggleButton(); - public BooleanConfigItem(ConfigOption option) { - super(option); + public BooleanConfigItem(Stage stage, ConfigOption option) { + super(stage, option); button.setMaxWidth(Double.MAX_VALUE); if ("1".equals(option.getValue())) { button.setSelected(true); diff --git a/corefx/src/main/java/com/core/ui/config/ConfigItemUtils.java b/corefx/src/main/java/com/core/ui/config/ConfigItemUtils.java index 9a30b6ba..dcba2a9c 100644 --- a/corefx/src/main/java/com/core/ui/config/ConfigItemUtils.java +++ b/corefx/src/main/java/com/core/ui/config/ConfigItemUtils.java @@ -10,19 +10,18 @@ public final class ConfigItemUtils { } public static IConfigItem get(Stage stage, ConfigOption option) { - IConfigItem configItem = null; + IConfigItem configItem; ConfigDataType dataType = ConfigDataType.get(option.getType()); - switch (dataType) { - case BOOL: - configItem = new BooleanConfigItem(option); - break; - default: - if (!option.getSelect().isEmpty()) { - configItem = new SelectConfigItem(option); - } else { - configItem = new DefaultConfigItem(option); - } - break; + if (dataType == ConfigDataType.BOOL) { + configItem = new BooleanConfigItem(stage, option); + } else { + if (!option.getSelect().isEmpty()) { + configItem = new SelectConfigItem(stage, option); + } else if (option.getLabel().endsWith(" file")) { + configItem = new FileConfigItem(stage, option); + } else { + configItem = new DefaultConfigItem(stage, option); + } } return configItem; diff --git a/corefx/src/main/java/com/core/ui/config/DefaultConfigItem.java b/corefx/src/main/java/com/core/ui/config/DefaultConfigItem.java index bfde9b90..06f799d4 100644 --- a/corefx/src/main/java/com/core/ui/config/DefaultConfigItem.java +++ b/corefx/src/main/java/com/core/ui/config/DefaultConfigItem.java @@ -3,12 +3,13 @@ package com.core.ui.config; import com.core.client.rest.ConfigOption; import com.jfoenix.controls.JFXTextField; import javafx.scene.Node; +import javafx.stage.Stage; public class DefaultConfigItem extends BaseConfigItem { private JFXTextField textField; - public DefaultConfigItem(ConfigOption option) { - super(option); + public DefaultConfigItem(Stage stage, ConfigOption option) { + super(stage, option); textField = new JFXTextField(option.getValue()); textField.setMaxWidth(Double.MAX_VALUE); textField.textProperty().addListener(((observable, oldValue, newValue) -> { diff --git a/corefx/src/main/java/com/core/ui/config/FileConfigItem.java b/corefx/src/main/java/com/core/ui/config/FileConfigItem.java new file mode 100644 index 00000000..aa733faa --- /dev/null +++ b/corefx/src/main/java/com/core/ui/config/FileConfigItem.java @@ -0,0 +1,56 @@ +package com.core.ui.config; + +import com.core.client.rest.ConfigOption; +import com.jfoenix.controls.JFXButton; +import com.jfoenix.controls.JFXTextField; +import javafx.scene.Node; +import javafx.scene.layout.ColumnConstraints; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Priority; +import javafx.scene.layout.RowConstraints; +import javafx.stage.FileChooser; +import javafx.stage.Stage; + +import java.io.File; + +public class FileConfigItem extends BaseConfigItem { + private GridPane gridPane; + + public FileConfigItem(Stage stage, ConfigOption option) { + super(stage, option); + gridPane = new GridPane(); + gridPane.setHgap(5); + gridPane.setMaxWidth(Double.MAX_VALUE); + RowConstraints rowConstraints = new RowConstraints(); + rowConstraints.setVgrow(Priority.SOMETIMES); + ColumnConstraints textFieldConstraints = new ColumnConstraints(); + textFieldConstraints.setHgrow(Priority.SOMETIMES); + textFieldConstraints.setPercentWidth(60); + ColumnConstraints buttonConstraints = new ColumnConstraints(); + buttonConstraints.setHgrow(Priority.SOMETIMES); + buttonConstraints.setPercentWidth(40); + gridPane.getColumnConstraints().addAll(textFieldConstraints, buttonConstraints); + + JFXTextField textField = new JFXTextField(); + textField.setMaxWidth(Double.MAX_VALUE); + textField.textProperty().addListener(((observable, oldValue, newValue) -> getOption().setValue(newValue))); + JFXButton button = new JFXButton("Select File"); + button.getStyleClass().add("core-button"); + button.setMaxWidth(Double.MAX_VALUE); + button.setOnAction(event -> { + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle("Select File"); + fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); + File file = fileChooser.showOpenDialog(stage); + if (file != null) { + textField.setText(file.getPath()); + } + }); + gridPane.addRow(0, textField, button); + } + + @Override + public Node getNode() { + return gridPane; + } +} diff --git a/corefx/src/main/java/com/core/ui/config/SelectConfigItem.java b/corefx/src/main/java/com/core/ui/config/SelectConfigItem.java index d61fe194..af3915d3 100644 --- a/corefx/src/main/java/com/core/ui/config/SelectConfigItem.java +++ b/corefx/src/main/java/com/core/ui/config/SelectConfigItem.java @@ -3,12 +3,13 @@ package com.core.ui.config; import com.core.client.rest.ConfigOption; import com.jfoenix.controls.JFXComboBox; import javafx.scene.Node; +import javafx.stage.Stage; public class SelectConfigItem extends BaseConfigItem { private JFXComboBox comboBox = new JFXComboBox<>(); - public SelectConfigItem(ConfigOption option) { - super(option); + public SelectConfigItem(Stage stage, ConfigOption option) { + super(stage, option); comboBox.setMaxWidth(Double.MAX_VALUE); comboBox.getItems().addAll(option.getSelect()); comboBox.getSelectionModel().select(option.getValue());