107 lines
3.6 KiB
Java
107 lines
3.6 KiB
Java
package de.opcua.app.ui;
|
|
|
|
import de.opcua.app.config.Settings;
|
|
import javafx.event.ActionEvent;
|
|
import javafx.fxml.FXML;
|
|
import javafx.scene.control.CheckBox;
|
|
import javafx.scene.control.ComboBox;
|
|
import javafx.scene.control.PasswordField;
|
|
import javafx.scene.control.TextField;
|
|
import javafx.stage.FileChooser;
|
|
|
|
import java.io.File;
|
|
import java.util.Optional;
|
|
|
|
public class ConfigController {
|
|
|
|
@FXML private TextField endpointTextBox;
|
|
@FXML private TextField hostTextBox;
|
|
|
|
// HTTP Configuration
|
|
@FXML private CheckBox httpEnabledCheckBox;
|
|
@FXML private TextField httpPortTextBox;
|
|
|
|
// HTTPS Configuration
|
|
@FXML private CheckBox httpsEnabledCheckBox;
|
|
@FXML private TextField httpsPortTextBox;
|
|
@FXML private TextField keystorePathTextBox;
|
|
@FXML private PasswordField keystorePasswordTextBox;
|
|
@FXML private ComboBox<String> keystoreTypeComboBox;
|
|
|
|
private Settings initial;
|
|
private Settings updated;
|
|
|
|
public void setSettings(Settings s) {
|
|
this.initial = s;
|
|
if (endpointTextBox != null) endpointTextBox.setText(s.endpoint());
|
|
if (hostTextBox != null) hostTextBox.setText(s.host());
|
|
|
|
// HTTP fields
|
|
if (httpEnabledCheckBox != null) httpEnabledCheckBox.setSelected(s.httpEnabled());
|
|
if (httpPortTextBox != null) httpPortTextBox.setText(String.valueOf(s.httpPort()));
|
|
|
|
// HTTPS fields
|
|
if (httpsEnabledCheckBox != null) httpsEnabledCheckBox.setSelected(s.httpsEnabled());
|
|
if (httpsPortTextBox != null) httpsPortTextBox.setText(String.valueOf(s.httpsPort()));
|
|
if (keystorePathTextBox != null) keystorePathTextBox.setText(s.keystorePath());
|
|
if (keystorePasswordTextBox != null) keystorePasswordTextBox.setText(s.keystorePassword());
|
|
if (keystoreTypeComboBox != null) keystoreTypeComboBox.setValue(s.keystoreType());
|
|
}
|
|
|
|
@FXML
|
|
public void initialize() {
|
|
// Initialize ComboBox items if present
|
|
if (keystoreTypeComboBox != null) {
|
|
keystoreTypeComboBox.getItems().addAll("JKS", "PKCS12");
|
|
keystoreTypeComboBox.setValue("JKS");
|
|
}
|
|
}
|
|
|
|
@FXML
|
|
public void SaveButton_Click(ActionEvent e) {
|
|
try {
|
|
int httpPort = Integer.parseInt(httpPortTextBox.getText());
|
|
int httpsPort = Integer.parseInt(httpsPortTextBox.getText());
|
|
|
|
updated = new Settings(
|
|
endpointTextBox.getText(),
|
|
hostTextBox.getText(),
|
|
httpEnabledCheckBox != null && httpEnabledCheckBox.isSelected(),
|
|
httpPort,
|
|
httpsEnabledCheckBox != null && httpsEnabledCheckBox.isSelected(),
|
|
httpsPort,
|
|
keystorePathTextBox != null ? keystorePathTextBox.getText() : "",
|
|
keystorePasswordTextBox != null ? keystorePasswordTextBox.getText() : "",
|
|
keystoreTypeComboBox != null ? keystoreTypeComboBox.getValue() : "JKS",
|
|
initial.scriptLoggingEnabled(),
|
|
initial.scriptLogLevel(),
|
|
initial.scriptLogDirectory()
|
|
);
|
|
|
|
// Close window
|
|
endpointTextBox.getScene().getWindow().hide();
|
|
} catch (NumberFormatException ex) {
|
|
System.err.println("Invalid port number: " + ex.getMessage());
|
|
}
|
|
}
|
|
|
|
@FXML
|
|
public void BrowseKeystore_Click(ActionEvent e) {
|
|
FileChooser fc = new FileChooser();
|
|
fc.setTitle("Select Keystore");
|
|
fc.getExtensionFilters().addAll(
|
|
new FileChooser.ExtensionFilter("Keystore Files", "*.jks", "*.p12", "*.pfx"),
|
|
new FileChooser.ExtensionFilter("All Files", "*.*")
|
|
);
|
|
|
|
File file = fc.showOpenDialog(keystorePathTextBox.getScene().getWindow());
|
|
if (file != null) {
|
|
keystorePathTextBox.setText(file.getAbsolutePath());
|
|
}
|
|
}
|
|
|
|
public Optional<Settings> getUpdatedSettings() {
|
|
return Optional.ofNullable(updated);
|
|
}
|
|
}
|