Controls with Values [was Possible additions to JavaFX to facilitate forms and validations]
richard.bair at oracle.com
Tue Dec 6 09:02:46 PST 2011
> > Oh, I just had a crazy idea. What if we just reused WritableValue? Have value holding controls implement WritableValue. Hmmm.
> That's not so crazy. Actually, I proposed it in the forum thread. :) (Ok, I proposed ObservableValue.)
Oh, you probably gave the idea to me sub-consciously :-)
> There's a set of interfaces that may be considered for this.
> The simplest would be Observable. That gives you add/remove listener. Since these are not parameterized, you could have a List<Control> and call them on each item.
> Next up is ObservableValue/WritableValue, which gives you getValue/+setValue.
> Since these are parameterized, you won't be able to iterate through a List<Control<T>> and use them on each item without casting; could be useful still.
> Lastly, Property, which gives you the binding methods as well.
> In that case, i.e. class Control<T> implements Property<T>, the control would *be* the property for the value it holds, i.e. instead of textField.textProperty.bind(someObservable) you could do textField.bind(someObservable). The actual methods could just could be proxies to the control-specific value property.
> (This is what would be compatible with zonski's original proposal.)
> I'm not sure how much it gives though, since most controls will hold different datatypes so you can't really abstract over them.
> Just some quick thoughts.
From a naming perspective, the idea that TextField would implement property seems wrong, although the idea of binding a TextField to something directly seems great (we had similar API in SwingLabs back in the day for a set of data-aware components I was experimenting with). It takes thinking of a Control a little differently -- in addition to being a thing with a bunch of state, it is also, fundamentally, used for displaying and editing a value. It still wouldn't be what we would call a "Property" in the meaning of the word, but the Property interface does express the API that could be useful in this context.
More information about the openjfx-dev