All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bayern.steinbrecher.screens.WizardScreen Maven / Gradle / Ivy

Go to download

An abstract structure for JavaFX based applications for handling dialogs and switching between them.

There is a newer version: 0.2.4
Show newest version
package bayern.steinbrecher.screens;

import bayern.steinbrecher.wizard.Wizard;
import bayern.steinbrecher.wizard.WizardPage;
import bayern.steinbrecher.wizard.WizardState;
import javafx.fxml.LoadException;
import javafx.scene.Parent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.ResourceBundle;

public abstract class WizardScreen extends Screen {
    private final Wizard wizard;

    protected WizardScreen() throws LoadException {
        super(WizardScreen.class.getResource("WizardScreen.fxml"),
                ResourceBundle.getBundle("bayern.steinbrecher.screens.WizardScreen"));
        this.wizard = Wizard.create(generatePages());
    }

    @Override
    protected void afterControllerIsInitialized(@NotNull WizardScreenController controller) {
        super.afterControllerIsInitialized(controller);
        wizard.stateProperty()
                .addListener(((obs, oldVal, newVal) -> {
                    if (newVal == WizardState.FINISHED) {
                        controller.getScreenManager()
                                .switchBack();
                    }
                }));
        wizard.atFinishProperty()
                .addListener((observable, oldValue, newValue) -> {
                    System.out.println("HERE");
                });
    }

    @Override
    @NotNull
    public final Parent create(@NotNull ScreenManager manager) {
        return wizard.getRoot();
    }

    @NotNull
    public final Optional getResult() {
        return wizard.getVisitedPages()
                .map(this::getResultImpl);
    }

    @NotNull
    protected abstract Map> generatePages() throws LoadException;

    @Nullable
    protected abstract R getResultImpl(@NotNull Collection visitedPages);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy