From 80005d214d519f4fd35c7682b3a2308413cba5e1 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sun, 1 May 2022 12:19:22 +0200 Subject: [PATCH] created Class AlertDelete.java --- .../main/tournamentList/AlertDelete.java | 34 +++++++++++++++++++ .../TournamentListController.java | 12 ++++--- 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/AlertDelete.java diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/AlertDelete.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/AlertDelete.java new file mode 100644 index 0000000..e440807 --- /dev/null +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/AlertDelete.java @@ -0,0 +1,34 @@ +package ch.zhaw.projekt2.turnierverwaltung.main.tournamentList; + +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonBar; +import javafx.scene.control.ButtonType; + +import java.io.IOException; + +public class AlertDelete extends Alert { + ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES); + ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO); + Boolean result; + + public AlertDelete(String name){ + super(Alert.AlertType.WARNING); + setTitle("Entfernen"); + setHeaderText("Turnier entfernen?"); + setContentText("Sind Sie sicher, dass sie das Turnier " + name + " entfernen wollen?\n" + + "Nach diesem Vorgang kann es nicht wiederhergestellt werden."); + getButtonTypes().setAll(yesButton, noButton); + } + + public boolean showAndGetResult() { + result = false; + showAndWait().ifPresent(type -> { + if (type == yesButton) { + result = true; + } + }); + return result; + } + + +} diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/TournamentListController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/TournamentListController.java index bf8b2c5..3ce4cef 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/TournamentListController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/TournamentListController.java @@ -87,12 +87,14 @@ public class TournamentListController extends FXController { @FXML void deleteTournament(ActionEvent event) { - //TODO Ask first to delete? File tournamentFile = tournamentListView.getSelectionModel().getSelectedItems().get(0); - try { - getFileIO().deleteTournament(tournamentFile); - } catch (IOException e) { - e.printStackTrace(); //TODO handle and logging + AlertDelete alert = new AlertDelete(tournamentFile.toString()); + if(alert.showAndGetResult()){ + try { + getFileIO().deleteTournament(tournamentFile); + } catch (IOException e) { + e.printStackTrace(); //TODO handle and logging + } } }