Class SimpleListModel<E>
- All Implemented Interfaces:
Serializable,Pageable,Selectable<E>,Sortable<E>,ListModel<E>,ListSubModel<E>,PageableModel
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.
- Author:
- tomyeh
- See Also:
-
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
_selectionFields inherited from interface org.zkoss.zul.PageableModel
INTERNAL_EVENT -
Constructor Summary
ConstructorsConstructorDescriptionSimpleListModel(E[] data) Constructor.SimpleListModel(E[] data, boolean live) Constructor.SimpleListModel(List<? extends E> data) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionclone()protected voidSelectable's implementor use only.getElementAt(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.getSortDirection(Comparator<E> cmpr) Returns the sort direction of this model for the given comparator.getSubModel(Object value, int nRows) Returns the subset of the list model data that matches the specified value.protected booleaninSubModel(Object key, 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(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 Details
-
SimpleListModel
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
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
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 Details
-
getSize
public int getSize()Description copied from interface:ListModelReturns the length of the list. -
getElementAt
Description copied from interface:ListModelReturns the value at the specified index.- Specified by:
getElementAtin interfaceListModel<E>
-
sort
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. -
getSortDirection
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
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:
-
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
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:
-
clone
- Overrides:
clonein classAbstractListModel<E>
-
fireSelectionEvent
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.
-