Class SimpleListModel<E>
- java.lang.Object
-
- org.zkoss.zul.AbstractListModel<E>
-
- org.zkoss.zul.SimpleListModel<E>
-
- All Implemented Interfaces:
java.io.Serializable,Pageable,Selectable<E>,Sortable<E>,ListModel<E>,ListSubModel<E>,PageableModel
public class SimpleListModel<E> extends AbstractListModel<E> implements Sortable<E>, ListSubModel<E>, java.io.Serializable
A simple implementation ofListModel.Note: It assumes the content is immutable. If not, use
ListModelListorListModelArrayinstead. 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
SimpleListModelalso implementsListSubModel. It means when it is used withCombobox, only the data that matches what the user typed will be shown.- Author:
- tomyeh
- See Also:
ListModelArray,ListModelSet,ListModelList,ListModelMap,(since 3.0.2), Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.zkoss.zul.AbstractListModel
AbstractListModel.DefaultSelectionControl<E>
-
-
Field Summary
-
Fields inherited from class org.zkoss.zul.AbstractListModel
_selection
-
Fields inherited from interface org.zkoss.zul.PageableModel
INTERNAL_EVENT
-
-
Constructor Summary
Constructors Constructor Description SimpleListModel(E[] data)Constructor.SimpleListModel(E[] data, boolean live)Constructor.SimpleListModel(java.util.List<? extends E> data)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()protected voidfireSelectionEvent(E e)Selectable's implementor use only.EgetElementAt(int j)Returns the value at the specified index.protected intgetMaxNumberInSubModel(int nRows)Returns the maximal allowed number of matched items in the sub-model returned bygetSubModel(java.lang.Object, int).intgetSize()Returns the length of the list.java.lang.StringgetSortDirection(java.util.Comparator<E> cmpr)Returns the sort direction of this model for the given comparator.ListModel<E>getSubModel(java.lang.Object value, int nRows)Returns the subset of the list model data that matches the specified value.protected booleaninSubModel(java.lang.Object key, java.lang.Object value)Compares if the given value shall belong to the submodel represented by the key.voidsort()Sort the data model by default or assigned comparator.voidsort(java.util.Comparator<E> cmpr, boolean ascending)Sorts the data.-
Methods inherited from class org.zkoss.zul.AbstractListModel
addListDataListener, addPagingEventListener, addToSelection, clearSelection, fireEvent, getActivePage, getListDataListeners, getPageCount, getPageSize, getSelection, getSelectionControl, getTotalSize, isMultiple, isSelected, isSelectionEmpty, newEmptySelection, readSelection, removeAllSelection, removeFromSelection, removeListDataListener, removePagingEventListener, retainAllSelection, setActivePage, setMultiple, setPageSize, setSelection, setSelectionControl, writeSelection
-
-
-
-
Constructor Detail
-
SimpleListModel
public SimpleListModel(E[] data, boolean live)
Constructor.- Parameters:
data- the array to representlive- whether to have a 'live'ListModelon 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 modifydataonce it is passed to this method with live is true, sinceListboxis not smart enough to handle it.- Since:
- 2.4.1
-
SimpleListModel
public SimpleListModel(E[] data)
Constructor. It made a copy of the specified array (data).Notice that if the data is static or not shared, it is better to use
SimpleListModelMap(data, true)instead, since making a copy is slower.
-
SimpleListModel
public SimpleListModel(java.util.List<? extends E> data)
Constructor. Notice the data will be converted to an array, so the performance is not good if the data is huge. UseListModelListinstead if the data is huge.- Since:
- 2.4.1
-
-
Method Detail
-
getSize
public int getSize()
Description copied from interface:ListModelReturns the length of the list.
-
getElementAt
public E getElementAt(int j)
Description copied from interface:ListModelReturns the value at the specified index.- Specified by:
getElementAtin interfaceListModel<E>
-
sort
public void sort(java.util.Comparator<E> cmpr, boolean ascending)
Sorts the data.
-
sort
public void sort()
Description copied from interface:SortableSort the data model by default or assigned comparator. Notice that the default implementation does nothing, the model which implements Sortable need to implement this method.- Specified by:
sortin interfaceSortable<E>- See Also:
Sortable.sort(Comparator, boolean)
-
getSortDirection
public java.lang.String getSortDirection(java.util.Comparator<E> cmpr)
Description copied from interface:SortableReturns the sort direction of this model for the given comparator. It must be one of "ascending", "descending" and "natural".Default: "natural".
- Specified by:
getSortDirectionin interfaceSortable<E>
-
getSubModel
public ListModel<E> getSubModel(java.lang.Object value, int nRows)
Returns the subset of the list model data that matches the specified value. It is usually used for implementation of auto-complete.The implementation uses
inSubModel(java.lang.Object, java.lang.Object)to check if the returned object ofgetElementAt(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.- Specified by:
getSubModelin interfaceListSubModel<E>- Parameters:
value- the value to retrieve the subset of the list model. It is the key argument when invokinginSubModel(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).- Since:
- 3.0.2
- See Also:
inSubModel(java.lang.Object, java.lang.Object),getMaxNumberInSubModel(int)
-
getMaxNumberInSubModel
protected int getMaxNumberInSubModel(int nRows)
Returns the maximal allowed number of matched items in the sub-model returned bygetSubModel(java.lang.Object, int).Default:
nRows < 0 ? 15: nRows.- Since:
- 5.0.4
-
inSubModel
protected boolean inSubModel(java.lang.Object key, java.lang.Object value)Compares if the given value shall belong to the submodel represented by the key.Default: converts both key and value to String objects and then return true if the String object of value starts with the String object
- Parameters:
key- the key representing the submodel. In autocomplete, it is the value entered by user.value- the value in this model.- Since:
- 5.0.4
- See Also:
getSubModel(java.lang.Object, int)
-
clone
public java.lang.Object clone()
- Overrides:
clonein classAbstractListModel<E>
-
fireSelectionEvent
protected void fireSelectionEvent(E e)
Description copied from class:AbstractListModelSelectable's implementor use only.Fires a selection event for component to scroll into view. The override subclass must put the index0 of
AbstractListModel.fireEvent(int, int, int)as the view index to scroll. By default, the value -1 is assumed which means no scroll into view.The method is invoked when both methods are invoked.
AbstractListModel.addToSelection(Object)andAbstractListModel.setSelection(Collection).- Overrides:
fireSelectionEventin classAbstractListModel<E>- Parameters:
e- selected object.
-
-