Commit 00af6236 authored by Axel Howind's avatar Axel Howind

fix button handling issues

parent 7c624020
package com.dua3.fx.util.controls;
import com.dua3.utility.lang.LangUtil;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;
......@@ -40,4 +44,19 @@ public abstract class InputDialogPane<R> extends DialogPane implements Supplier<
public void initButtons() {
getButtonTypes().setAll(buttons);
}
protected Node createButton(ButtonType buttonType) {
// a wizard dialog should only close when finish or cancel is clicked
if (LangUtil.isOneOf(buttonType, ButtonType.OK, ButtonType.FINISH, ButtonType.CANCEL)) {
return super.createButton(buttonType);
}
final Button button = new Button(buttonType.getText());
final ButtonBar.ButtonData buttonData = buttonType.getButtonData();
ButtonBar.setButtonData(button, buttonData);
button.setDefaultButton(buttonData.isDefaultButton());
button.setCancelButton(buttonData.isCancelButton());
return button;
}
}
......@@ -34,17 +34,11 @@ public class WizardDialog extends Dialog<Map<String,Object>> {
public WizardDialog() {
setResultConverter(btn -> {
// stay in the dialog if something is not ok or we haven't reached "Finish" yet
if (btn != ButtonType.FINISH) {
return null;
}
// otherwise add current page to the stack, then build and return the result map
// add current page to the stack, then build and return the result map
pageStack.add(current);
LinkedHashMap<String, Object> result = new LinkedHashMap<>();
pageStack.stream()
.forEach( p -> result.put(p.first, p.second.result) );
pageStack.stream().forEach( p -> result.put(p.first, p.second.result) );
return result;
});
......
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