This chapter covers each WidgetProcessor in detail. For an explanation of
how WidgetProcessors fit into the overall architecture of Metawidget, see
Chapter 2, Architecture.
Swing does not include an automatic JComponent to Object binding mechanism, but Metawidget
supports third-party alternatives via addWidgetProcessor.
BeansBindingProcessor binds properties using Beans Binding (JSR 295). It supports the various
Beans Binding update strategies:
myMetawidget.addWidgetProcessor( new BeansBindingProcessor( new BeansBindingProcessorConfig() .setUpdateStrategy( UpdateStrategy.READ )) );
If set to READ or READ_WRITE (the default is
READ_ONCE), the object being inspected must
provide PropertyChangeSupport. If set to READ_WRITE, updates
to the UI are automatically sync'ed back to the setToInspect, otherwise the
client must manually call save:
myMetawidget.getWidgetProcessor( BeansBindingProcessor.class ).save( myMetawidget )
After JComponents have been generated for the initial setToInspect, clients
can update their values to a new Object without a full re-inspection by using rebind:
myMetawidget.getWidgetProcessor( BeansBindingProcessor.class ).rebind( newObject, myMetawidget )For more details, see Section 10.3, “Rebinding”.
BeanUtilsProcessor binds properties using
Apache BeanUtils. It supports JavaBean
and Scala property styles:
myMetawidget.addWidgetProcessor( new BeanUtilsBindingProcessor( new BeanUtilsBindingProcessorConfig() .setPropertyStyle( BeanUtilsBindingProcessorConfig.PROPERTYSTYLE_SCALA )) );
Updates to the UI can be saved back to the setToInspect by calling save:
myMetawidget.getWidgetProcessor( BeanUtilsBindingProcessor.class ).save( myMetawidget )
After JComponents have been generated for the initial setToInspect, clients
can update their values to a new Object without a full re-inspection by using rebind:
myMetawidget.getWidgetProcessor( BeanUtilsBindingProcessor.class ).rebind( newObject, myMetawidget )For more details, see Section 10.3, “Rebinding”.
Swing supplies javax.swing.Action for binding JButtons to backing classes, and this is
typically combined with Java-based reflection to support runtime binding. This is exactly what the default action binding,
ReflectionBinding, does.
However, Metawidget makes action bindings pluggable to support other use cases. In particular, use cases where there
is no backing class, and instead the JButton should invoke, say, an RPC
call. Implement your own pluggable binding by extending BaseWidgetProcessor and use it by calling:
myMetawidget.addWidgetProcessor( new MyWidgetProcessor() );