created Class AlertDelete.java
This commit is contained in:
parent
58b1692181
commit
80005d214d
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue