JavaGantt 2011.1 API

eu.beesoft.gaia.swing.builder
Class SwingBuilder<T>

java.lang.Object
  extended by eu.beesoft.gaia.util.ObjectBuilder<T>
      extended by eu.beesoft.gaia.swing.builder.SwingBuilder<T>
Type Parameters:
T - class of object created by this builder
Direct Known Subclasses:
ActionBuilder, ComponentBuilder, ListModelBuilder, TableColumnBuilder

public abstract class SwingBuilder<T>
extends ObjectBuilder<T>

Abstract superclass of all Swing-related object builders. It supports data binding.

Data binding assumes that there is one root data object for displayed form. Another objects are referenced from it or from objects referenced by it. So the object hierarchy is requested in bound data.

The binding for builder (and its object / component) is recorded in source XML file (as an attribute 'binding'). SwingBuilder uses this algorithm to bind a specific data property to component created by it:

  1. it is looking for getter / setter
  2. tries a field access
  3. if property container is an instance of ValueObject, it uses get / set method
  4. throws exception if property is not accessible

The binding for builder (and its object / component) is recorded in source XML file (as an attribute 'binding'). You can use also so called dot-convention: if your object references via property a object A, object A references via property b object B, and you want to display property c of that object, you can write binding as a.b.c - it is easy.


Constructor Summary
SwingBuilder()
           
 
Method Summary
protected  java.lang.Object convertValue(java.lang.Object value, java.lang.Class<?> targetClass, java.lang.String fullBinding)
          Converts given value to requested type.
protected  java.lang.Object createBoundData(java.lang.String binding)
          Creates a new data object for given binding.
protected  java.lang.Object findBoundData(java.lang.String fullBinding, SwingBuilder<?> caller)
          Returns an object that is addressed with given binding.
protected  java.util.List<SwingBuilder<?>> getBindableChildren()
          Retuns a list of all children - builders that support data binding.
 java.lang.String getBinding()
          Returns this bulder binding.
 java.lang.Object getBoundData(java.util.Set<java.lang.Object> changedObjects, java.lang.String fullBinding)
          Returns data from builder's object.
protected  java.lang.Object getBoundValueFromComponent(java.util.Set<java.lang.Object> changedObjects, java.lang.String fullBinding)
          Gets data value from the component created by this builder.
protected  java.lang.String getPropertyFromResourceBundle(java.lang.String name)
          Returns property value for given name from the current resource bundle.
protected  java.lang.Object getValueFromBoundObject(java.lang.Object object, java.lang.String propertyName, java.lang.String fullBinding)
          Returns a value from given data object and given property.
protected  void initBinding(java.lang.String value)
          Initializes property binding (stores it to the instance variable).
protected  boolean isBindable()
          Returns true if binding !
protected  java.awt.Dimension parseDimension(java.lang.String value)
          Helper method to convert given String to java.awt.Dimension object.
 void setBoundData(java.lang.Object data, java.lang.String fullBinding)
          Sets given data to component created by this builder.
protected  void setBoundValueToComponent(java.lang.Object value, java.lang.String fullBinding)
          Sets given data value to the component created by this builder.
protected  void setValueToBoundObject(java.lang.Object object, java.lang.String propertyName, java.lang.Object value, java.lang.String fullBinding)
          Sets a value to a given property of the given object.
 
Methods inherited from class eu.beesoft.gaia.util.ObjectBuilder
addChild, createObject, createObject, getFactory, getChildren, getId, getObject, getParent, getProperties, getProperty, initClass, initId, initObjectProperties, initObjectProperty, parseBoolean, parseClass, parseConstant, parseConstructor, parseDouble, parseInstance, parseInstance, parseInt, parseInt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwingBuilder

public SwingBuilder()
Method Detail

parseDimension

protected java.awt.Dimension parseDimension(java.lang.String value)
Helper method to convert given String to java.awt.Dimension object. String must have a form [int, int], for example "3, 5".

Parameters:
value - - string to convert
Returns:
created Dimension object

getPropertyFromResourceBundle

protected java.lang.String getPropertyFromResourceBundle(java.lang.String name)
Returns property value for given name from the current resource bundle.

Parameters:
name - - name of the property to finf
Returns:
property value for given name

initBinding

protected void initBinding(java.lang.String value)
Initializes property binding (stores it to the instance variable). Given value is a a name of the property, which should be displayed by builder's object (component).

