Bidirectional binding with conversion
Michael Heinrichs
michael.heinrichs at oracle.com
Fri Dec 9 05:36:19 PST 2011
Hi,
comments see inlined.
- Michael
On 09.12.2011, at 13:43, Tom Schindl wrote:
> Am 09.12.11 12:25, schrieb Daniel Zwolenski:
>> Nice idea, I can see it being useful.
>>
>> Does it need to be limited to bidirectional bindings? Any reason unidirectional bindings cant use a converter too?
>>
>
> Correct I don't see a reason for that.
Unidirectional bindings are already capable of conversions. There are a number of convenient methods to format anything into a String and one can always create a custom binding to do more complex conversions. Bidirectional bindings do not allow custom bindings (yet).
>
>> I wonder if we need a way to detect the failed parsing/formatting? For example if we were converting a TextField.textProperty to a Number (or Date) and it couldn't be parsed, I reckon I'd want to highlight the field as an error. Maybe this could be done with a custom formatter, is that the best way though?
>
> Yes we should. Why don't we allow the method to return a type:
>
> public static ValueBinding bindBidirectional(Property<String>
> stringProperty, Property<?> otherProperty, Format format)
>
> public ValueBinding bindBidirectional(Property<?> other, Format format)
>
> class Binding {
> ObjectProperty<Status> status;
>
> public dispose() {
>
> }
>
> }
>
> We can then:
> a) Observe the status of the binding
> b) remove the need of the unbind method because we can dispose the
> binding
Observing the status of a binding is an interesting idea, but it does not fit the intend of bindings in the Property and Binding API. The only purpose of bidirectional bindings in this library is to keep two properties in-sync. And they have to be as light-weight as possible to allow huge amounts of them. There are many enhancements possible: input validation, lifecycle management, support for transactions etc. etc., but if they do not serve the main intent, they just add complexity, increase footprint and thus have to be solved elsewhere.
Relying on a dispose() method would force developers to keep track of references to bindings, if they want to unbind them eventually. Calling a static method with the two properties seems a lot more convenient to me.
>
> Tom
>
> --
> B e s t S o l u t i o n . a t EDV Systemhaus GmbH
> ------------------------------------------------------------------------
> tom schindl geschäftsführer/CEO
> ------------------------------------------------------------------------
> eduard-bodem-gasse 5-7/1 A-6020 innsbruck fax ++43 512 935833
> http://www.BestSolution.at phone ++43 512 935834
More information about the openjfx-dev
mailing list