org.zkoss.zul
Class ListModelList<E>

java.lang.Object
  extended by org.zkoss.zul.AbstractListModel<E>
      extended by org.zkoss.zul.ListModelList<E>
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, List<E>, Selectable<E>, Sortable<E>, ListModel<E>

public class ListModelList<E>
extends AbstractListModel<E>
implements Sortable<E>, List<E>, Serializable

This is the ListModel as a List to be used with Listbox. Add or remove the contents of this model as a List would cause the associated Listbox to change accordingly.

For more information, please refer to ZK Developer's Reference: List Model

Author:
Henri Chen
See Also:
ListModel, ListModelList, ListModelMap, Serialized Form

Field Summary
protected  List<E> _list
           
 
Fields inherited from class org.zkoss.zul.AbstractListModel
_selection
 
Constructor Summary
ListModelList()
          Constructor.
ListModelList(Collection<? extends E> c)
          Constructor.
ListModelList(E[] array)
          Constructor.
ListModelList(int initialCapacity)
          Constructor.
ListModelList(List<E> list, boolean live)
          Constructor
 
Method Summary
 boolean add(E o)
           
 void add(int index, E element)
           
 boolean addAll(Collection<? extends E> c)
           
 boolean addAll(int index, Collection<? extends E> c)
           
 void addSelection(E obj)
          Deprecated. As of release 6.0.0, replaced with AbstractListModel.addToSelection(E).
 void clear()
           
 Object clone()
           
 boolean contains(Object elem)
           
 boolean containsAll(Collection<?> c)
           
 boolean equals(Object o)
           
protected  void fireSelectionEvent(E e)
          Selectable's implementor use only.
 E get(int index)
           
 E getElementAt(int j)
          Returns the value at the specified index.
 List<E> getInnerList()
          Get the inner real List.
 int getSize()
          Returns the length of the list.
 String getSortDirection(Comparator<E> cmpr)
          Returns the sort direction of this model for the given comparator.
 int hashCode()
           
 int indexOf(Object elem)
           
 boolean isEmpty()
           
 Iterator<E> iterator()
           
 int lastIndexOf(Object elem)
           
 ListIterator<E> listIterator()
           
 ListIterator<E> listIterator(int index)
           
 E remove(int index)
           
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 void removeRange(int fromIndex, int toIndex)
          Remove from fromIndex(inclusive) to toIndex(exclusive).
 void removeSelection(Object obj)
          Deprecated. As of release 6.0.0, replaced with AbstractListModel.removeFromSelection(java.lang.Object).
 boolean retainAll(Collection<?> c)
           
 E set(int index, E element)
           
 int size()
           
 void sort(Comparator<E> cmpr, boolean ascending)
          Sorts the data.
 List<E> subList(int fromIndex, int toIndex)
           
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 String toString()
           
 
Methods inherited from class org.zkoss.zul.AbstractListModel
addListDataListener, addToSelection, clearSelection, fireEvent, getSelection, isMultiple, isSelected, isSelectionEmpty, newEmptySelection, readSelection, removeAllSelection, removeFromSelection, removeListDataListener, retainAllSelection, setMultiple, setSelection, writeSelection
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_list

protected List<E> _list
Constructor Detail

ListModelList

public ListModelList(List<E> list,
                     boolean live)
Constructor

Parameters:
list - the list 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 list if it is passed to this method with live is true, since Listbox is not smart enough to handle it. Instead, modify it thru this object.
Since:
2.4.0

ListModelList

public ListModelList()
Constructor.


ListModelList

public ListModelList(Collection<? extends E> c)
Constructor. It makes a copy of the specified collection (i.e., not live).

Notice that if the data is static or not shared, it is better to use ListModelList(c, true) instead, since making a copy is slower.


ListModelList

public ListModelList(E[] array)
Constructor. It makes a copy of the specified array (i.e., not live).

Since:
2.4.1

ListModelList

public ListModelList(int initialCapacity)
Constructor.

Parameters:
initialCapacity - the initial capacity for this ListModelList.
Method Detail

removeRange

public void removeRange(int fromIndex,
                        int toIndex)
Remove from fromIndex(inclusive) to toIndex(exclusive). If fromIndex equals toIndex, this methods do nothing.

Parameters:
fromIndex - the begin index (inclusive) to be removed.
toIndex - the end index (exclusive) to be removed.

getInnerList

public List<E> getInnerList()
Get the inner real List.


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>

add

public void add(int index,
                E element)
Specified by:
add in interface List<E>

add

public boolean add(E o)
Specified by:
add in interface Collection<E>
Specified by:
add in interface List<E>

addAll

public boolean addAll(Collection<? extends E> c)
Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface List<E>

addAll

public boolean addAll(int index,
                      Collection<? extends E> c)
Specified by:
addAll in interface List<E>

clear

public void clear()
Specified by:
clear in interface Collection<E>
Specified by:
clear in interface List<E>

contains

public boolean contains(Object elem)
Specified by:
contains in interface Collection<E>
Specified by:
contains in interface List<E>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<E>
Specified by:
containsAll in interface List<E>

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection<E>
Specified by:
equals in interface List<E>
Overrides:
equals in class Object

get

public E get(int index)
Specified by:
get in interface List<E>

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<E>
Specified by:
hashCode in interface List<E>
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

indexOf

public int indexOf(Object elem)
Specified by:
indexOf in interface List<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface List<E>

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface List<E>

lastIndexOf

public int lastIndexOf(Object elem)
Specified by:
lastIndexOf in interface List<E>

listIterator

public ListIterator<E> listIterator()
Specified by:
listIterator in interface List<E>

listIterator

public ListIterator<E> listIterator(int index)
Specified by:
listIterator in interface List<E>

remove

public E remove(int index)
Specified by:
remove in interface List<E>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface List<E>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<E>
Specified by:
removeAll in interface List<E>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<E>
Specified by:
retainAll in interface List<E>

set

public E set(int index,
             E element)
Specified by:
set in interface List<E>

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in interface List<E>

subList

public List<E> subList(int fromIndex,
                       int toIndex)
Specified by:
subList in interface List<E>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface List<E>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface List<E>

sort

public void sort(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 cmprt to compare.

getSortDirection

public String getSortDirection(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>

clone

public Object clone()
Overrides:
clone in class AbstractListModel<E>

fireSelectionEvent

protected void fireSelectionEvent(E e)
Description copied from class: AbstractListModel
Selectable'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) and AbstractListModel.setSelection(Collection).

Overrides:
fireSelectionEvent in class AbstractListModel<E>
Parameters:
e - selected object.

addSelection

public void addSelection(E obj)
Deprecated. As of release 6.0.0, replaced with AbstractListModel.addToSelection(E).


removeSelection

public void removeSelection(Object obj)
Deprecated. As of release 6.0.0, replaced with AbstractListModel.removeFromSelection(java.lang.Object).



Copyright © 2013. All rights reserved.