Create alert popup if user wants to create new game schedule #49

Merged
fassband merged 2 commits from gameSchedule_Alert into main 2022-05-13 16:12:29 +02:00
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;
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,8 +29,15 @@ public class GameScheduleController extends FXController {
@FXML
void createNewSchedule(ActionEvent event) {
if (getTournamentDecorator().getTournament().getGameList().size() > 0) {
AlertNewSchedule alert = new AlertNewSchedule();
if (alert.showAndGetResult()) {
getTournamentDecorator().createNewGameSchedule();
}
} else {
getTournamentDecorator().createNewGameSchedule();
}
}
@FXML
void openPlacesFormular(ActionEvent event) {

View File

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