created Class AlertDelete.java

This commit is contained in:
schrom01 2022-05-01 12:19:22 +02:00
parent 58b1692181
commit 80005d214d
2 changed files with 41 additions and 5 deletions

View File

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

View File

@ -87,12 +87,14 @@ public class TournamentListController extends FXController {
@FXML @FXML
void deleteTournament(ActionEvent event) { void deleteTournament(ActionEvent event) {
//TODO Ask first to delete?
File tournamentFile = tournamentListView.getSelectionModel().getSelectedItems().get(0); File tournamentFile = tournamentListView.getSelectionModel().getSelectedItems().get(0);
try { AlertDelete alert = new AlertDelete(tournamentFile.toString());
getFileIO().deleteTournament(tournamentFile); if(alert.showAndGetResult()){
} catch (IOException e) { try {
e.printStackTrace(); //TODO handle and logging getFileIO().deleteTournament(tournamentFile);
} catch (IOException e) {
e.printStackTrace(); //TODO handle and logging
}
} }
} }