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.
This commit is contained in:
schrom01 2022-05-07 16:43:46 +02:00
parent 89e72a1592
commit afab6dbee3
7 changed files with 41 additions and 17 deletions

View File

@ -7,24 +7,23 @@ public abstract class FXController {
FactoryDecorator factoryDecorator; FactoryDecorator factoryDecorator;
FileIO fileIO; FileIO fileIO;
Pane pane; 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){ public void setup(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, Pane pane){
this.tournamentDecorator = tournamentDecorator; this.tournamentDecorator = tournamentDecorator;
this.fileIO = fileIO; this.fileIO = fileIO;
this.factoryDecorator = factoryDecorator; this.factoryDecorator = factoryDecorator;
this.pane = pane; this.pane = pane;
tournamentDecorator.addListener(new IsObserver() { addListener();
@Override
public void update() {
loadContent();
}
});
factoryDecorator.addListener(new IsObserver() {
@Override
public void update() {
loadContent();
}
});
} }
public abstract void loadContent(); public abstract void loadContent();
@ -33,6 +32,16 @@ public abstract class FXController {
this.tournamentDecorator = tournamentDecorator; this.tournamentDecorator = tournamentDecorator;
} }
public void addListener(){
tournamentDecorator.addListener(listener);
factoryDecorator.addListener(listener);
}
protected void removeListener(){
tournamentDecorator.removeListener(listener);
factoryDecorator.removeListener(listener);
}
protected TournamentDecorator getTournamentDecorator() { protected TournamentDecorator getTournamentDecorator() {
return tournamentDecorator; return tournamentDecorator;
} }

View File

@ -55,6 +55,7 @@ public class GameDecorator implements IsObservable{
public void refreshParticipants(){ public void refreshParticipants(){
game.refreshParticipants(); game.refreshParticipants();
informListener();
} }
public Place getPlace() { public Place getPlace() {

View File

@ -18,6 +18,9 @@ public class GameScheduleController extends FXController {
@FXML @FXML
private Button editParticipantBtn; private Button editParticipantBtn;
@FXML
private Button closeTournamentBtn;
@FXML @FXML
private HBox hBoxCenter; private HBox hBoxCenter;
@ -33,14 +36,22 @@ public class GameScheduleController extends FXController {
@FXML @FXML
void openPlacesFormular(ActionEvent event) { void openPlacesFormular(ActionEvent event) {
removeListener();
getFactoryDecorator().openPlacesFormular(); getFactoryDecorator().openPlacesFormular();
} }
@FXML @FXML
void openParticipantFormular(ActionEvent event) { void openParticipantFormular(ActionEvent event) {
removeListener();
getFactoryDecorator().openParticipantFormular(); getFactoryDecorator().openParticipantFormular();
} }
@FXML
void closeTournament(ActionEvent event) {
removeListener();
getFactoryDecorator().openTournamentList();
}
@Override @Override
public void loadContent() { public void loadContent() {
getFactoryDecorator().loadGameTree(hBoxCenter, getTournamentDecorator()); getFactoryDecorator().loadGameTree(hBoxCenter, getTournamentDecorator());

View File

@ -89,6 +89,7 @@ public class ParticipantFormularController extends FXController {
@FXML @FXML
void close(ActionEvent event) { void close(ActionEvent event) {
removeListener();
getFactoryDecorator().openScheduleView(); getFactoryDecorator().openScheduleView();
} }

View File

@ -68,6 +68,7 @@ public class PlacesFormularController extends FXController {
@FXML @FXML
void close(ActionEvent event) { void close(ActionEvent event) {
removeListener();
getFactoryDecorator().openScheduleView(); getFactoryDecorator().openScheduleView();
} }

View File

@ -61,6 +61,7 @@ public class TournamentListController extends FXController {
@FXML @FXML
void openTournament(ActionEvent event) { void openTournament(ActionEvent event) {
removeListener();
FileIO.TournamentFile tournamentFile = tournamentListView.getSelectionModel().getSelectedItems().get(0); FileIO.TournamentFile tournamentFile = tournamentListView.getSelectionModel().getSelectedItems().get(0);
getFactoryDecorator().openTournament(tournamentFile); getFactoryDecorator().openTournament(tournamentFile);
} }

View File

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.*?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.*?>
<?import javafx.scene.layout.BorderPane?> <?import javafx.scene.layout.*?>
<?import javafx.scene.layout.HBox?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameScheduleController"> <BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.2" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameScheduleController">
<top> <top>
<HBox alignment="TOP_RIGHT" prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER"> <HBox alignment="TOP_RIGHT" prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children> <children>
@ -24,6 +23,7 @@
<Insets right="40.0" /> <Insets right="40.0" />
</HBox.margin> </HBox.margin>
</Button> </Button>
<Button fx:id="closeTournamentBtn" layoutX="470.0" layoutY="10.0" mnemonicParsing="false" onAction="#closeTournament" text="Close Tournament" />
</children> </children>
</HBox> </HBox>
</top> </top>