org.zkoss.zul
Class SimpleListModel

java.lang.Object
  extended by org.zkoss.zul.AbstractListModel
      extended by org.zkoss.zul.SimpleListModel
All Implemented Interfaces:
java.io.Serializable, Selectable, ListModel, ListModelExt, ListSubModel

public class SimpleListModel
extends AbstractListModel
implements ListModelExt, ListSubModel, java.io.Serializable

A simple implementation of ListModel. Note: It assumes the content is immutable. If not, use ListModelList or ListModelArray nstead.

Author:
tomyeh
See Also:
ListModelArray, ListModelSet, ListModelList, ListModelMap, (since 3.0.2), Serialized Form

Constructor Summary
SimpleListModel(java.util.List data)
          Constructor.
SimpleListModel(java.lang.Object[] data)
          Constructor.
SimpleListModel(java.lang.Object[] data, boolean live)
          Constructor.
 
Method Summary
 java.lang.Object getElementAt(int j)
          Returns the value at the specified index.
 int getSize()
          Returns the length of the list.
 ListModel getSubModel(java.lang.Object value, int nRows)
          Returns the subset of the list model data that matches the specified value.
protected  java.lang.String objectToString(java.lang.Object value)
          Returns the string from the value object.
 void sort(java.util.Comparator cmpr, boolean ascending)
          Sorts the data.
 
Methods inherited from class org.zkoss.zul.AbstractListModel
addListDataListener, addSelection, clearSelection, fireEvent, getSelection, removeAllSelection, removeListDataListener, removeSelection, retainAllSelection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleListModel

public SimpleListModel(java.lang.Object[] data,
                       boolean live)
Constructor.

Parameters:
data - the array to represent
live - whether to have a 'live' ListModel on top of the specified list. If false, the content of the specified list is copied. If true, this object is a 'facade' of the specified list, i.e., when you add or remove items from this ListModelList, the inner "live" list would be changed accordingly. However, it is not a good idea to modify data once it is passed to this method with live is true, since Listbox is not smart enough to hanle it.
Since:
2.4.1

SimpleListModel

public SimpleListModel(java.lang.Object[] data)
Constructor. It made a copy of the specified array (data).


SimpleListModel

public SimpleListModel(java.util.List data)
Constructor.

Since:
2.4.1
Method Detail

getSize

public int getSize()
Description copied from interface: ListModel
Returns the length of the list.

Specified by:
getSize in interface ListModel

getElementAt

public java.lang.Object getElementAt(int j)
Description copied from interface: ListModel
Returns the value at the specified index.

Specified by:
getElementAt in interface ListModel

sort

public void sort(java.util.Comparator cmpr,
                 boolean ascending)
Sorts the data.

Specified by:
sort in interface ListModelExt
Parameters:
cmpr - the comparator.
ascending - whether to sort in the ascending order. It is ignored since this implementation uses cmprt to compare.

getSubModel

public ListModel getSubModel(java.lang.Object value,
                             int nRows)
Returns the subset of the list model data that matches the specified value. It is ususally used for implmentation of auto-complete.

The implementation uses objectToString(java.lang.Object) to convert the returned object of getElementAt(int) to the string. And then, an element is considered as 'matched', if the string starts with the specified value.

Note: If the nRows is a negative number, 10 is assumed.

Specified by:
getSubModel in interface ListSubModel
Parameters:
value - the value to retrieve the subset of the list model. It is converted to a string first by use of objectToString(java.lang.Object). Then, it is used to check if an element starts with (aka., prefix with) this string.
nRows - the number of rows suggested to return (as the returned ListModel instance). It's a suggestion for developer to follow. If nonpositive, it means the maximal allowed rows is decided by the implementation of ListSubmodel.
Since:
3.0.2

objectToString

protected java.lang.String objectToString(java.lang.Object value)
Returns the string from the value object. It is used to convert the object type to the string type for getSubModel(Object, int).

The implementation uses Object.toString() to convert the value to a string (and to an empty string if null). If you need better control, you can override this method.

Parameters:
value - the value object.
Since:
3.0.2


Copyright © 2005-2009 Potix Corporation. All Rights Reserved. SourceForge.net Logo