package com.dezorganizacja.bridge.view.graphical;

import com.dezorganizacja.bridge.presenter.MainPresenter;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class FXApplication extends Application {
    private static MainPresenter mainPresenter;

    public static void setMainPresenter(MainPresenter mainPresenter) {
        FXApplication.mainPresenter = mainPresenter;
    }

    @Override
    public void start(Stage stage) throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
        Parent root = loader.load();
        stage.setTitle("Bridge");
        stage.setScene(new Scene(root, 300, 275));

        MainController controller = loader.getController();
        controller.init(mainPresenter);

        stage.show();
    }
}

@@ -141,16 +141,52 @@
 cation;%0A
+import javafx.application.Platform;%0A
 import j
@@ -291,16 +291,45 @@
 Stage;%0A%0A
+import java.io.IOException;%0A%0A
 public c
@@ -416,16 +416,48 @@
 esenter;
+%0A    private static Stage stage;
 %0A%0A    pu
@@ -645,24 +645,256 @@
 Exception %7B%0A
+        FXApplication.stage = stage;%0A        _changeMainScene();%0A    %7D%0A%0A    private void _changeMainScene() %7B%0A        String programStage = mainPresenter.getStage();%0A        String fxml = ProgramStageMap.stageToFXML(programStage);%0A%0A
         FXML
@@ -951,25 +951,12 @@
 rce(
-%22/
 fxml
-/main.fxml%22
 ));%0A
@@ -978,25 +978,232 @@
 root
- = loader.load();
+;%0A        try %7B%0A            root = loader.load();%0A        %7D catch (IOException e) %7B%0A            System.err.println(%22error while loading %22 + fxml + %22 resource%22);%0A            e.printStackTrace();%0A            return;%0A        %7D%0A
 %0A   
@@ -1341,24 +1341,62 @@
 ntroller();%0A
+        if (controller != null) %7B%0A    
         cont
@@ -1422,16 +1422,26 @@
 senter);
+%0A        %7D
 %0A%0A      
@@ -1461,11 +1461,135 @@
 );%0A    %7D
+%0A%0A    public void changeMainScene() %7B%0A        // TODO thread safety%0A        Platform.runLater(this::_changeMainScene);%0A    %7D
 %0A%7D%0A

Make FXApplication change its main scene