Add checks on station name when editing
This commit is contained in:
parent
53d6132ecd
commit
fa0130b4b4
@ -8,6 +8,7 @@ import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.Random;
|
||||
@ -67,6 +68,7 @@ public class MainController implements Initializable {
|
||||
return;
|
||||
}
|
||||
controller.setStationSettings(selectedStation);
|
||||
controller.setStationNameList(settings.getStations().stream().map(StationSettings::toString).toList());
|
||||
|
||||
settingsStage = new Stage();
|
||||
settingsStage.initModality(Modality.APPLICATION_MODAL);
|
||||
|
@ -13,6 +13,8 @@ import java.io.IOException;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.Optional;
|
||||
@ -30,6 +32,7 @@ import javafx.collections.ObservableList;
|
||||
import javafx.event.Event;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.DatePicker;
|
||||
@ -74,6 +77,8 @@ public class StationSettingsController {
|
||||
private StringProperty scheduleStartTime = new SimpleStringProperty();
|
||||
private StringProperty username = new SimpleStringProperty();
|
||||
|
||||
private ArrayList<String> stationNames = new ArrayList<String>();
|
||||
|
||||
@FXML
|
||||
private Label connectionTestStatusLabel;
|
||||
|
||||
@ -390,6 +395,28 @@ public class StationSettingsController {
|
||||
|
||||
@FXML
|
||||
private void handleSaveButtonPress(Event e) {
|
||||
if (stationName.get() == null || stationName.get().equals("")) {
|
||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||
alert.setTitle("Invalid station name");
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText("Station name must not be empty");
|
||||
alert.showAndWait();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!stationName.get().toLowerCase().equals(settings.getName().toLowerCase())) {
|
||||
for (String otherStationName : stationNames) {
|
||||
if (stationName.get().toLowerCase().equals(otherStationName.toLowerCase())) {
|
||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||
alert.setTitle("Invalid station name");
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText("Station name '" + stationName.get() + "' is already used.");
|
||||
alert.showAndWait();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
settings.setAddress(stationAddress.get());
|
||||
settings.setDigitsPerGroup(digitsPerGroup.get());
|
||||
settings.setExternalProgramCommand(externalProgramCommand.get());
|
||||
@ -419,6 +446,7 @@ public class StationSettingsController {
|
||||
logger.log(Level.SEVERE, "Unsupported OS " + osName);
|
||||
} else {
|
||||
logger.log(Level.SEVERE, "Unsupported OS " + osName);
|
||||
// TODO: Alert
|
||||
}
|
||||
|
||||
Node node = (Node) e.getSource();
|
||||
@ -483,6 +511,11 @@ public class StationSettingsController {
|
||||
return stationAddress;
|
||||
}
|
||||
|
||||
public void setStationNameList(List<String> newStationNames) {
|
||||
stationNames.clear();
|
||||
stationNames.addAll(newStationNames);
|
||||
}
|
||||
|
||||
public void setStationSettings(StationSettings newSettings) {
|
||||
settings = newSettings;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user