Commit 7fde8135 authored by Axel Howind's avatar Axel Howind

result handling (in progress)

parent 0f072a14
......@@ -97,7 +97,8 @@ public class DialogSample extends Application {
.page("dbms",
Dialogs.inputPane()
.header("Choose your Database from the list below.")
.radioList("rdmbs", "Database", null, String.class, "H2", "PostgreSQL", "MySQL"))
.radioList("rdmbs", "Database", null, String.class, "H2", "PostgreSQL", "MySQL")
.resultHandler((p,b) -> true))
.showAndWait();
System.out.format("Dialog result:%n%s%n", rc);
}));
......
......@@ -16,18 +16,24 @@ package com.dua3.fx.util.controls;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import javafx.scene.control.DialogPane;
import javafx.scene.control.ButtonType;
/**
* Abstract base class for DialogPane builders.
*
* Provides a fluent interface to create Dialog panes.
*
* @param <T> the type of the dialog or pane to build
* @param <B> the type of the builder
*/
public abstract class AbstractDialogPaneBuilder<T, B extends AbstractDialogPaneBuilder<T, B>> {
public static interface ResultHandler<T> {
boolean handleResult(T source, ButtonType btn);
}
final BiConsumer<T, String> headerSetter;
final BiConsumer<T, String> textSetter;
......@@ -45,7 +51,7 @@ public abstract class AbstractDialogPaneBuilder<T, B extends AbstractDialogPaneB
private String header = null;
private String text = null;
private Consumer<DialogPane> resultHandler = p -> {};
private ResultHandler<T> resultHandler = (p,b) -> true;
protected void setSupplier(Supplier<T> supplier) {
this.supplier = Objects.requireNonNull(supplier);
......@@ -90,7 +96,7 @@ public abstract class AbstractDialogPaneBuilder<T, B extends AbstractDialogPaneB
}
/**
* Set Alert text.
* Set text.
* @param fmt
* the format String as defined by {@link java.util.Formatter}
* @param args
......@@ -105,12 +111,12 @@ public abstract class AbstractDialogPaneBuilder<T, B extends AbstractDialogPaneB
}
@SuppressWarnings("unchecked")
public B resultHandler(Consumer<DialogPane> resultHandler) {
public B resultHandler(ResultHandler<T> resultHandler) {
this.resultHandler = Objects.requireNonNull(resultHandler);
return (B) this;
}
public Consumer<DialogPane> getResultHandler() {
public ResultHandler<T> getResultHandler() {
return resultHandler;
}
......
......@@ -15,7 +15,6 @@
package com.dua3.fx.util.controls;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;
/**
......@@ -24,7 +23,7 @@ import javafx.scene.control.DialogPane;
* Provides a fluent interface to create Alerts.
*/
public class AlertPaneBuilder
extends StandardDialogPaneBuilder<DialogPane, AlertPaneBuilder, ButtonType> {
extends StandardDialogPaneBuilder<DialogPane, AlertPaneBuilder> {
public AlertPaneBuilder(AlertType type) {
super(() -> createPane(type));
}
......
......@@ -16,7 +16,6 @@ package com.dua3.fx.util.controls;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.DoubleFunction;
......@@ -42,7 +41,7 @@ import javafx.scene.control.TextField;
* Provides a fluent interface to create Alerts.
*/
public class InputDialogPaneBuilder
extends StandardDialogPaneBuilder<InputDialogPane, InputDialogPaneBuilder, Map<String, Object>>
extends StandardDialogPaneBuilder<InputDialogPane, InputDialogPaneBuilder>
implements InputBuilder<InputDialogPaneBuilder> {
public InputDialogPaneBuilder() {
......
......@@ -4,7 +4,7 @@ import java.util.function.Supplier;
import javafx.scene.control.DialogPane;
public class StandardDialogPaneBuilder<T extends DialogPane, B extends StandardDialogPaneBuilder<T,B,R>, R>
public class StandardDialogPaneBuilder<T extends DialogPane, B extends StandardDialogPaneBuilder<T,B>>
extends AbstractDialogPaneBuilder<T, B> {
protected StandardDialogPaneBuilder(Supplier<T> supplier) {
super(supplier, DialogPane::setHeaderText, DialogPane::setContentText);
......
......@@ -8,6 +8,8 @@ import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.dua3.fx.util.controls.AbstractDialogPaneBuilder.ResultHandler;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.collections.FXCollections;
......@@ -88,7 +90,7 @@ public class WizardDialog extends Dialog<ButtonType> {
}
@SuppressWarnings("unchecked")
public <P extends DialogPane> void setPane(P pane, Consumer<P> resultHandler) {
public <P extends DialogPane> void setPane(P pane, ResultHandler<P> resultHandler) {
this.pane = pane;
this.resultHandler = (Consumer<? super DialogPane>) resultHandler;
}
......
......@@ -2,8 +2,8 @@ package com.dua3.fx.util.controls;
import java.util.LinkedHashMap;
import java.util.Optional;
import java.util.function.Consumer;
import com.dua3.fx.util.controls.AbstractDialogPaneBuilder.ResultHandler;
import com.dua3.fx.util.controls.WizardDialog.Page;
import javafx.scene.control.ButtonType;
......@@ -21,11 +21,11 @@ public class WizardDialogBuilder {
LinkedHashMap<String, Page> pages = new LinkedHashMap<>();
public WizardDialogBuilder page(String name, StandardDialogPaneBuilder<?,?,?> builder) {
public <T extends DialogPane,B extends StandardDialogPaneBuilder<T,B>> WizardDialogBuilder page(String name, B builder) {
Page page = new Page();
page.setNext(builder.next);
DialogPane pane = (DialogPane) builder.build();
Consumer<DialogPane> resultHandler = builder.getResultHandler();
T pane = builder.build();
ResultHandler<T> resultHandler = builder.getResultHandler();
page.setPane(pane, resultHandler);
pages.put(name, page);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment