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

Show UML class diagram
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.ShuttleListBinder
All Implemented Interfaces:
Binder

public class ShuttleListBinder
extends AbstractBinder

Binder for handling ShuttleList component. Use the following keys to configure the produced binding:

SELECTABLE_ITEMS_HOLDER_KEY
to specify the list of "available" source values (this may be a Collection or an array).

SELECTED_ITEMS_HOLDER_KEY
to specify the value holder into which the selected items will be placed (this may be a Collection or an array). Initially, this set must contain only values that exist in the selectable set.

SELECTED_ITEM_TYPE_KEY
to specify the underlying type of the elements in the selected and selectable value sets.

COMPARATOR_KEY
to specify the Comparator to use for comparing elements in the selected and selectable value sets.

RENDERER_KEY
to specify the a ListCellRenderer for elements of the value sets. This is typically used if the String value of the elements is not appropriate for use in the shuttle lists.

FORM_ID
to specify formId in which this ShuttleList appears, this allow form-specific settings like the texts and icon.
In order to have this Binder selected properly when adding ShuttleList components to a form, you will need to have the following context configuration:
 <bean id="binderSelectionStrategy" class="org.springframework.richclient.form.binding.swing.SwingBinderSelectionStrategy">
     <property name="bindersForControlTypes">
         <map>
             <entry>
                 <key>
                     <value type="java.lang.Class">org.springframework.richclient.components.ShuttleList</value>
                 </key>
                 <bean class="org.springframework.richclient.components.ShuttleListBinder" />
             </entry>
         </map>
     </property>
 </bean>
 

Also, see SwingBindingFactoryProvider and SwingBindingFactoryProvider for how to configure and use that binding factory, which offers convenience methods for constructing a bound shuttle list. With the provider, factory, and binder registered, the following code can be used to add a bound shuttle list to a form:

 final SandboxSwingBindingFactory bf = (SandboxSwingBindingFactory) getBindingFactory();
 TableFormBuilder formBuilder = new TableFormBuilder( bf );
 ...
 String[] languages = new String[] { "java", "perl", "ruby", "C#" };
 List languagesList = Arrays.asList( languages ); 
 formBuilder.add( bf.createBoundShuttleList( "languageSkills", languagesList ), "align=left" );
 

Author:
Larry Streepy, Benoit Xhenseval

Field Summary
static String COMPARATOR_KEY
           
static String FORM_ID
           
static String MODEL_KEY
           
static String RENDERER_KEY
           
static String SELECTABLE_ITEMS_HOLDER_KEY
           
static String SELECTED_ITEM_TYPE_KEY
           
static String SELECTED_ITEMS_HOLDER_KEY
           
 
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
  ShuttleListBinder()
          Constructor.
protected ShuttleListBinder(String[] supportedContextKeys)
          Constructor allowing the specification of additional/alternate context keys.
 
Method Summary
protected  void applyContext(ShuttleListBinding binding, Map context)
          Apply the values from the context to the specified binding.
static Map createBindingContext(FormModel formModel, String selectionFormProperty, ValueModel selectableItemsHolder, String renderedProperty)
          Utility method to construct the context map used to configure instances of ShuttleListBinding created by this binder.
protected  JComponent createControl(Map context)
           
protected  Binding doBind(JComponent control, FormModel formModel, String formPropertyPath, Map context)
           
 void setShowEditButton(boolean showEditButton)
           
 
Methods inherited from class org.springframework.richclient.form.binding.support.AbstractBinder
bind, bind, 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_HOLDER_KEY

public static final String SELECTABLE_ITEMS_HOLDER_KEY
See Also:
Constant Field Values

SELECTED_ITEMS_HOLDER_KEY

public static final String SELECTED_ITEMS_HOLDER_KEY
See Also:
Constant Field Values

SELECTED_ITEM_TYPE_KEY

public static final String SELECTED_ITEM_TYPE_KEY
See Also:
Constant Field Values

MODEL_KEY

public static final String MODEL_KEY
See Also:
Constant Field Values

FORM_ID

public static final String FORM_ID
See Also:
Constant Field Values

COMPARATOR_KEY

public static final String COMPARATOR_KEY
See Also:
Constant Field Values

RENDERER_KEY

public static final String RENDERER_KEY
See Also:
Constant Field Values
Constructor Detail

ShuttleListBinder

public ShuttleListBinder()
Constructor.


ShuttleListBinder

protected ShuttleListBinder(String[] supportedContextKeys)
Constructor allowing the specification of additional/alternate context keys. This is for use by derived classes.

Parameters:
supportedContextKeys - Context keys supported by subclass
Method Detail

setShowEditButton

public void setShowEditButton(boolean showEditButton)

createBindingContext

public static Map createBindingContext(FormModel formModel,
                                       String selectionFormProperty,
                                       ValueModel selectableItemsHolder,
                                       String renderedProperty)
Utility method to construct the context map used to configure instances of ShuttleListBinding created by this binder.

Binds the values specified in the collection contained within selectableItemsHolder to a ShuttleList, with any user selection being placed in the form property referred to by selectionFormProperty. Each item in the list will be rendered by looking up a property on the item by the name contained in renderedProperty, retrieving the value of the property, and rendering that value in the UI.

Note that the selection in the bound list will track any changes to the selectionFormProperty. This is especially useful to preselect items in the list - if selectionFormProperty is not empty when the list is bound, then its content will be used for the initial selection.

Parameters:
selectionFormProperty - form property to hold user's selection. This property must be a Collection or array type.
selectableItemsHolder - ValueModel containing the items with which to populate the list.
renderedProperty - the property to be queried for each item in the list, the result of which will be used to render that item in the UI. May be null, in which case the selectable items will be rendered as strings.

doBind

protected Binding doBind(JComponent control,
                         FormModel formModel,
                         String formPropertyPath,
                         Map context)
Specified by:
doBind in class AbstractBinder

applyContext

protected void applyContext(ShuttleListBinding binding,
                            Map context)
Apply the values from the context to the specified binding.

Parameters:
binding - Binding to update
context - Map of context values to apply to the binding

createControl

protected JComponent createControl(Map context)
Specified by:
createControl in class AbstractBinder


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