org.zkoss.zul
Class ListModelArray<E>

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

public class ListModelArray<E>
extends AbstractListModel<E>
implements Sortable<E>, Serializable

This is the ListModel as an Object array to be used with Listbox. Change the contents of this model as an Object array would cause the associated Listbox to change accordingly.

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

Field Summary
protected  Object[] _array
           
 
Constructor Summary
ListModelArray(E[] src)
          Constructor.
ListModelArray(E[] array, boolean live)
          Constructor
ListModelArray(int size)
          Constructor.
ListModelArray(List<? extends E> list)
          Constructor.
 
Method Summary
 boolean equals(Object o)
           
 E get(int index)
          Get the value of this ListModelArray at specified index.
 E getElementAt(int j)
          Returns the value at the specified index.
 Object[] getInnerArray()
          Get the inner real Object[].
 int getSize()
          Returns the length of the list.
 int hashCode()
           
 int indexOf(Object elm)
          Returns the index of the specified element.
 void set(int index, E value)
          Change content of the Array at specified index.
 void sort(Comparator<E> cmpr, boolean ascending)
          Sorts the data.
 String toString()
           
 
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, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_array

protected final Object[] _array
Constructor Detail

ListModelArray

public ListModelArray(E[] array,
                      boolean live)
Constructor

Parameters:
array - the array to represent
live - whether to have a 'live' ListModel on top of the specified array. If false, the content of the specified array is copied. If true, this object is a 'facade' of the specified array, i.e., when you add or remove items from this ListModelArray, the inner "live" array would be changed accordingly. However, it is not a good idea to modify array if it is passed to this method with live is true, since Listbox is not smart enough to hanle it. Instead, modify it thru this object.
Since:
2.4.0

ListModelArray

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

Parameters:
src - the source array used to initialize this ListModelArray.

ListModelArray

public ListModelArray(int size)
Constructor.

Parameters:
size - the array size.

ListModelArray

public ListModelArray(List<? extends E> list)
Constructor. It mades a copy of the specified list (i.e., not live).

Since:
2.4.1
Method Detail

get

public E get(int index)
Get the value of this ListModelArray at specified index.

Parameters:
index - the array index to be get value.

set

public void set(int index,
                E value)
Change content of the Array at specified index.

Parameters:
index - the array index to be set the new value.

getInnerArray

public Object[] getInnerArray()
Get the inner real Object[].

Since:
2.4.0

indexOf

public int indexOf(Object elm)
Returns the index of the specified element.


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(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.

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.