Tournament list #11
|
@ -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,14 +87,16 @@ 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);
|
||||||
|
AlertDelete alert = new AlertDelete(tournamentFile.toString());
|
||||||
|
if(alert.showAndGetResult()){
|
||||||
try {
|
try {
|
||||||
getFileIO().deleteTournament(tournamentFile);
|
getFileIO().deleteTournament(tournamentFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace(); //TODO handle and logging
|
e.printStackTrace(); //TODO handle and logging
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadContent() {
|
public void loadContent() {
|
||||||
|
|
Loading…
Reference in New Issue