-
Notifications
You must be signed in to change notification settings - Fork 50
Advanced customization
You are at the right place if you want to :
- customize the components used to edit your fields
- tweak the binding between the model and the view
- support type of fields that are not supported by default in FXForm2
Almost all nodes used in FXForm2 are created using FactoryProvider. A FactoryProvider is responsible for providing factories for all elements in your form.
FXForm2 uses 4 different factory providers for each kind of node (label, editor, tooltip, constraint messages). These providers have default values that should match almost all of your needs. However, you can use any FactoryProvider you want for each kind if you need, using the appropriate setters in FXForm.
| Kind | Default factory provider | Description |
|---|---|---|
| Labels | DefaultLabelFactoryProvider | A provider providing a LabelFactory |
| Editor | DefaultFactoryProvider | A customizable default provider |
| Tooltip | DefaultTooltipFactoryProvider | A provider providing a AutoHidableLabelFactory |
| Constraint messages | DefaultConstraintFactory | A provider providing a factory creating ConstraintLabel |
The DefaultFactoryProvider can be customized to add support for new type of elements or to customize the factories used for the default types.
You have two way to configure the DefaultFactoryProvider
DefaultFactoryProvider.addGlobalFactory(myHandler, myFactory)- myHandler is the ElementHandler performing the matching between a given element and myFactory
- myFactory is your factory that should be used when the handler matches This static configuration can be used to configure all forms created after that.
DefaultFactoryProvider provider = new DefaultFactoryProvider();
provider.addFactory(myHandler, myFactory);FXForm2 uses an Adapter to convert the data between a bean property and the property of the Node used in the view. Let's say you have a DoubleProperty in your bean and this property is bound to a TextField in the view. The TextField represents its content through a StringProperty. So FXForm has to know how the convert data between a DoubleProperty and a StringProperty.
To achieve this, FXForms use an AdapterProvider, which is responsible for providing the Adapter that can convert data between two properties type.
The default implementation of the AdapterProvider is the DefaultAdapterProvider which can be customized using the static method addGlobalAdapter and the instance method addAdapter to provide your own adapters. This can be your case if the type of your property is not in the default list of properties supported by FXForm or if you use a custom node to edit this property. This can also be used to customized the formatting and parsing for numbers for example.