From afab6dbee306a2e624e7c2f9c8acaa324fcca37c Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sat, 7 May 2022 16:43:46 +0200 Subject: [PATCH] refactoring of GameSchedule and button "close Tournament" added. added "informListener()" to method refreshParticipants in GameDecorator.java to be sure the new participants are saved in file. --- .../turnierverwaltung/FXController.java | 33 ++++++++++++------- .../main/gameScheduleView/GameDecorator.java | 1 + .../GameScheduleController.java | 11 +++++++ .../ParticipantFormularController.java | 1 + .../PlacesFormularController.java | 1 + .../TournamentListController.java | 1 + .../gameScheduleView/GameSchedule.fxml | 10 +++--- 7 files changed, 41 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FXController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FXController.java index bb07387..68a86b6 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FXController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FXController.java @@ -7,24 +7,23 @@ public abstract class FXController { FactoryDecorator factoryDecorator; FileIO fileIO; Pane pane; + IsObserver listener; + + public FXController(){ + listener = new IsObserver() { + @Override + public void update() { + loadContent(); + } + }; + } public void setup(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, Pane pane){ this.tournamentDecorator = tournamentDecorator; this.fileIO = fileIO; this.factoryDecorator = factoryDecorator; this.pane = pane; - tournamentDecorator.addListener(new IsObserver() { - @Override - public void update() { - loadContent(); - } - }); - factoryDecorator.addListener(new IsObserver() { - @Override - public void update() { - loadContent(); - } - }); + addListener(); } public abstract void loadContent(); @@ -33,6 +32,16 @@ public abstract class FXController { this.tournamentDecorator = tournamentDecorator; } + public void addListener(){ + tournamentDecorator.addListener(listener); + factoryDecorator.addListener(listener); + } + + protected void removeListener(){ + tournamentDecorator.removeListener(listener); + factoryDecorator.removeListener(listener); + } + protected TournamentDecorator getTournamentDecorator() { return tournamentDecorator; } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameDecorator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameDecorator.java index 31322e4..29d93f2 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameDecorator.java @@ -55,6 +55,7 @@ public class GameDecorator implements IsObservable{ public void refreshParticipants(){ game.refreshParticipants(); + informListener(); } public Place getPlace() { diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java index f0dab5e..675806b 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java @@ -18,6 +18,9 @@ public class GameScheduleController extends FXController { @FXML private Button editParticipantBtn; + @FXML + private Button closeTournamentBtn; + @FXML private HBox hBoxCenter; @@ -33,14 +36,22 @@ public class GameScheduleController extends FXController { @FXML void openPlacesFormular(ActionEvent event) { + removeListener(); getFactoryDecorator().openPlacesFormular(); } @FXML void openParticipantFormular(ActionEvent event) { + removeListener(); getFactoryDecorator().openParticipantFormular(); } + @FXML + void closeTournament(ActionEvent event) { + removeListener(); + getFactoryDecorator().openTournamentList(); + } + @Override public void loadContent() { getFactoryDecorator().loadGameTree(hBoxCenter, getTournamentDecorator()); diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/ParticipantFormularController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/ParticipantFormularController.java index 0528301..b677ce5 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/ParticipantFormularController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/ParticipantFormularController.java @@ -89,6 +89,7 @@ public class ParticipantFormularController extends FXController { @FXML void close(ActionEvent event) { + removeListener(); getFactoryDecorator().openScheduleView(); } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/placesAddFormular/PlacesFormularController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/placesAddFormular/PlacesFormularController.java index c5534e5..6a2de96 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/placesAddFormular/PlacesFormularController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/placesAddFormular/PlacesFormularController.java @@ -68,6 +68,7 @@ public class PlacesFormularController extends FXController { @FXML void close(ActionEvent event) { + removeListener(); getFactoryDecorator().openScheduleView(); } 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 bcc1109..b70630a 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 @@ -61,6 +61,7 @@ public class TournamentListController extends FXController { @FXML void openTournament(ActionEvent event) { + removeListener(); FileIO.TournamentFile tournamentFile = tournamentListView.getSelectionModel().getSelectedItems().get(0); getFactoryDecorator().openTournament(tournamentFile); } diff --git a/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/gameScheduleView/GameSchedule.fxml b/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/gameScheduleView/GameSchedule.fxml index 6c824a7..8e77213 100644 --- a/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/gameScheduleView/GameSchedule.fxml +++ b/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/gameScheduleView/GameSchedule.fxml @@ -1,11 +1,10 @@ - - - - + + + - + @@ -24,6 +23,7 @@ +