Search |
||||
Evan Summers's blogAutomatic BindingPosted by evanx on September 1, 2008 at 10:55 AM PDT
In the Gooey MvnC prequel, we advocate an MVC-type architecture for programming a Swing UI panel, using convention-over-configuration to automate event handling, thread switching and beans binding. In the Gooey Event Proxy prequel, we introduced a minimalistic helper class towards the above strategy, illustrating the automatic wiring of events, for starters. Now we present automatic binding by convention-over-configuration, in order to bind components in the view to properties in the presentation model, automatically, by matching component names to property names.
Our helper binds components to bean properties as follows.
where GBeanInfo and GPropertyInfo are wrappers for java.beans.BeanInfo
and PropertyDescriptor, and GBeanProperty ties in a reference to
a bean instance.
For example, GTextFieldBinding below is used to establish a binding
between a JTextField and a bean property.
where the binding implements various listeners, and registers itself
as a listener on the component's events eg. FocusEvent, and
also as a PropertyChangeListener on the bean property.
In the focusLost() event handler below, we push the edited value into
the bean property.
In propertyChange() below, we invoke updateComponent()
to pull the value from the bean into the component.
The full article is reposited
here. »
Related Topics >>
Java Desktop Comments
Comments are listed in date ascending order (oldest first)
|
CategoriesArchivesOctober 2008
September 2008 August 2008 July 2008 June 2008 May 2008 April 2008 March 2008 January 2008 November 2007 October 2007 September 2007 August 2007 July 2007 June 2007 May 2007 April 2007 March 2007 February 2007 January 2007 December 2006 November 2006 October 2006 September 2006 August 2006 July 2006 June 2006 May 2006 Recent Entries |
|||
|
|