gui - some refactoring for creating dynamic config ui elements
This commit is contained in:
parent
0d4356ae55
commit
d2b459e503
4 changed files with 9 additions and 151 deletions
|
@ -1,127 +0,0 @@
|
|||
package com.core.ui;
|
||||
|
||||
import com.core.client.rest.ConfigOption;
|
||||
import com.core.data.ConfigDataType;
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXComboBox;
|
||||
import com.jfoenix.controls.JFXTextField;
|
||||
import com.jfoenix.controls.JFXToggleButton;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.ColumnConstraints;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Data
|
||||
public class ConfigItem {
|
||||
private final Window window;
|
||||
private ConfigOption option;
|
||||
private Label label;
|
||||
private Node node;
|
||||
|
||||
public ConfigItem(Stage window, ConfigOption option) {
|
||||
this.window = window;
|
||||
this.option = option;
|
||||
label = new Label(option.getLabel());
|
||||
createNode();
|
||||
}
|
||||
|
||||
private void createNode() {
|
||||
ConfigDataType dataType = ConfigDataType.get(option.getType());
|
||||
switch (dataType) {
|
||||
case BOOL:
|
||||
node = booleanConfig();
|
||||
break;
|
||||
default:
|
||||
if (!option.getSelect().isEmpty()) {
|
||||
node = optionsConfig();
|
||||
} else if (option.getLabel().contains("file")) {
|
||||
node = fileConfigItem();
|
||||
} else {
|
||||
node = defaultConfigItem();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public ConfigOption getOption() {
|
||||
String value;
|
||||
ConfigDataType dataType = ConfigDataType.get(option.getType());
|
||||
switch (dataType) {
|
||||
case BOOL:
|
||||
JFXToggleButton button = (JFXToggleButton) node;
|
||||
if (button.isSelected()) {
|
||||
value = "1";
|
||||
} else {
|
||||
value = "0";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!option.getSelect().isEmpty()) {
|
||||
JFXComboBox<String> comboBox = (JFXComboBox<String>) node;
|
||||
value = comboBox.getSelectionModel().getSelectedItem();
|
||||
} else {
|
||||
JFXTextField textField = (JFXTextField) node;
|
||||
value = textField.getText();
|
||||
}
|
||||
break;
|
||||
}
|
||||
option.setValue(value);
|
||||
return option;
|
||||
}
|
||||
|
||||
private GridPane fileConfigItem() {
|
||||
GridPane gridPane = new GridPane();
|
||||
gridPane.setHgap(10);
|
||||
JFXTextField textField = new JFXTextField(option.getValue());
|
||||
textField.setMaxWidth(Double.MAX_VALUE);
|
||||
gridPane.addColumn(0, textField);
|
||||
JFXButton button = new JFXButton("File");
|
||||
button.setMaxWidth(Double.MAX_VALUE);
|
||||
button.getStyleClass().add("core-button");
|
||||
gridPane.addColumn(1, button);
|
||||
ColumnConstraints firstColumn = new ColumnConstraints(10);
|
||||
firstColumn.setPercentWidth(80);
|
||||
ColumnConstraints secondColumn = new ColumnConstraints(10);
|
||||
secondColumn.setPercentWidth(20);
|
||||
gridPane.getColumnConstraints().addAll(firstColumn, secondColumn);
|
||||
button.setOnAction(event -> {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("Select File");
|
||||
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
||||
File file = fileChooser.showOpenDialog(window);
|
||||
if (file != null) {
|
||||
textField.setText(file.getPath());
|
||||
}
|
||||
});
|
||||
return gridPane;
|
||||
}
|
||||
|
||||
private JFXTextField defaultConfigItem() {
|
||||
JFXTextField textField = new JFXTextField(option.getValue());
|
||||
textField.setMaxWidth(Double.MAX_VALUE);
|
||||
return textField;
|
||||
}
|
||||
|
||||
private JFXToggleButton booleanConfig() {
|
||||
JFXToggleButton button = new JFXToggleButton();
|
||||
button.setMaxWidth(Double.MAX_VALUE);
|
||||
if ("1".equals(option.getValue())) {
|
||||
button.setSelected(true);
|
||||
}
|
||||
return button;
|
||||
}
|
||||
|
||||
private JFXComboBox<String> optionsConfig() {
|
||||
JFXComboBox<String> comboBox = new JFXComboBox<>();
|
||||
comboBox.setMaxWidth(Double.MAX_VALUE);
|
||||
comboBox.getItems().addAll(option.getSelect());
|
||||
comboBox.getSelectionModel().select(option.getValue());
|
||||
return comboBox;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.core.ui;
|
|||
|
||||
import com.core.Controller;
|
||||
import com.core.data.NodeType;
|
||||
import com.core.utils.FxmlUtils;
|
||||
import com.core.utils.IconUtils;
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXListView;
|
||||
|
@ -12,7 +13,6 @@ import javafx.application.Platform;
|
|||
import javafx.css.PseudoClass;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ProgressBar;
|
||||
|
@ -54,15 +54,7 @@ public class GraphToolbar extends VBox {
|
|||
|
||||
public GraphToolbar(Controller controller) {
|
||||
this.controller = controller;
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/graph_toolbar.fxml"));
|
||||
loader.setRoot(this);
|
||||
loader.setController(this);
|
||||
|
||||
try {
|
||||
loader.load();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
FxmlUtils.loadRootController(this, "/fxml/graph_toolbar.fxml");
|
||||
|
||||
startIcon = IconUtils.get("play_circle_filled");
|
||||
startIcon.setSize(ICON_SIZE);
|
||||
|
|
|
@ -4,8 +4,8 @@ import com.core.Controller;
|
|||
import com.core.client.rest.ConfigGroup;
|
||||
import com.core.client.rest.ConfigOption;
|
||||
import com.core.client.rest.GetConfig;
|
||||
import com.core.data.CoreNode;
|
||||
import com.core.ui.ConfigItem;
|
||||
import com.core.ui.config.ConfigItemUtils;
|
||||
import com.core.ui.config.IConfigItem;
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXScrollPane;
|
||||
import com.jfoenix.controls.JFXTabPane;
|
||||
|
@ -15,7 +15,6 @@ import javafx.scene.control.ScrollPane;
|
|||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.layout.ColumnConstraints;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
@ -25,11 +24,9 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class ConfigDialog extends StageDialog {
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
private CoreNode coreNode;
|
||||
private List<ConfigItem> configItems = new ArrayList<>();
|
||||
private List<IConfigItem> configItems = new ArrayList<>();
|
||||
private JFXButton saveButton;
|
||||
@FXML private JFXTabPane tabPane;
|
||||
@FXML private HBox buttonBar;
|
||||
|
||||
public ConfigDialog(Controller controller) {
|
||||
super(controller, "/fxml/config_dialog.fxml");
|
||||
|
@ -38,7 +35,7 @@ public class ConfigDialog extends StageDialog {
|
|||
}
|
||||
|
||||
public List<ConfigOption> getOptions() {
|
||||
return configItems.stream().map(ConfigItem::getOption).collect(Collectors.toList());
|
||||
return configItems.stream().map(IConfigItem::getOption).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void showDialog(String title, GetConfig getConfig, Runnable runnable) {
|
||||
|
@ -64,11 +61,10 @@ public class ConfigDialog extends StageDialog {
|
|||
gridPane.setHgap(10);
|
||||
gridPane.setVgap(10);
|
||||
int index = 0;
|
||||
logger.info("tabs: {}", tabPane.getTabs());
|
||||
tabPane.getTabs().add(tab);
|
||||
|
||||
for (ConfigOption option : group.getOptions()) {
|
||||
ConfigItem configItem = new ConfigItem(getStage(), option);
|
||||
IConfigItem configItem = ConfigItemUtils.get(getStage(), option);
|
||||
gridPane.addRow(index, configItem.getLabel(), configItem.getNode());
|
||||
configItems.add(configItem);
|
||||
index += 1;
|
||||
|
|
|
@ -26,15 +26,12 @@ public class HookDialog extends StageDialog {
|
|||
|
||||
public HookDialog(Controller controller) {
|
||||
super(controller, "/fxml/hook_dialog.fxml");
|
||||
|
||||
setTitle("Hook");
|
||||
|
||||
saveButton = createButton("Save");
|
||||
addCancelButton();
|
||||
|
||||
stateCombo.getItems().addAll(
|
||||
Arrays.stream(SessionState.values()).map(Enum::name).sorted().collect(Collectors.toList())
|
||||
);
|
||||
stateCombo.getItems()
|
||||
.addAll(Arrays.stream(SessionState.values()).map(Enum::name).sorted().collect(Collectors.toList()));
|
||||
stateCombo.getSelectionModel().select(SessionState.RUNTIME.name());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue