|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.zkoss.zul.AbstractListModel<E>
org.zkoss.zul.SimpleListModel<E>
public class SimpleListModel<E>
A simple implementation of ListModel
.
Note: It assumes the content is immutable. If not, use ListModelList
or ListModelArray
instead.
In additions, it stores the data in the array format, so if the original
data is not an array. It is better not to use this class.
Also notice that SimpleListModel
also implements
ListSubModel
. It means when it is used with Combobox
,
only the data that matches what the user typed will be shown.
ListModelArray
,
ListModelSet
,
ListModelList
,
ListModelMap
,
(since 3.0.2)
,
Serialized FormConstructor Summary | |
---|---|
SimpleListModel(E[] data)
Constructor. |
|
SimpleListModel(E[] data,
boolean live)
Constructor. |
|
SimpleListModel(List<? extends E> data)
Constructor. |
Method Summary | |
---|---|
E |
getElementAt(int j)
Returns the value at the specified index. |
protected int |
getMaxNumberInSubModel(int nRows)
Returns the maximal allowed number of matched items in the sub-model returned by getSubModel(java.lang.Object, int) . |
int |
getSize()
Returns the length of the list. |
ListModel<E> |
getSubModel(Object value,
int nRows)
Returns the subset of the list model data that matches the specified value. |
protected boolean |
inSubModel(Object key,
Object value)
Compares if the given value shall belong to the submodel represented by the key. |
protected String |
objectToString(Object value)
Deprecated. As of release 5.0.4, replaced with inSubModel(java.lang.Object, java.lang.Object) . |
void |
sort(Comparator<E> 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 |
---|
public SimpleListModel(E[] data, boolean live)
data
- the array to representlive
- 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.public SimpleListModel(E[] data)
data
).
public SimpleListModel(List<? extends E> data)
ListModelList
instead
if the data is huge.
Method Detail |
---|
public int getSize()
ListModel
getSize
in interface ListModel<E>
public E getElementAt(int j)
ListModel
getElementAt
in interface ListModel<E>
public void sort(Comparator<E> cmpr, boolean ascending)
sort
in interface Sortable<E>
cmpr
- the comparator.ascending
- whether to sort in the ascending order.
It is ignored since this implementation uses cmprt to compare.public ListModel<E> getSubModel(Object value, int nRows)
The implementation uses inSubModel(java.lang.Object, java.lang.Object)
to check if
the returned object of getElementAt(int)
shall be in
the sub model.
Notice the maximal allowed number of items is decided by
getMaxNumberInSubModel(int)
, which, by default, returns 15
if nRows is negative.
getSubModel
in interface ListSubModel<E>
value
- the value to retrieve the subset of the list model.
It is the key argument when invoking inSubModel(java.lang.Object, java.lang.Object)
.
this string.nRows
- the maximal allowed number of matched items.
If negative, it means the caller allows any number, but the implementation
usually limits to a certain number (for better performance).inSubModel(java.lang.Object, java.lang.Object)
,
getMaxNumberInSubModel(int)
protected int getMaxNumberInSubModel(int nRows)
getSubModel(java.lang.Object, int)
.
Default: nRows < 0 ? 15: nRows
.
protected boolean inSubModel(Object key, Object value)
Default: converts both key and value to String objects and then return true if the String object of value starts with the String object
key
- the key representing the submodel. In autocomplete,
it is the value entered by user.value
- the value in this model.getSubModel(java.lang.Object, int)
protected String objectToString(Object value)
inSubModel(java.lang.Object, java.lang.Object)
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |