@Retention(value=SOURCE) @Target(value=TYPE) public static @interface FXBeanInfo.Generate
FXBeanInfo.Provider
and its FXBeanInfo
rather than
constructing it manually. Classical way of
creating FXBeanInfo
is to use the FXBeanInfo.Builder
and
manually specify each property
and action
attributes.
FXBeanInfo
FXBeanInfo.Generate
annotation. Annotate your bean class
with this annotation and make it extend non-existing(!) super
class. That class is going to be automatically generated during compilation.
It will implement FXBeanInfo.Provider
and return a FXBeanInfo
based on the fields and methods of your class.
@FXBeanInfo
.Generate class Empty extends EmptyBeanInfo { public Empty() { assert this instanceofFXBeanInfo
.Provider; assert getFXBeanInfo() != null; } }
ReadOnlyProperty
interface. All non-private and final
fields
of your class are going to be registered. Derived properties are registered
as bindings providing an ObservableValue
. Constant properties
are simple fields like int
, double
or String
.
@All fields have to beFXBeanInfo
.Generate class Properties extends PropertiesBeanInfo { finalStringProperty
word = newSimpleStringProperty
(this, "name"); finalIntegerProperty
count = newSimpleIntegerProperty
(this, "count"); final boolean upperCase; finalObservableValue
<String
> sentence; public Properties(boolean upperCase) { this.upperCase = upperCase; this.sentence =Bindings
.createStringBinding(() -> {StringBuilder
sb = newStringBuilder
(); for (int i = 0; i < count.get(); i++) { sb.append(word.get()); }String
text = sb.toString(); return upperCase ? text.toUpperCase() : text; }, word, count);FXBeanInfo
info = getFXBeanInfo();Map
<String
,ObservableValue
<?>> p = info.getProperties(); assert p.get("word") != null; assert p.get("count") != null; assert p.get("upperCase") != null; assert p.get("sentence") != null; } }
final
and must not be private
!
void
and accept no arguments or a single ActionEvent
or ActionDataEvent
argument.
@Avoid overloaded methods. Only one name can be used for an action and property per bean class.FXBeanInfo
.Generate class Actions extends ActionsBeanInfo { void init() { } void onAction(ActionEvent
ev) { } void onActionWithData(ActionDataEvent
ev) { } Actions() {FXBeanInfo
info = getFXBeanInfo();Map
<String
,EventHandlerProperty
> a = info.getActions(); assert a.get("init") != null; assert a.get("onAction") != null; assert a.get("onActionWithData") != null; } }
Copyright © 2020. All rights reserved.