net.sf.jzeno.echo.databinding
Class BoundListModel

java.lang.Object
  extended by net.sf.jzeno.echo.databinding.BoundListModel
All Implemented Interfaces:
java.io.Serializable, ListModel

public final class BoundListModel
extends java.lang.Object
implements ListModel, java.io.Serializable

Implementation of the ListModel that can be bound to a list of domain model javabeans. It is typically used in components like the DynaListBox. It allows you to specify which property on each individual model bean is used to visualize the beans in a list. You can do this by using setLabelProperty() . The list of javabeans are specified through the setList() method.

See Also:
Serialized Form

Constructor Summary
BoundListModel()
           Default constructor.
BoundListModel(java.util.Collection list, java.lang.String labelProperty)
           A shortcut constructor that allows you to specify the list of javabeans and the labelproperty to use for representation in the user interface.
 
Method Summary
 void addListDataListener(ListDataListener l)
           A method for registering ListDataListeners.
protected  void fireContentsChanged(java.lang.Object source, int index0, int index1)
           
 java.lang.Object get(int index)
           Retrieves one of the javabeans based on it's index in the list of beans.
 java.util.Comparator getComparator()
           
 Decorator getDecorator()
           
 java.lang.String getEmptySelectionLabel()
           
protected  java.lang.String getLabelForBean(java.lang.Object bean)
           Internal helper operation that retrieves the visual text that represents one of the javabeans.
 java.lang.String getLabelProperty()
           Gets the property of the java beans in the list, that is used for visualisation.
 java.util.List getList()
           
 java.lang.String getNullLabel()
           Gets the null label.
 void removeListDataListener(ListDataListener l)
           A method for unregistering ListDataListeners.
 void setComparator(java.util.Comparator comparator)
           
 void setDecorator(Decorator decorator)
           A decorator can be used to process the visualisation of the label.
 void setEmptySelectionLabel(java.lang.String emptySelectionLabel)
           Sets the label to visualize if the list of javabeans that was set, is empty.
 void setLabelProperty(java.lang.String labelProperty)
           Sets the property that will be used for visualizing the javabeans.
 void setList(java.util.List list)
           Sets the list of javabeans to be visualized.
 void setNullLabel(java.lang.String nullLabel)
           The nullLabel is the label that will be in the list of possible options (at the top) that corresponds to a selection of null.
 int size()
           Retrieves the number of elements in the list as returned by getList(), and as accessible through get().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoundListModel

public BoundListModel()

Default constructor. If you use this constructor the label-property and the list of javabeans must be specified by calling the right methods after construction.


BoundListModel

public BoundListModel(java.util.Collection list,
                      java.lang.String labelProperty)

A shortcut constructor that allows you to specify the list of javabeans and the labelproperty to use for representation in the user interface.

Parameters:
list - the list of javabeans.
labelProperty - the property on each individual model javabean to use for visualisation.
Method Detail

addListDataListener

public void addListDataListener(ListDataListener l)

A method for registering ListDataListeners. It is not recomended to provide your own listeners. In essence the databound components in jZeno will take care of the details of updating the model/etc...

A concrete example is the fact that a DynaListBox component is itself the ListDataListener for the model it uses.

Specified by:
addListDataListener in interface ListModel
Parameters:
l - The ListDataListener to be added.

removeListDataListener

public void removeListDataListener(ListDataListener l)

A method for unregistering ListDataListeners. It is not recomended to register/unregister your own listeners.

Specified by:
removeListDataListener in interface ListModel
Parameters:
l - The ListDataListener to be removed.

fireContentsChanged

protected void fireContentsChanged(java.lang.Object source,
                                   int index0,
                                   int index1)

get

public java.lang.Object get(int index)

Retrieves one of the javabeans based on it's index in the list of beans.

It is important to realize that if the nullLabel property is specified, that the list of javabeans is extended with an object to represent that null selection, and that this selection will be index 0 in the list. Hence all indexes will have shifted with 1 index.

If the emptySelectionLabel property is set, and the list of javabenas that is set (@see setList()) is empty, then the list returned by getList() will contain 1 item. And the operation will succeed for index 0 !

Specified by:
get in interface ListModel
Parameters:
index - the index to retrieve.
Returns:
the object at the specified index.

getLabelForBean

protected java.lang.String getLabelForBean(java.lang.Object bean)

Internal helper operation that retrieves the visual text that represents one of the javabeans.

Parameters:
bean - the bean for which to determine the visual label.
Returns:
the label that will appear in the UI.

size

public int size()

Retrieves the number of elements in the list as returned by getList(), and as accessible through get().

It is important to realize the effect of a nullLabel. The nullLabel will add an item to this list !

Specified by:
size in interface ListModel
Returns:
The size of the list.

getLabelProperty

public java.lang.String getLabelProperty()

Gets the property of the java beans in the list, that is used for visualisation.


setLabelProperty

public void setLabelProperty(java.lang.String labelProperty)

Sets the property that will be used for visualizing the javabeans.


getList

public java.util.List getList()

setList

public void setList(java.util.List list)

Sets the list of javabeans to be visualized.


getDecorator

public Decorator getDecorator()

setDecorator

public void setDecorator(Decorator decorator)

A decorator can be used to process the visualisation of the label.

The object passed into this decorator depends on the labelProperty.

It is also important to realize that the object passed to the decorator can potentially be the nullLabel !


getNullLabel

public java.lang.String getNullLabel()

Gets the null label.


setNullLabel

public void setNullLabel(java.lang.String nullLabel)

The nullLabel is the label that will be in the list of possible options (at the top) that corresponds to a selection of null.

E.g. a DynaListBox will write a null to the databound property if it is selected. The otherway around means that this label will be selected by default of the databound property is null.


getEmptySelectionLabel

public java.lang.String getEmptySelectionLabel()

setEmptySelectionLabel

public void setEmptySelectionLabel(java.lang.String emptySelectionLabel)

Sets the label to visualize if the list of javabeans that was set, is empty.


setComparator

public void setComparator(java.util.Comparator comparator)

getComparator

public java.util.Comparator getComparator()