void setupCleanup() {
        Platform.runLater(() -> {
            Scene scene = getScene();
            // if there is no scene, don't cause NPE by calling "getWindow()" on null
            if (Objects.isNull(scene)) {
                // should only be thrown in tests with mocked views
                LOGGER.error("setupCleanup - Scene could not be found! setOnCloseRequest was not set");
                return;
            }

            Stage stage = (Stage) getScene().getWindow();
            // when application is closed, destroy all modules
            stage.setOnCloseRequest(event -> {
                LOGGER.trace("Stage was requested to be closed");
                event.consume(); // we need to perform some cleanup actions first

                // close all open modules until one returns false
                while (!getOpenModules().isEmpty()) {
                    WorkbenchModule openModule = getOpenModules().get(0);
                    if (!closeModule(openModule)) {
                        LOGGER.trace("Module " + openModule + " could not be closed yet");

                        // once module is ready to be closed, start stage closing process over again
                        getModuleCloseable(openModule).thenRun(() -> {
                            LOGGER.trace("moduleCloseable - Stage - thenRun triggered: " + openModule);
                            LOGGER.trace(openModule + " restarted stage closing process");
                            // re-start closing process, in case other modules are blocking the closing process
                            stage.fireEvent(new WindowEvent(stage, WindowEvent.WINDOW_CLOSE_REQUEST));
                        });
                        LOGGER.trace("moduleCloseable - Stage - thenRun set: " + openModule);

                        break; // interrupt closing until the interrupting module has been safely closed
                    }
                }

                if (getOpenModules().isEmpty()) {
                    LOGGER.trace("All modules could be closed successfully, closing stage");
                    stage.close();
                }
            });
        });
    }
Constructor for WorkbenchFX by using the {@link WorkbenchBuilder}.

@param builder to use for the setup
workbenchfx-core/src/main/java/com/dlsc/workbenchfx/Workbench.java