parent
							
								
									92d121890c
								
							
						
					
					
						commit
						6c761c944f
					
				| 
						 | 
					@ -37,11 +37,6 @@ public abstract class FXController {
 | 
				
			||||||
        factoryDecorator.addListener(listener);
 | 
					        factoryDecorator.addListener(listener);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected void removeListener(){
 | 
					 | 
				
			||||||
        tournamentDecorator.removeListener(listener);
 | 
					 | 
				
			||||||
        factoryDecorator.removeListener(listener);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    protected TournamentDecorator getTournamentDecorator() {
 | 
					    protected TournamentDecorator getTournamentDecorator() {
 | 
				
			||||||
        return tournamentDecorator;
 | 
					        return tournamentDecorator;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,6 @@ package ch.zhaw.projekt2.turnierverwaltung;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameController;
 | 
					import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameController;
 | 
				
			||||||
import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameDecorator;
 | 
					import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameDecorator;
 | 
				
			||||||
import ch.zhaw.projekt2.turnierverwaltung.main.tournamentList.TournamentListController;
 | 
					 | 
				
			||||||
import javafx.fxml.FXMLLoader;
 | 
					import javafx.fxml.FXMLLoader;
 | 
				
			||||||
import javafx.geometry.Insets;
 | 
					import javafx.geometry.Insets;
 | 
				
			||||||
import javafx.scene.control.Label;
 | 
					import javafx.scene.control.Label;
 | 
				
			||||||
| 
						 | 
					@ -11,16 +10,15 @@ import javafx.scene.paint.Color;
 | 
				
			||||||
import javafx.scene.text.Font;
 | 
					import javafx.scene.text.Font;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
import java.net.URL;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Factory {
 | 
					public class Factory {
 | 
				
			||||||
    private TournamentDecorator tournamentDecorator;
 | 
					    private TournamentDecorator tournamentDecorator;
 | 
				
			||||||
    private FileIO fileIO;
 | 
					    private FileIO fileIO;
 | 
				
			||||||
    //TODO save views instead of recreate them.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Factory(FileIO fileIO, TournamentDecorator tournamentDecorator) {
 | 
					    public Factory(FileIO fileIO, TournamentDecorator tournamentDecorator) {
 | 
				
			||||||
        this.fileIO = fileIO;
 | 
					        this.fileIO = fileIO;
 | 
				
			||||||
        this.tournamentDecorator = tournamentDecorator;
 | 
					        this.tournamentDecorator = tournamentDecorator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public TournamentDecorator getTournamentDecorator() {
 | 
					    public TournamentDecorator getTournamentDecorator() {
 | 
				
			||||||
| 
						 | 
					@ -42,25 +40,43 @@ public class Factory {
 | 
				
			||||||
        return null;
 | 
					        return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void loadTournamentList(BorderPane pane, FactoryDecorator factoryDecorator) {
 | 
					    public void loadAllViews(FactoryDecorator factoryDecorator, BorderPane pane){
 | 
				
			||||||
 | 
					        for(View view : View.values()){
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                view.loadView(tournamentDecorator, fileIO, factoryDecorator, pane);
 | 
				
			||||||
 | 
					            } catch (IOException e) {
 | 
				
			||||||
 | 
					                e.printStackTrace();
 | 
				
			||||||
 | 
					                //TODO Handle and logging.
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void showTournamentList(BorderPane pane, FactoryDecorator factoryDecorator) {
 | 
				
			||||||
        tournamentDecorator.setTournament(null);
 | 
					        tournamentDecorator.setTournament(null);
 | 
				
			||||||
        TournamentListController controller = (TournamentListController) setCenterOfBorderPane(pane, getClass().getResource("tournamentList/tournamentList.fxml"), factoryDecorator);
 | 
					        setCenterOfBorderPane(pane, View.tournamentList);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Can be used to Open new Scene in same Stage.
 | 
					    //Can be used to Open new Scene in same Stage.
 | 
				
			||||||
    //This way possible to later give object to Controller
 | 
					    //This way possible to later give object to Controller
 | 
				
			||||||
    public void loadParticipantFormular(BorderPane pane, FactoryDecorator factoryDecorator) {
 | 
					    public void showParticipantFormular(BorderPane pane, FactoryDecorator factoryDecorator) {
 | 
				
			||||||
        setCenterOfBorderPane(pane, getClass().getResource("participantAddFormular/participantFormular.fxml"), factoryDecorator);
 | 
					        setCenterOfBorderPane(pane, View.participantFormular);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void loadPlacesFormular(BorderPane pane, FactoryDecorator factoryDecorator) {
 | 
					    public void showPlacesFormular(BorderPane pane, FactoryDecorator factoryDecorator) {
 | 
				
			||||||
        setCenterOfBorderPane(pane, getClass().getResource("placesAddFormular/PlacesFormular.fxml"), factoryDecorator);
 | 
					        setCenterOfBorderPane(pane, View.placesFormular);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void loadGameScheduler(BorderPane pane, FactoryDecorator factoryDecorator) {
 | 
					    public void showGameScheduler(BorderPane pane, FactoryDecorator factoryDecorator) {
 | 
				
			||||||
        setCenterOfBorderPane(pane, getClass().getResource("gameScheduleView/GameSchedule.fxml"), factoryDecorator);
 | 
					        setCenterOfBorderPane(pane, View.gameScheduler);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void setCenterOfBorderPane(BorderPane pane, View view) {
 | 
				
			||||||
 | 
					        FXController controller = null;
 | 
				
			||||||
 | 
					        pane.setCenter(view.getPane());
 | 
				
			||||||
 | 
					        resetFooter(pane, true);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public GameController loadGameView(VBox box, GameDecorator gameDecorator, FactoryDecorator factoryDecorator) {
 | 
					    public GameController loadGameView(VBox box, GameDecorator gameDecorator, FactoryDecorator factoryDecorator) {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            FXMLLoader loader = new FXMLLoader(getClass().getResource("gameScheduleView/Game.fxml"));
 | 
					            FXMLLoader loader = new FXMLLoader(getClass().getResource("gameScheduleView/Game.fxml"));
 | 
				
			||||||
| 
						 | 
					@ -75,23 +91,6 @@ public class Factory {
 | 
				
			||||||
        return null;
 | 
					        return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private FXController setCenterOfBorderPane(BorderPane pane, URL location, FactoryDecorator factoryDecorator) {
 | 
					 | 
				
			||||||
        FXController controller = null;
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            FXMLLoader loader = new FXMLLoader(location);
 | 
					 | 
				
			||||||
            pane.setCenter(loader.load());
 | 
					 | 
				
			||||||
            controller = loader.getController();
 | 
					 | 
				
			||||||
            controller.setup(tournamentDecorator, fileIO, factoryDecorator, pane);
 | 
					 | 
				
			||||||
            VBox bottom = (VBox) pane.getBottom();
 | 
					 | 
				
			||||||
            resetFooter(pane, true);
 | 
					 | 
				
			||||||
        } catch (IOException e) {
 | 
					 | 
				
			||||||
            e.printStackTrace();
 | 
					 | 
				
			||||||
            //TODO handle and logging?
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return controller;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void printMessageToFooter(BorderPane pane, String msg, boolean error) {
 | 
					    public void printMessageToFooter(BorderPane pane, String msg, boolean error) {
 | 
				
			||||||
        VBox bottom = (VBox) pane.getBottom();
 | 
					        VBox bottom = (VBox) pane.getBottom();
 | 
				
			||||||
        Label label = new Label();
 | 
					        Label label = new Label();
 | 
				
			||||||
| 
						 | 
					@ -131,4 +130,30 @@ public class Factory {
 | 
				
			||||||
        vBox.setBorder(null);
 | 
					        vBox.setBorder(null);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public enum View {
 | 
				
			||||||
 | 
					        tournamentList("tournamentList/tournamentList.fxml"),
 | 
				
			||||||
 | 
					        participantFormular("participantAddFormular/participantFormular.fxml"),
 | 
				
			||||||
 | 
					        placesFormular("placesAddFormular/PlacesFormular.fxml"),
 | 
				
			||||||
 | 
					        gameScheduler("gameScheduleView/GameSchedule.fxml");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private String fxmlFileName;
 | 
				
			||||||
 | 
					        private Pane pane;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private View(String fxmlFileName) {
 | 
				
			||||||
 | 
					            this.fxmlFileName = fxmlFileName;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public Pane getPane() {
 | 
				
			||||||
 | 
					            return pane;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void loadView(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, BorderPane borderPane) throws IOException {
 | 
				
			||||||
 | 
					            FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFileName));
 | 
				
			||||||
 | 
					            this.pane = loader.load();
 | 
				
			||||||
 | 
					            FXController controller = loader.getController();
 | 
				
			||||||
 | 
					            controller.setup(tournamentDecorator, fileIO, factoryDecorator, borderPane);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -59,28 +59,32 @@ public class FactoryDecorator implements IsObservable{
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void openTournamentList() {
 | 
					    public void openTournamentList() {
 | 
				
			||||||
        factory.loadTournamentList((BorderPane) pane, this);
 | 
					        factory.showTournamentList((BorderPane) pane, this);
 | 
				
			||||||
        informListener();
 | 
					        informListener();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void openParticipantFormular() {
 | 
					    public void openParticipantFormular() {
 | 
				
			||||||
        factory.loadParticipantFormular((BorderPane) pane, this);
 | 
					        factory.showParticipantFormular((BorderPane) pane, this);
 | 
				
			||||||
        informListener();
 | 
					        informListener();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void openPlacesFormular() {
 | 
					    public void openPlacesFormular() {
 | 
				
			||||||
        factory.loadPlacesFormular((BorderPane) pane, this);
 | 
					        factory.showPlacesFormular((BorderPane) pane, this);
 | 
				
			||||||
        informListener();
 | 
					        informListener();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void openScheduleView() {
 | 
					    public void openScheduleView() {
 | 
				
			||||||
        factory.loadGameScheduler((BorderPane) pane, this);
 | 
					        factory.showGameScheduler((BorderPane) pane, this);
 | 
				
			||||||
        informListener();
 | 
					        informListener();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void loadGameList(HBox hBoxCenter, TournamentDecorator tournamentDecorator, boolean treeView) {
 | 
					    public void loadGameList(HBox hBoxCenter, TournamentDecorator tournamentDecorator, boolean treeView) {
 | 
				
			||||||
        hBoxCenter.getChildren().clear();
 | 
					        hBoxCenter.getChildren().clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(tournamentDecorator.getTournament() == null){
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        List<List<Game>> gameList = tournamentDecorator.getTournament().getGameList();
 | 
					        List<List<Game>> gameList = tournamentDecorator.getTournament().getGameList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        List<GameDecorator> gameDecoratorsList = new ArrayList<>();
 | 
					        List<GameDecorator> gameDecoratorsList = new ArrayList<>();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,6 +22,7 @@ public class MainWindow extends Application {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        BorderPane pane = factory.loadMainWindow();
 | 
					        BorderPane pane = factory.loadMainWindow();
 | 
				
			||||||
        factoryDecorator = new FactoryDecorator(fileIO, factory, pane);
 | 
					        factoryDecorator = new FactoryDecorator(fileIO, factory, pane);
 | 
				
			||||||
 | 
					        factory.loadAllViews(factoryDecorator, pane);
 | 
				
			||||||
        tournamentDecorator.setFactoryDecorator(factoryDecorator);
 | 
					        tournamentDecorator.setFactoryDecorator(factoryDecorator);
 | 
				
			||||||
        factoryDecorator.openTournamentList();
 | 
					        factoryDecorator.openTournamentList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,19 +35,16 @@ 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
 | 
					    @FXML
 | 
				
			||||||
    void closeTournament(ActionEvent event) {
 | 
					    void closeTournament(ActionEvent event) {
 | 
				
			||||||
        removeListener();
 | 
					 | 
				
			||||||
        getFactoryDecorator().openTournamentList();
 | 
					        getFactoryDecorator().openTournamentList();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ package ch.zhaw.projekt2.turnierverwaltung.main.participantAddFormular;
 | 
				
			||||||
import ch.zhaw.projekt2.turnierverwaltung.FXController;
 | 
					import ch.zhaw.projekt2.turnierverwaltung.FXController;
 | 
				
			||||||
import ch.zhaw.projekt2.turnierverwaltung.Participant;
 | 
					import ch.zhaw.projekt2.turnierverwaltung.Participant;
 | 
				
			||||||
import ch.zhaw.projekt2.turnierverwaltung.Player;
 | 
					import ch.zhaw.projekt2.turnierverwaltung.Player;
 | 
				
			||||||
 | 
					import ch.zhaw.projekt2.turnierverwaltung.Tournament;
 | 
				
			||||||
import javafx.event.ActionEvent;
 | 
					import javafx.event.ActionEvent;
 | 
				
			||||||
import javafx.fxml.FXML;
 | 
					import javafx.fxml.FXML;
 | 
				
			||||||
import javafx.scene.control.Button;
 | 
					import javafx.scene.control.Button;
 | 
				
			||||||
| 
						 | 
					@ -97,12 +98,16 @@ public class ParticipantFormularController extends FXController {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    void close(ActionEvent event) {
 | 
					    void close(ActionEvent event) {
 | 
				
			||||||
        removeListener();
 | 
					 | 
				
			||||||
        getFactoryDecorator().openScheduleView();
 | 
					        getFactoryDecorator().openScheduleView();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void loadContent() {
 | 
					    public void loadContent() {
 | 
				
			||||||
        participantListView.setItems(getTournamentDecorator().getTournament().getParticipants());
 | 
					        Tournament tournament = getTournamentDecorator().getTournament();
 | 
				
			||||||
 | 
					        if(tournament != null){
 | 
				
			||||||
 | 
					            participantListView.setItems(tournament.getParticipants());
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            participantListView.getItems().clear();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ package ch.zhaw.projekt2.turnierverwaltung.main.placesAddFormular;
 | 
				
			||||||
import ch.zhaw.projekt2.turnierverwaltung.FXController;
 | 
					import ch.zhaw.projekt2.turnierverwaltung.FXController;
 | 
				
			||||||
import ch.zhaw.projekt2.turnierverwaltung.Place;
 | 
					import ch.zhaw.projekt2.turnierverwaltung.Place;
 | 
				
			||||||
import ch.zhaw.projekt2.turnierverwaltung.Player;
 | 
					import ch.zhaw.projekt2.turnierverwaltung.Player;
 | 
				
			||||||
 | 
					import ch.zhaw.projekt2.turnierverwaltung.Tournament;
 | 
				
			||||||
import javafx.event.ActionEvent;
 | 
					import javafx.event.ActionEvent;
 | 
				
			||||||
import javafx.fxml.FXML;
 | 
					import javafx.fxml.FXML;
 | 
				
			||||||
import javafx.scene.control.Button;
 | 
					import javafx.scene.control.Button;
 | 
				
			||||||
| 
						 | 
					@ -73,12 +74,16 @@ public class PlacesFormularController extends FXController {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    void close(ActionEvent event) {
 | 
					    void close(ActionEvent event) {
 | 
				
			||||||
        removeListener();
 | 
					 | 
				
			||||||
        getFactoryDecorator().openScheduleView();
 | 
					        getFactoryDecorator().openScheduleView();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void loadContent() {
 | 
					    public void loadContent() {
 | 
				
			||||||
        placeListView.setItems(getTournamentDecorator().getTournament().getPlaces());
 | 
					        Tournament tournament = getTournamentDecorator().getTournament();
 | 
				
			||||||
 | 
					        if(tournament != null){
 | 
				
			||||||
 | 
					            placeListView.setItems(tournament.getPlaces());
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            placeListView.getItems().clear();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,7 +62,6 @@ 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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue