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 forListModelandSelectable- Author:
- tomyeh
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractListModel.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>_selectionThe current selection.-
Fields inherited from interface org.zkoss.zul.PageableModel
INTERNAL_EVENT
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractListModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListDataListener(ListDataListener l)Adds a listener to the list that's notified each time a change to the data model occurs.voidaddPagingEventListener(PagingListener l)Adds a listener to the list of listeners to be notified when a PagingEvent happens outside of standard Paging componentbooleanaddToSelection(E obj)Add the specified object into selection.voidclearSelection()Change the selection to the empty set.java.lang.Objectclone()protected voidfireEvent(int type, int index0, int index1)Fires aListDataEventfor all registered listener (thruaddListDataListener(org.zkoss.zul.event.ListDataListener).protected voidfireSelectionEvent(E e)Selectable's implementor use only.intgetActivePage()Returns the active page (starting from 0).java.util.List<ListDataListener>getListDataListeners()Returns all listeners.intgetPageCount()Returns the number of pages.intgetPageSize()Returns the number of items per page.java.util.Set<E>getSelection()Returns the current selection.SelectionControlgetSelectionControl()Returns the selection control for the selection model, if any.intgetTotalSize()Returns the total number of items.booleanisMultiple()Returns whether the current selection mode is multiple.booleanisSelected(java.lang.Object obj)Returns whether an object is selected.booleanisSelectionEmpty()Returns true if the selection is currently empty.protected java.util.Set<E>newEmptySelection()Instantiation an empty set of the section.protected voidreadSelection(java.io.ObjectInputStream s)Reads back_selection.protected voidremoveAllSelection(java.util.Collection<?> c)Removes the selection of the given collection.booleanremoveFromSelection(java.lang.Object obj)Remove the specified object from selection.voidremoveListDataListener(ListDataListener l)Removes a listener from the list that's notified each time a change to the data model occurs.voidremovePagingEventListener(PagingListener l)Removes a listener from the list of listeners to be notified when a PagingEvent happens outside of standard Paging componentprotected voidretainAllSelection(java.util.Collection<?> c)Removes the selection that doesn't belong to the given collection.voidsetActivePage(int pg)Sets the active page (starting from 0).voidsetMultiple(boolean multiple)Sets the selection mode to be multiple.voidsetPageSize(int size)Sets the number of items per page.voidsetSelection(java.util.Collection<? extends E> selection)Replace the current selection with the given set.voidsetSelectionControl(SelectionControl ctrl)Sets the selection control for the selection modelprotected voidwriteSelection(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:ListModelReturns all listeners.- Specified by:
getListDataListenersin interfaceListModel<E>
-
fireEvent
protected void fireEvent(int type, int index0, int index1)Fires aListDataEventfor 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:
addListDataListenerin 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:
removeListDataListenerin interfaceListModel<E>
-
getSelection
public java.util.Set<E> getSelection()
Returns the current selection. It is readonly. Don't modify it directly- Specified by:
getSelectionin 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:
setSelectionin interfaceSelectable<E>
-
isSelected
public boolean isSelected(java.lang.Object obj)
Returns whether an object is selected.- Specified by:
isSelectedin interfaceSelectable<E>
-
isSelectionEmpty
public boolean isSelectionEmpty()
Returns true if the selection is currently empty.- Specified by:
isSelectionEmptyin 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:
addToSelectionin interfaceSelectable<E>- Parameters:
obj- the object to be as selection.- Returns:
- true if it is added successfully; false if
objis 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:
removeFromSelectionin 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:
clearSelectionin 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:
isMultiplein interfaceSelectable<E>- See Also:
Selectable.setMultiple(boolean)
-
setMultiple
public void setMultiple(boolean multiple)
Sets the selection mode to be multiple.- Specified by:
setMultiplein interfaceSelectable<E>
-
setSelectionControl
public void setSelectionControl(SelectionControl ctrl)
Description copied from interface:SelectableSets the selection control for the selection model- Specified by:
setSelectionControlin interfaceSelectable<E>
-
getSelectionControl
public SelectionControl getSelectionControl()
Description copied from interface:SelectableReturns the selection control for the selection model, if any.- Specified by:
getSelectionControlin 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.IOExceptionWrites_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.ClassNotFoundExceptionReads back_selection.Default: write it directly. Override it if E is not serializable.
- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
getPageSize
public int getPageSize()
Description copied from interface:PageableReturns the number of items per page.Default: 20.
- Specified by:
getPageSizein interfacePageable
-
getTotalSize
public int getTotalSize()
Description copied from interface:PageableModelReturns the total number of items.- Specified by:
getTotalSizein interfacePageableModel
-
setPageSize
public void setPageSize(int size) throws org.zkoss.zk.ui.WrongValueExceptionDescription copied from interface:PageableSets the number of items per page.- Specified by:
setPageSizein interfacePageable- Throws:
org.zkoss.zk.ui.WrongValueException
-
getPageCount
public int getPageCount()
Description copied from interface:PageableReturns the number of pages. Note: there is at least one page even no item at all.- Specified by:
getPageCountin interfacePageable
-
getActivePage
public int getActivePage()
Description copied from interface:PageableReturns the active page (starting from 0).- Specified by:
getActivePagein interfacePageable
-
setActivePage
public void setActivePage(int pg) throws org.zkoss.zk.ui.WrongValueExceptionDescription copied from interface:PageableSets the active page (starting from 0).- Specified by:
setActivePagein interfacePageable- Throws:
org.zkoss.zk.ui.WrongValueException
-
addPagingEventListener
public void addPagingEventListener(PagingListener l)
Description copied from interface:PageableModelAdds a listener to the list of listeners to be notified when a PagingEvent happens outside of standard Paging component- Specified by:
addPagingEventListenerin interfacePageableModel
-
removePagingEventListener
public void removePagingEventListener(PagingListener l)
Description copied from interface:PageableModelRemoves a listener from the list of listeners to be notified when a PagingEvent happens outside of standard Paging component- Specified by:
removePagingEventListenerin interfacePageableModel
-
-