org.springframework.richclient.form.binding.swing
Class AbstractListBinder

java.lang.Object
  extended by org.springframework.richclient.application.support.ApplicationServicesAccessor
      extended by org.springframework.richclient.form.binding.support.AbstractBinder
          extended by org.springframework.richclient.form.binding.swing.AbstractListBinder
All Implemented Interfaces:
Binder
Direct Known Subclasses:
ComboBoxBinder, ListBinder

public abstract class AbstractListBinder
extends AbstractBinder

Abstract base class for list bindings.

The property selectableItems is used as a source of list values. the value of selectableItems is converted to ListModel by using the conversion service

The items of selectableItems can be filtered by defining a constraint for filter and sorted by defining comparator. Dynamic filtering and sorting is supported if the values of filter or comparator implements Observable

Every value for selectableItems, filter and comparator can be defined for all created binding instances or by using a context map where the keys SELECTABLE_ITEMS_KEY, COMPARATOR_KEY and FILTER_KEY can be used for specifying the context dependent values.

If the context values of SELECTABLE_ITEMS_KEY, COMPARATOR_KEY and FILTER_KEY implement Closure it will be used to create the instance for the value by passing the value of selectableItems, filter or comparator as the argument.
Please take into account that the argument for the closure can be null if the property is not set. This feature is usefull to chain filter constraints.

Subclasses must implement createListBinding(JComponent, FormModel, String) which creates the instance for AbstractListBinding. applyContext(AbstractListBinding, Map) can be overwritten to apply additional context values

Author:
Mathias Broekelmann

Field Summary
static String COMPARATOR_KEY
          key for defining a context dependent comparator value that is used to sort the elements of selectableItems.
static String FILTER_KEY
          key for defining a context dependent filter constraint value that is used to filter the elements of selectableItems.
static String SELECTABLE_ITEMS_KEY
          key for defining a context dependent selectableItems value.
 
Fields inherited from class org.springframework.richclient.form.binding.support.AbstractBinder
BINDING_CLIENT_PROPERTY_KEY, log
 
Fields inherited from class org.springframework.richclient.application.support.ApplicationServicesAccessor
logger
 
Constructor Summary
AbstractListBinder(Class requiredSourceClass)
          Creates a new instance by defining a type for the form fields and using the default context keys SELECTABLE_ITEMS_KEY, COMPARATOR_KEY and FILTER_KEY
AbstractListBinder(Class requiredSourceClass, String[] supportedContextKeys)
          Creates a new instance by defining a type for the form fields and using the given context keys
 
Method Summary
protected  void applyContext(AbstractListBinding binding, Map context)
          Applies any context or preset value.
protected abstract  AbstractListBinding createListBinding(JComponent control, FormModel formModel, String formPropertyPath)
          Called to create the binding instance
protected  Object decorate(Object closure, Object object)
          Decorates an object instance if the closure value is an instance of Closure.
protected  Binding doBind(JComponent control, FormModel formModel, String formPropertyPath, Map context)
          Creates the binding and applies any context values
 Comparator getComparator()
          Returns the Comparator which is used for bindings.
 Constraint getFilter()
          Returns the Constraint which is used as a filter for the selectable items.
 Object getSelectableItems()
          Returns the selectable items which where used as a source for the selectable items.
 void setComparator(Comparator comparator)
          Defines the Comparator which is used for bindings.
 void setFilter(Constraint filter)
          Defines the Constraint which is used as a filter for the selectable items.
 void setSelectableItems(Object selectableItems)
          Defines the selectable items which where used as a source for the selectable items.
 
Methods inherited from class org.springframework.richclient.form.binding.support.AbstractBinder
bind, bind, createControl, getPropertyType, getRequiredSourceClass, validateContextKeys
 
