Add checks on station name when adding

This commit is contained in:
Nathan McRae 2025-02-08 13:52:51 -08:00
parent c0028b2978
commit 53d6132ecd

View File

@ -5,6 +5,7 @@ import javafx.collections.ListChangeListener;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.TextInputDialog;
@ -58,6 +59,26 @@ public class StationSelectionController {
Optional<String> result = dialog.showAndWait();
result.ifPresent(stationName -> {
if (stationName == null || stationName.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;
}
for (StationSettings station : stationList) {
if (stationName.toLowerCase().equals(station.getName().toLowerCase())) {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Invalid station name");
alert.setHeaderText(null);
alert.setContentText("Station name '" + stationName + "' is already used.");
alert.showAndWait();
return;
}
}
StationSettings newStation = new StationSettings(stationName);
stationList.add(newStation);
});