Commit cb8288ba authored by Axel Howind's avatar Axel Howind

fix ignored valid state for "Finish" button

parent 47383de1
package com.dua3.fx.samples;
import java.util.List;
import java.util.Optional;
import com.dua3.fx.util.Dialogs;
import com.dua3.utility.io.CsvIo;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
......@@ -13,6 +9,9 @@ import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.util.List;
import java.util.Optional;
/**
* Sample Application.
*/
......@@ -96,7 +95,7 @@ public class DialogSample extends Application {
Dialogs.inputPane()
.header("Choose your Database from the list below.")
.radioList("rdmbs", "Database", () -> null, String.class, List.of("H2", "PostgreSQL", "MySQL"))
.resultHandler((p,b) -> true))
)
.showAndWait();
System.out.format("Dialog result:%n%s%n", rc);
}));
......
package com.dua3.fx.util.controls;
import java.text.NumberFormat;
import java.util.Collection;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.property.*;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.scene.Node;
......@@ -30,6 +10,14 @@ import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.util.StringConverter;
import java.text.NumberFormat;
import java.util.Collection;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* Interface for an input field.
*
......@@ -111,6 +99,7 @@ public interface InputControl<R> {
public void setValidate(Function<R,Optional<String>> validate) {
this.validate = Objects.requireNonNull(validate);
updateValidState(valueProperty().getValue());
}
private void updateValidState(R r) {
......
package com.dua3.fx.util.controls;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.logging.Logger;
import javafx.beans.property.Property;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyStringProperty;
......@@ -15,6 +11,11 @@ import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.VBox;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Optional;
import java.util.logging.Logger;
public class RadioPane<T> extends VBox implements InputControl<T> {
/** Logger */
......@@ -56,6 +57,7 @@ public class RadioPane<T> extends VBox implements InputControl<T> {
});
this.state = new State<>(property);
this.state.setValidate( v -> v==null?Optional.of("Nothing selected.") : Optional.empty());
// update toggle, when state changes
state.valueProperty().addListener( (v,o,n) -> {
......
package com.dua3.fx.util.controls;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.dua3.fx.util.controls.AbstractDialogPaneBuilder.ResultHandler;
import com.dua3.utility.data.Pair;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanExpression;
import javafx.collections.FXCollections;
......@@ -22,6 +12,15 @@ import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
public class WizardDialog extends Dialog<Map<String,Object>> {
/** Logger instance */
......@@ -139,7 +138,7 @@ public class WizardDialog extends Dialog<Map<String,Object>> {
// next button
if (page.getNext()==null) {
addButtonToDialogPane(page, ButtonType.FINISH, null, null);
addButtonToDialogPane(page, ButtonType.FINISH, null, pane.validProperty());
} else {
addButtonToDialogPane(page, ButtonType.NEXT, evt -> {
pageStack.add(Pair.of(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