corefx added FileConfigItem back in for dynamic config dialogs

This commit is contained in:
Blake J. Harnden 2018-10-16 10:08:19 -07:00
parent 8d610c99e9
commit 24157e7be5
6 changed files with 80 additions and 19 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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