From 3664a4e8a730e2920b4563530a20681208a251e1 Mon Sep 17 00:00:00 2001 From: Andreas Billmann Date: Thu, 11 Aug 2016 13:11:23 +0200 Subject: [PATCH] the most senseless combination of rules are not possible any more --- .../ValidationEditorController.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/ninja/javafx/smartcsv/fx/validation/ValidationEditorController.java b/src/main/java/ninja/javafx/smartcsv/fx/validation/ValidationEditorController.java index 11dd839..204ead5 100644 --- a/src/main/java/ninja/javafx/smartcsv/fx/validation/ValidationEditorController.java +++ b/src/main/java/ninja/javafx/smartcsv/fx/validation/ValidationEditorController.java @@ -28,6 +28,8 @@ package ninja.javafx.smartcsv.fx.validation; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.scene.control.*; import ninja.javafx.smartcsv.fx.FXMLController; @@ -181,11 +183,30 @@ public class ValidationEditorController extends FXMLController { initTextInputControl(valueOfRuleTextField, enableValueOfRule); initCodeAreaControl(groovyRuleTextArea, enableGroovyRule); + listenToExcludingRuleCombinations(); + selectedColumn.addListener(observable -> { updateForm(); }); } + private void listenToExcludingRuleCombinations() { + addDependencyListener(enableIntegerRule, enableDoubleRule, enableAlphanumericRule, enableDateRule); + addDependencyListener(enableDoubleRule, enableIntegerRule, enableAlphanumericRule, enableDateRule); + addDependencyListener(enableAlphanumericRule, enableIntegerRule, enableDoubleRule, enableDateRule); + addDependencyListener(enableDateRule, enableIntegerRule, enableDoubleRule, enableAlphanumericRule); + } + + private void addDependencyListener(CheckBox rule, CheckBox... dependentRules) { + rule.selectedProperty().addListener((observable, oldValue, newValue) -> { + if (newValue) { + for (CheckBox dependentRule: dependentRules) { + dependentRule.selectedProperty().setValue(false); + } + } + }); + } + public String getSelectedColumn() { return selectedColumn.get(); }