Class AbstractListModel<E>
- java.lang.Object
-
- org.zkoss.zul.AbstractListModel<E>
-
- All Implemented Interfaces:
java.io.Serializable
,Pageable
,Selectable<E>
,ListModel<E>
,PageableModel
- Direct Known Subclasses:
GroupsListModel
,ListModelArray
,ListModelList
,ListModelMap
,ListModelSet
,SimpleListModel
public abstract class AbstractListModel<E> extends java.lang.Object implements ListModel<E>, Selectable<E>, java.io.Serializable, PageableModel
A skeletal implementation forListModel
andSelectable
- Author:
- tomyeh
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractListModel.DefaultSelectionControl<E>
A default selection control implementation forAbstractListModel
, by default it assumes all elements are selectable.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<E>
_selection
The current selection.-
Fields inherited from interface org.zkoss.zul.PageableModel
INTERNAL_EVENT
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractListModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListDataListener(ListDataListener l)
Adds a listener to the list that's notified each time a change to the data model occurs.void
addPagingEventListener(PagingListener l)
Adds a listener to the list of listeners to be notified when a PagingEvent happens outside of standard Paging componentboolean
addToSelection(E obj)
Add the specified object into selection.void
clearSelection()
Change the selection to the empty set.java.lang.Object
clone()
protected void
fireEvent(int type, int index0, int index1)
Fires aListDataEvent
for all registered listener (thruaddListDataListener(org.zkoss.zul.event.ListDataListener)
.protected void
fireSelectionEvent(E e)
Selectable's implementor use only.int
getActivePage()
Returns the active page (starting from 0).java.util.List<ListDataListener>
getListDataListeners()
Returns all listeners.int
getPageCount()
Returns the number of pages.int
getPageSize()
Returns the number of items per page.java.util.Set<E>
getSelection()
Returns the current selection.SelectionControl
getSelectionControl()
Returns the selection control for the selection model, if any.int
getTotalSize()
Returns the total number of items.boolean
isMultiple()
Returns whether the current selection mode is multiple.boolean
isSelected(java.lang.Object obj)
Returns whether an object is selected.boolean
isSelectionEmpty()
Returns true if the selection is currently empty.protected java.util.Set<E>
newEmptySelection()
Instantiation an empty set of the section.protected void
readSelection(java.io.ObjectInputStream s)
Reads back_selection
.protected void
removeAllSelection(java.util.Collection<?> c)
Removes the selection of the given collection.boolean
removeFromSelection(java.lang.Object obj)
Remove the specified object from selection.void
removeListDataListener(ListDataListener l)
Removes a listener from the list that's notified each time a change to the data model occurs.void
removePagingEventListener(PagingListener l)
Removes a listener from the list of listeners to be notified when a PagingEvent happens outside of standard Paging componentprotected void
retainAllSelection(java.util.Collection<?> c)
Removes the selection that doesn't belong to the given collection.void
setActivePage(int pg)
Sets the active page (starting from 0).void
setMultiple(boolean multiple)
Sets the selection mode to be multiple.void
setPageSize(int size)
Sets the number of items per page.void
setSelection(java.util.Collection<? extends E> selection)
Replace the current selection with the given set.void
setSelectionControl(SelectionControl ctrl)
Sets the selection control for the selection modelprotected void
writeSelection(java.io.ObjectOutputStream s)
Writes_selection
.-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.zkoss.zul.ListModel
getElementAt, getSize
-
-
-
-
Field Detail
-
_selection
protected transient java.util.Set<E> _selection
The current selection.
-
-
Method Detail
-
getListDataListeners
public java.util.List<ListDataListener> getListDataListeners()
Description copied from interface:ListModel
Returns all listeners.- Specified by:
getListDataListeners
in interfaceListModel<E>
-
fireEvent
protected void fireEvent(int type, int index0, int index1)
Fires aListDataEvent
for all registered listener (thruaddListDataListener(org.zkoss.zul.event.ListDataListener)
.Note: you can invoke this method only in an event listener.
-
addListDataListener
public void addListDataListener(ListDataListener l)
Adds a listener to the list that's notified each time a change to the data model occurs.- Specified by:
addListDataListener
in interfaceListModel<E>
-
removeListDataListener
public void removeListDataListener(ListDataListener l)
Removes a listener from the list that's notified each time a change to the data model occurs.- Specified by:
removeListDataListener
in interfaceListModel<E>
-
getSelection
public java.util.Set<E> getSelection()
Returns the current selection. It is readonly. Don't modify it directly- Specified by:
getSelection
in interfaceSelectable<E>
- Returns:
- the current selection.
-
setSelection
public void setSelection(java.util.Collection<? extends E> selection)
Replace the current selection with the given set.If this represents a change to the current selection then notify each ListDataListener, including UI.
- Specified by:
setSelection
in interfaceSelectable<E>
-
isSelected
public boolean isSelected(java.lang.Object obj)
Returns whether an object is selected.- Specified by:
isSelected
in interfaceSelectable<E>
-
isSelectionEmpty
public boolean isSelectionEmpty()
Returns true if the selection is currently empty.- Specified by:
isSelectionEmpty
in interfaceSelectable<E>
-
addToSelection
public boolean addToSelection(E obj)
Add the specified object into selection.If this represents a change to the current selection then notify each ListDataListener, including UI.
- Specified by:
addToSelection
in interfaceSelectable<E>
- Parameters:
obj
- the object to be as selection.- Returns:
- true if it is added successfully; false if
obj
is not part of the data, or was already selected.
-
removeFromSelection
public boolean removeFromSelection(java.lang.Object obj)
Remove the specified object from selection.If this represents a change to the current selection then notify each ListDataListener, including UI.
- Specified by:
removeFromSelection
in interfaceSelectable<E>
- Parameters:
obj
- the object to be remove from selection.- Returns:
- whether it is removed successfully
-
clearSelection
public void clearSelection()
Change the selection to the empty set.If this represents a change to the current selection then notify each ListDataListener, including UI.
- Specified by:
clearSelection
in interfaceSelectable<E>
-
fireSelectionEvent
protected void fireSelectionEvent(E e)
Selectable's implementor use only.Fires a selection event for component to scroll into view. The override subclass must put the index0 of
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.
addToSelection(Object)
andsetSelection(Collection)
.- Parameters:
e
- selected object.
-
removeAllSelection
protected void removeAllSelection(java.util.Collection<?> c)
Removes the selection of the given collection.
-
retainAllSelection
protected void retainAllSelection(java.util.Collection<?> c)
Removes the selection that doesn't belong to the given collection.
-
isMultiple
public boolean isMultiple()
Returns whether the current selection mode is multiple.- Specified by:
isMultiple
in interfaceSelectable<E>
- See Also:
Selectable.setMultiple(boolean)
-
setMultiple
public void setMultiple(boolean multiple)
Sets the selection mode to be multiple.- Specified by:
setMultiple
in interfaceSelectable<E>
-
setSelectionControl
public void setSelectionControl(SelectionControl ctrl)
Description copied from interface:Selectable
Sets the selection control for the selection model- Specified by:
setSelectionControl
in interfaceSelectable<E>
-
getSelectionControl
public SelectionControl getSelectionControl()
Description copied from interface:Selectable
Returns the selection control for the selection model, if any.- Specified by:
getSelectionControl
in interfaceSelectable<E>
-
newEmptySelection
protected java.util.Set<E> newEmptySelection()
Instantiation an empty set of the section. It is used to initialize_selection
.By default, it instantiates an instance of LinkedHashSet. The deriving class might override to instantiate a different class.
-
writeSelection
protected void writeSelection(java.io.ObjectOutputStream s) throws java.io.IOException
Writes_selection
.Default: write it directly. Override it if E is not serializable.
- Throws:
java.io.IOException
-
readSelection
protected void readSelection(java.io.ObjectInputStream s) throws java.io.IOException, java.lang.ClassNotFoundException
Reads back_selection
.Default: write it directly. Override it if E is not serializable.
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
getPageSize
public int getPageSize()
Description copied from interface:Pageable
Returns the number of items per page.Default: 20.
- Specified by:
getPageSize
in interfacePageable
-
getTotalSize
public int getTotalSize()
Description copied from interface:PageableModel
Returns the total number of items.- Specified by:
getTotalSize
in interfacePageableModel
-
setPageSize
public void setPageSize(int size) throws WrongValueException
Description copied from interface:Pageable
Sets the number of items per page.- Specified by:
setPageSize
in interfacePageable
- Throws:
WrongValueException
-
getPageCount
public int getPageCount()
Description copied from interface:Pageable
Returns the number of pages. Note: there is at least one page even no item at all.- Specified by:
getPageCount
in interfacePageable
-
getActivePage
public int getActivePage()
Description copied from interface:Pageable
Returns the active page (starting from 0).- Specified by:
getActivePage
in interfacePageable
-
setActivePage
public void setActivePage(int pg) throws WrongValueException
Description copied from interface:Pageable
Sets the active page (starting from 0).- Specified by:
setActivePage
in interfacePageable
- Throws:
WrongValueException
-
addPagingEventListener
public void addPagingEventListener(PagingListener l)
Description copied from interface:PageableModel
Adds a listener to the list of listeners to be notified when a PagingEvent happens outside of standard Paging component- Specified by:
addPagingEventListener
in interfacePageableModel
-
removePagingEventListener
public void removePagingEventListener(PagingListener l)
Description copied from interface:PageableModel
Removes a listener from the list of listeners to be notified when a PagingEvent happens outside of standard Paging component- Specified by:
removePagingEventListener
in interfacePageableModel
-
-