Parameters:
value - - value from according attribute in XML to initialize this property

getBinding

public java.lang.String getBinding()
Returns this bulder binding.

Returns:
binding

isBindable

protected boolean isBindable()
Returns true if binding != null.

Returns:
true if binding != null

getBindableChildren

protected java.util.List<SwingBuilder<?>> getBindableChildren()
Retuns a list of all children - builders that support data binding.

Returns:
list of all bindable children

setBoundData

public void setBoundData(java.lang.Object data,
                         java.lang.String fullBinding)
Sets given data to component created by this builder. This method calls setBoundValueToComponent(Object, String).

Parameters:
data - - data to set
fullBinding - - qualified path from root of data to given data

getBoundData

public java.lang.Object getBoundData(java.util.Set<java.lang.Object> changedObjects,
                                     java.lang.String fullBinding)
Returns data from builder's object.

Parameters:
changedObjects - - a collection of data object's changed by user
fullBinding - - qualified path from root of data to given data
Returns:
data object (with possible changed properties) set to this builder by method setBoundData(Object, String).

createBoundData

protected java.lang.Object createBoundData(java.lang.String binding)
Creates a new data object for given binding.

This method is invoked from getBoundData(Set, String) method, when is processed a property chain with null objects in the middle and changed value at last property (for example, you have binding a.b.c, object for b is null and user changed property c in UI - then is necessary to create object for b property to create full chain).

This implementation throws RuntimeException to notify programmer to override it.

Parameters:
binding - - binding for which should be created object
Returns:
newly created object

findBoundData

protected java.lang.Object findBoundData(java.lang.String fullBinding,
                                         SwingBuilder<?> caller)
Returns an object that is addressed with given binding.

Parameters:
fullBinding - - binding for finding of object
caller - - instance of SwingBuilder which invoked this method
Returns:
object for given binding

getValueFromBoundObject

protected java.lang.Object getValueFromBoundObject(java.lang.Object object,
                                                   java.lang.String propertyName,
                                                   java.lang.String fullBinding)
Returns a value from given data object and given property. It obtains it in this order:
  1. checks for getter to invocation
  2. check for field to get value
  3. if given object is ValueObject, gets its property with given name
  4. throws RuntimeException if no access to requested property was found

Parameters:
object - - source of requested data
propertyName - - name of the requested property
fullBinding - - information about qualified binding from root of the form
Returns:
object from given property
Throws:
java.lang.RuntimeException - if property with given name cannot be accessed

setValueToBoundObject

protected void setValueToBoundObject(java.lang.Object object,
                                     java.lang.String propertyName,
                                     java.lang.Object value,
                                     java.lang.String fullBinding)
Sets a value to a given property of the given object. It does it in this order:
  1. checks for setter to invocation
  2. check for field to set value
  3. if given object is ValueObject, sets its property with given name
  4. throws RuntimeException if no access to requested property was found

Parameters:
object - - container for given value
propertyName - - name of the property
value - - value to set
fullBinding - - information about qualified binding from root of the form
Throws:
java.lang.RuntimeException - if property with given name cannot be accessed

setBoundValueToComponent

protected void setBoundValueToComponent(java.lang.Object value,
                                        java.lang.String fullBinding)
Sets given data value to the component created by this builder. Override this method for specific component. This implementation simply throws RuntimeException to notify programmer about a necessity to override this method.

Parameters:
value - - a value to set
fullBinding - - binding to given value from root form object

getBoundValueFromComponent

protected java.lang.Object getBoundValueFromComponent(java.util.Set<java.lang.Object> changedObjects,
                                                      java.lang.String fullBinding)
Gets data value from the component created by this builder. Override this method for specific component. This implementation simply throws RuntimeException to notify programmer about a necessity to override this method.

Parameters:
changedObjects - - collection of changed data objects, add your data object to this if your component's value was changed by user
fullBinding - - binding to component's value from root form object
Returns:
value from component's object

convertValue

protected java.lang.Object convertValue(java.lang.Object value,
                                        java.lang.Class<?> targetClass,
                                        java.lang.String fullBinding)
Converts given value to requested type.

Parameters:
value - - a value to convert
targetClass - - a type to which should be given value converted
fullBinding - - binding to given value from root form object
Returns:
converted value

JavaGantt 2011.1 API