Methods inherited from class org.springframework.richclient.application.support.ApplicationServicesAccessor
getActiveWindow, getApplication, getApplicationContext, getApplicationName, getApplicationServices, getCommandConfigurer, getComponentFactory, getConversionService, getIconSource, getImageSource, getMessage, getMessage, getMessage, getMessage, getMessages, getMessageSource, getObjectConfigurer, getService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SELECTABLE_ITEMS_KEY

public static final String SELECTABLE_ITEMS_KEY
key for defining a context dependent selectableItems value. See class description for details.

See Also:
Constant Field Values

COMPARATOR_KEY

public static final String COMPARATOR_KEY
key for defining a context dependent comparator value that is used to sort the elements of selectableItems. Values must be instances of Comparator. See class description for more details.

See Also:
Constant Field Values

FILTER_KEY

public static final String FILTER_KEY
key for defining a context dependent filter constraint value that is used to filter the elements of selectableItems. Values must be instances of Constraint. See class description for more details.

See Also:
Constant Field Values
Constructor Detail

AbstractListBinder

public AbstractListBinder(Class requiredSourceClass)
Creates a new instance by defining a type for the form fields and using the default context keys SELECTABLE_ITEMS_KEY, COMPARATOR_KEY and FILTER_KEY

Parameters:
requiredSourceClass - the type of the form fields to bind, if null form fields can have any type

AbstractListBinder

public AbstractListBinder(Class requiredSourceClass,
                          String[] supportedContextKeys)
Creates a new instance by defining a type for the form fields and using the given context keys

Parameters:
requiredSourceClass - the type of the form fields to bind, if null form fields can have any type
supportedContextKeys - the keys which can be defined as context values
Throws:
NullPointerException - if supportedContextKeys is null
Method Detail

getComparator

public Comparator getComparator()
Returns the Comparator which is used for bindings. The value can be overwritten with a context value for COMPARATOR_KEY

Returns:
the comparator. If null no comparator is defined

setComparator

public void setComparator(Comparator comparator)
Defines the Comparator which is used for bindings. The value can be overwritten with a context value for COMPARATOR_KEY

Parameters:
comparator - the comparator. If null no comparator will be used

getFilter

public Constraint getFilter()
Returns the Constraint which is used as a filter for the selectable items. The value can be overwritten with a context value for FILTER_KEY

Returns:
the filter. If null no filter is defined

setFilter

public void setFilter(Constraint filter)
Defines the Constraint which is used as a filter for the selectable items. The value can be overwritten with a context value for FILTER_KEY

Parameters:
filter - the filter constraint. If null no filter will be used

getSelectableItems

public Object getSelectableItems()
Returns the selectable items which where used as a source for the selectable items. The value can be overwritten with a context value for SELECTABLE_ITEMS_KEY

Returns:
the selectable items. If null no selectable items will be used

setSelectableItems

public void setSelectableItems(Object selectableItems)
Defines the selectable items which where used as a source for the selectable items. The value can be overwritten with a context value for SELECTABLE_ITEMS_KEY

Parameters:
selectableItems - the selectable items. If null no selectable items will be used

doBind

protected final Binding doBind(JComponent control,
                               FormModel formModel,
                               String formPropertyPath,
                               Map context)
Creates the binding and applies any context values

Specified by:
doBind in class AbstractBinder

createListBinding

protected abstract AbstractListBinding createListBinding(JComponent control,
                                                         FormModel formModel,
                                                         String formPropertyPath)
Called to create the binding instance

Parameters:
control - the control to bind
formModel - the formmodel with the value of the formPropertyPath field
formPropertyPath - the field path to bind
Returns:
the binding instance. Must not be null

applyContext

protected void applyContext(AbstractListBinding binding,
                            Map context)
Applies any context or preset value.

Parameters:
binding - the binding to apply the values
context - contains context dependent values

decorate

protected Object decorate(Object closure,
                          Object object)
Decorates an object instance if the closure value is an instance of Closure.

Parameters:
closure - the closure which is used to decorate the object.
object - the value to decorate
Returns:
the decorated instance if closure implements Closure, otherwise the value of object


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.