Add checks on station name when adding
This commit is contained in:
parent
c0028b2978
commit
53d6132ecd
@ -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);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user