From 55517a531ef4a925f3f368f25c6831c347fc60ee Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Fri, 13 May 2022 16:04:19 +0200 Subject: [PATCH] Create alert popup if user wants to create new game schedule --- .../gameScheduleView/AlertNewSchedule.java | 26 +++++++++++++++++++ .../GameScheduleController.java | 10 +++++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java new file mode 100644 index 0000000..17a823d --- /dev/null +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java @@ -0,0 +1,26 @@ +package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView; + +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonBar; +import javafx.scene.control.ButtonType; + +public class AlertNewSchedule extends Alert { + private ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES); + private ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO); + private boolean result; + + public AlertNewSchedule() { + super(AlertType.WARNING); + setTitle("Neu erstellen"); + setHeaderText("Spielplan neu erstellen?"); + setContentText("Sind Sie sicher, dass Sie den Spielplan neu erstellen moechten?\nAlle Spielfortschritte gehen daraufhin verloren!"); + getButtonTypes().setAll(yesButton,noButton); + } + + public boolean showAndGetResult() { + showAndWait().ifPresent(input -> { + result = input == yesButton; + }); + return result; + } +} diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java index 3c8352e..f6e15a1 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java @@ -1,7 +1,6 @@ package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView; import ch.zhaw.projekt2.turnierverwaltung.FXController; -import ch.zhaw.projekt2.turnierverwaltung.Tournament; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; @@ -30,7 +29,14 @@ public class GameScheduleController extends FXController { @FXML void createNewSchedule(ActionEvent event) { - getTournamentDecorator().createNewGameSchedule(); + if (getTournamentDecorator().getTournament().getGameList().size() > 0) { + AlertNewSchedule alert = new AlertNewSchedule(); + if (alert.showAndGetResult()) { + getTournamentDecorator().createNewGameSchedule(); + } + } else { + getTournamentDecorator().createNewGameSchedule(); + } } @FXML