Project: Eclipse_Platform_UI
Bug 128142 [DataBinding] IDomainValidator needs to provide partial validation / be merged with IValidator
Reported: 2006-02-15 21:50:55 | Status: verified fixed

Suppose I want to restrict an Integer field to the range 1-10. I would use an IntegerValidator and a String2IntConverter on the target2model side. I would then write an IDomainValidator to restrict the integer value coming from the String2IntConverter to the range 1-10. But this would not result in ideal behavior. The partial validation in the IntegerValidator would permit any value from Integer.MIN to Interger.MAX. But since the domain model only allows a value in the range 1-10, it makes no sense to permit a leading - sign or more than two digits in the field. The way things stand currently, the user could enter 365 in the field and wouldn't find out until they tried to leave the field that this is an invalid value. The solution appears to be to change the partial validation algorithm to the following: Call the conversion validator's partial validation method. If this succeeds: Call the conversion validator's full validation method. If this succeeds: Use the converter to convert the value to the domain's data type Pass converted value to partial validation method on domain's validator. If we do this, then the domain's validator will be able to do both partial and full validation. If we do this, then IDomainValidator will have all the same methods as IValidator, so it can go away and we can just use IValidator in both instances.

Files changed in fix:
bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/BindSpec.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/DataBindingContext.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/DefaultBindSpec.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/DefaultBindSupportFactory.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/IValidator.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ObjectToPrimitiveValidator.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ReadOnlyValidator.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/RegexStringValidator.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2BytePrimitiveValidator.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DateValidator.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DoublePrimitiveValidator.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2FloatPrimitiveValidator.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2IntegerPrimitiveValidator.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2LongPrimitiveValidator.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ShortPrimitiveValidator.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValueBinding.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Adventure.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet004DataBindingContextErrorLabel.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet008ComputedValue.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/internal/databinding/provisional/factories/AbstractBindSupportFactoryTest.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/internal/databinding/provisional/validation/ObjectToPrimitiveValidatorTest.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindSpecTests.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/DatabindingContextTest.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/PropertyScenarios.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/internal/ValueBindingTest.java