com.dua3.utility.fx.controls.WizardDialogBuilder Maven / Gradle / Ivy
package com.dua3.utility.fx.controls;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
/**
* A builder class for constructing a {@link WizardDialog} instance.
* This builder helps in setting up the title and configuring the pages
* of the wizard dialog.
*/
public class WizardDialogBuilder {
final LinkedHashMap> pages = new LinkedHashMap<>();
private String title = "";
private String startPage = "";
WizardDialogBuilder() {}
/**
* Sets the title for the wizard dialog being built.
*
* @param title The title to set for the wizard dialog.
* @return The current instance of {@code WizardDialogBuilder}, for method chaining.
*/
public WizardDialogBuilder title(String title) {
this.title = title;
return this;
}
/**
* Adds a page to the wizard dialog.
*
* @param the type of the input dialog pane
* @param the type of the abstract pane builder
* @param the type of the result produced by the pane
* @param name the name of the page to add
* @param builder the builder used to create and configure the pane
* @return the current instance of {@code WizardDialogBuilder}, for method chaining
*/
public , B extends AbstractPaneBuilder, R> WizardDialogBuilder page(String name, B builder) {
D pane = builder.build();
AbstractDialogPaneBuilder.ResultHandler resultHandler = builder.getResultHandler();
WizardDialog.Page page = new WizardDialog.Page<>(pane, resultHandler);
page.setNext(builder.next);
pages.put(name, page);
if (startPage.isEmpty()) {
setStartPage(name);
}
return this;
}
/**
* Displays the constructed wizard dialog and waits for the user to close it.
*
* @return An Optional containing a map with the results from the wizard dialog if the dialog was completed,
* or an empty Optional if the dialog was canceled or closed without completion.
*/
@SuppressWarnings("OptionalContainsCollection")
public Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy