Package org.zkoss.zul

Class SimpleListModel<E>

    • Constructor Detail

      • SimpleListModel

        public SimpleListModel​(E[] 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 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. Use ListModelList instead if the data is huge.
        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<E>
      • getElementAt

        public E getElementAt​(int j)
        Description copied from interface: ListModel
        Returns the value at the specified index.
        Specified by:
        getElementAt in interface ListModel<E>
      • sort

        public void sort​(java.util.Comparator<E> cmpr,
                         boolean ascending)
        Sorts the data.
        Specified by:
        sort in interface Sortable<E>
        Parameters:
        cmpr - the comparator.
        ascending - whether to sort in the ascending order. It is ignored since this implementation uses cmpr to compare.
      • sort

        public void sort()
        Description copied from interface: Sortable
        Sort 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:
        sort in interface Sortable<E>
        See Also:
        Sortable.sort(Comparator, boolean)
      • getSortDirection

        public java.lang.String getSortDirection​(java.util.Comparator<E> cmpr)
        Description copied from interface: Sortable
        Returns the sort direction of this model for the given comparator. It must be one of "ascending", "descending" and "natural".

        Default: "natural".

        Specified by:
        getSortDirection in interface Sortable<E>
      • getMaxNumberInSubModel

        protected int getMaxNumberInSubModel​(int nRows)
        Returns the maximal allowed number of matched items in the sub-model returned by getSubModel(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)