Controls with Values [was Possible additions to JavaFX to facilitate forms and validations]
Daniel Zwolenski
zonski at googlemail.com
Mon Dec 12 14:13:06 PST 2011
>
> I wonder if there is some other solution to the problem? Could we instead
>> use an annotation to indicate what property on a control is the "data
>> model" for the control? Annotations are by far the easiest reflection API
>> to use IMO, so it isn't unreasonable for tools to resort to annotations (in
>> fact, toolability is one of the primary use cases for an annotation). So
>> what about something like @ValueProperty in javafx.scene.control, and we
>> can then apply it to whatever property on the control is to be considered
>> the "value" of the control?
>>
>
> If you're only going to use this for tooling, I think it looks like a
> clean solution.
>
> However, it won't let you abstract over the controls' "valuePropoperty"'s
> common methods, as in:
>
> InvalidationListener il = new InvalidationListener { ... }
>
> List<ValueControl> controls = Arrays.asList(textField1, textField2,
> choiceBox, toggleGroup, listView)
>
> for (ValueControl control : controls) {
> control.valueProperty.**addListener(il)
> }
>
> It can of course be discussed whether there is a good use-case for this.
>
> (Yes, I know ToggleGroup is not a Control, but I think conceptually it
> should be.)
>
>
True, but you could do it like this:
InvalidationListener il = new InvalidationListener { ... }
List<Control> controls = Arrays.asList(textField1, textField2, choiceBox,
toggleGroup, listView)
for (ValueControl control : controls) {
ValuePropertyHelper.getValueProperty(control).addListener(li);
}
Where ValuePropertyHelper is a class (preferably part of JFX) that finds
the field annotated with @ValueProperty property on the Control.
Works for me anyway, and doesn't clutter the Control API with duplicate
fields for the same thing.
More information about the openjfx-dev
mailing list