Advanced customization

Antoine Mischler edited this page Nov 28, 2013 · 5 revisions

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

Customizing the nodes used in FXForm2

The FactoryProvider

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

Customizing the DefaultFactoryProvider

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

The static way

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.

The local way

DefaultFactoryProvider provider = new DefaultFactoryProvider();
provider.addFactory(myHandler, myFactory);

Adapters: Customizing bindings in FXForm2

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.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.