Merge pull request #49 from PM2-IT21bWIN-ruiz-mach-krea/gameSchedule_Alert

Create alert popup if user wants to create new game schedule
This commit is contained in:
Roman Schenk 2022-05-13 16:12:29 +02:00 committed by GitHub Enterprise
commit 3d522dd13c
3 changed files with 35 additions and 5 deletions

View File

@ -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;
}
}

View File

@ -1,7 +1,6 @@
package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView; package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView;
import ch.zhaw.projekt2.turnierverwaltung.FXController; import ch.zhaw.projekt2.turnierverwaltung.FXController;
import ch.zhaw.projekt2.turnierverwaltung.Tournament;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
@ -30,7 +29,14 @@ public class GameScheduleController extends FXController {
@FXML @FXML
void createNewSchedule(ActionEvent event) { 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 @FXML

View File

@ -21,9 +21,7 @@ public class AlertDelete extends Alert {
public boolean showAndGetResult() { public boolean showAndGetResult() {
result = false; result = false;
showAndWait().ifPresent(type -> { showAndWait().ifPresent(type -> {
if (type == yesButton) { result = type == yesButton;
result = true;
}
}); });
return result; return result;
} }