com.taursys.model
Interface SelectModel

All Superinterfaces:
TextModel
All Known Implementing Classes:
DefaultSelectModel

public interface SelectModel
extends TextModel

Model interface which holds a list of options and the selected item. This model can be used in a variety of ways. It can be used in an un-bound mode, where the current selection is maintained internally. It can also be used in a bound mode where the current selection is propagated to a value holder. When used in the bound mode, either a single property, or multiple properties can be set in the value holder.

The following sections describe the required settings to make for each of the modes.

Un-bound Mode

To use this component in the un-bound mode, you can set the following properties:

Bound Mode

To use this component in the bound mode, use the same properties as described in the Un-bound Mode, plus the following additional properties:

Setting the List

The List must be a CollectionValueHolder. The holder can contain any type of object (but they must all be instances of the same class).

The List can be any type of CollectionValueHolder such as VOCollectionValueHolder or VOListValueHolder.

If the List is an ObjectArrayValueHolderList, then the toString() method is used as the display value (regardless of the displayPropertyName). If used in the bound mode, the whole object itself is stored in the target ValueHolder's object (regardless of the properties names listed in the setListPropertyNames method).

You can also preset the list in the constructor by passing it an array of Objects to be used for the List. The resulting List will be an ObjectArrayValueHolderList.

Other Important Information

When a selection is made, the values are copied from the properties in the list to the properties in the valueHolder object. The property names in propertyNames[] and listPropertyNames[] must appear in a corresponding order.

A "null" item will always be added to the listDisplay. When the "null" item is selected, a null will be assigned to the propertyNames[] in the valueHolder object. The actual "null" item to to display is defined by the nullDisplay (default is "--none--").

The format and pattern govern the display property in this component. The getText method returns the formatted display property, while the setText method changes the current selection to one whose display matches the given value. If you attempt to setText for an item that is not in the list, a NotInListException will be thrown.


Method Summary
 java.util.Collection getDisplayOptionList()
          Returns a Collection of the SelectModelOptions.
 java.lang.String getDisplayPropertyName()
          Returns the property name of the list object to display in the list.
 CollectionValueHolder getList()
          Returns collectionValueHolder which holds the collection of possible selections.
 java.lang.String[] getListPropertyNames()
          Returns array of property names in list object to copy to valueHolder object.
 java.lang.String getNullDisplay()
          Returns value to display in list for a null value.
 java.lang.String[] getPropertyNames()
          Sets array of property names in valueHolder object that correspond to properties of list object.
 java.lang.Object getSelectedItem()
          Returns the currently selected item from the list.
 boolean isNullAllowed()
          Returns indicator that a null value is a valid selection.
 void setDisplayPropertyName(java.lang.String newDisplayPropertyName)
          Sets the property name of the list object to display in the list.
 void setList(CollectionValueHolder newList)
          Sets collectionValueHolder which holds the collection of possible selections.
 void setListPropertyNames(java.lang.String[] newListPropertyNames)
          Sets array of property names in list object to copy to valueHolder object.
 void setNullAllowed(boolean newNullAllowed)
          Sets indicator that a null value is a valid selection.
 void setNullDisplay(java.lang.String newNullDisplay)
          Sets value to display in list for a null value.
 void setPropertyNames(java.lang.String[] newPropertyNames)
          Sets array of property names in valueHolder object that correspond to properties of list object.
 void setSelectedItem(java.lang.Object value)
          Sets the current selection by searching through the list for the given object.
 
Methods inherited from interface com.taursys.model.TextModel
addChangeListener, getFormat, getFormatPattern, getPropertyName, getText, getValueHolder, removeChangeListener, setFormat, setFormatPattern, setPropertyName, setText, setValueHolder
 

Method Detail

getDisplayOptionList

public java.util.Collection getDisplayOptionList()
                                          throws ModelException
Returns a Collection of the SelectModelOptions. The SelectModelOption has 2 properties: optionText which is the value to display in the list and selected, which indicates whether or not the item is selected.

The nullDisplay value will be first in the collection.

Throws:
ModelException - if problem while matching properties of valueHolder object to list object.

getSelectedItem

public java.lang.Object getSelectedItem()
                                 throws ModelException
Returns the currently selected item from the list.

Throws:
NotInListException - if current valueHolder object values do not match any item in list.
ModelException - if problem while matching properties of valueHolder object to list object.

setSelectedItem

public void setSelectedItem(java.lang.Object value)
                     throws ModelException
Sets the current selection by searching through the list for the given object. This method also copies the corresponding values from the selected list object to the valueHolder object. If the given value is null or a value matching the nullDisplay, this model will set the propertyNames[] in the valueHolder object to null.

Throws:
NotInListException - if the given value does not match any item in list.
ModelException - if problem while setting properties of object in valueHolder or fetching display values from the list.

setList

public void setList(CollectionValueHolder newList)
Sets collectionValueHolder which holds the collection of possible selections.


getList

public CollectionValueHolder getList()
Returns collectionValueHolder which holds the collection of possible selections.


setDisplayPropertyName

public void setDisplayPropertyName(java.lang.String newDisplayPropertyName)
Sets the property name of the list object to display in the list. Default is "value".


getDisplayPropertyName

public java.lang.String getDisplayPropertyName()
Returns the property name of the list object to display in the list. Default is "value".


setListPropertyNames

public void setListPropertyNames(java.lang.String[] newListPropertyNames)
Sets array of property names in list object to copy to valueHolder object. Default is {"value"}.


getListPropertyNames

public java.lang.String[] getListPropertyNames()
Returns array of property names in list object to copy to valueHolder object. Default is {"value"}.


setPropertyNames

public void setPropertyNames(java.lang.String[] newPropertyNames)
Sets array of property names in valueHolder object that correspond to properties of list object. Default is {"value"}.


getPropertyNames

public java.lang.String[] getPropertyNames()
Sets array of property names in valueHolder object that correspond to properties of list object. Default is {"value"}.


setNullAllowed

public void setNullAllowed(boolean newNullAllowed)
Sets indicator that a null value is a valid selection. If true, the nullDisplay value will appear in the list of options generated by getDisplayOptionList and setText will accept null or the nullDisplay value. If false, the setText method will throw a NotInListException if null or the nullDisplay value is set, and the nullDisplay will not appear in the displayOptionList. Default is true.


isNullAllowed

public boolean isNullAllowed()
Returns indicator that a null value is a valid selection. If true, the nullDisplay value will appear in the list of options generated by getDisplayOptionList and setText will accept null or the nullDisplay value. If false, the setText method will throw a NotInListException if null or the nullDisplay value is set, and the nullDisplay will not appear in the displayOptionList. Default is true.


setNullDisplay

public void setNullDisplay(java.lang.String newNullDisplay)
Sets value to display in list for a null value.


getNullDisplay

public java.lang.String getNullDisplay()
Returns value to display in list for a null value.



Copyright © 2007 Martin T Phelan. All Rights Reserved.