Package org.zkoss.zul

Class AbstractListModel<E>

java.lang.Object
org.zkoss.zul.AbstractListModel<E>
All Implemented Interfaces:
Serializable, Pageable, Selectable<E>, ListModel<E>, PageableModel
Direct Known Subclasses:
GroupsListModel, ListModelArray, ListModelList, ListModelMap, ListModelSet, SimpleListModel

public abstract class AbstractListModel<E> extends Object implements ListModel<E>, Selectable<E>, Serializable, PageableModel
A skeletal implementation for ListModel and Selectable
Author:
tomyeh
See Also:
  • Field Details

    • _selection

      protected transient Set<E> _selection
      The current selection.
  • Constructor Details

    • AbstractListModel

      protected AbstractListModel()
  • Method Details

    • getListDataListeners

      public List<ListDataListener> getListDataListeners()
      Description copied from interface: ListModel
      Returns all listeners.
      Specified by:
      getListDataListeners in interface ListModel<E>
    • fireEvent

      protected void fireEvent(int type, int index0, int index1)
      Fires a ListDataEvent for all registered listener (thru addListDataListener(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 interface ListModel<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 interface ListModel<E>
    • getSelection

      public Set<E> getSelection()
      Returns the current selection. It is readonly. Don't modify it directly
      Specified by:
      getSelection in interface Selectable<E>
      Returns:
      the current selection.
    • setSelection

      public void setSelection(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 interface Selectable<E>
    • isSelected

      public boolean isSelected(Object obj)
      Returns whether an object is selected.
      Specified by:
      isSelected in interface Selectable<E>
    • isSelectionEmpty

      public boolean isSelectionEmpty()
      Returns true if the selection is currently empty.
      Specified by:
      isSelectionEmpty in interface Selectable<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 interface Selectable<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(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 interface Selectable<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 interface Selectable<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) and setSelection(Collection).

      Parameters:
      e - selected object.
    • removeAllSelection

      protected void removeAllSelection(Collection<?> c)
      Removes the selection of the given collection.
    • retainAllSelection

      protected void retainAllSelection(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 interface Selectable<E>
      See Also:
    • setMultiple

      public void setMultiple(boolean multiple)
      Sets the selection mode to be multiple.
      Specified by:
      setMultiple in interface Selectable<E>
    • setSelectionControl

      public void setSelectionControl(SelectionControl ctrl)
      Description copied from interface: Selectable
      Sets the selection control for the selection model
      Specified by:
      setSelectionControl in interface Selectable<E>
    • getSelectionControl

      public SelectionControl getSelectionControl()
      Description copied from interface: Selectable
      Returns the selection control for the selection model, if any.
      Specified by:
      getSelectionControl in interface Selectable<E>
    • newEmptySelection

      protected 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(ObjectOutputStream s) throws IOException
      Writes _selection.

      Default: write it directly. Override it if E is not serializable.

      Throws:
      IOException
    • readSelection

      protected void readSelection(ObjectInputStream s) throws IOException, ClassNotFoundException
      Reads back _selection.

      Default: write it directly. Override it if E is not serializable.

      Throws:
      IOException
      ClassNotFoundException
    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • getPageSize

      public int getPageSize()
      Description copied from interface: Pageable
      Returns the number of items per page.

      Default: 20.

      Specified by:
      getPageSize in interface Pageable
    • getTotalSize

      public int getTotalSize()
      Description copied from interface: PageableModel
      Returns the total number of items.
      Specified by:
      getTotalSize in interface PageableModel
    • setPageSize

      public void setPageSize(int size) throws org.zkoss.zk.ui.WrongValueException
      Description copied from interface: Pageable
      Sets the number of items per page.
      Specified by:
      setPageSize in interface Pageable
      Throws:
      org.zkoss.zk.ui.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 interface Pageable
    • getActivePage

      public int getActivePage()
      Description copied from interface: Pageable
      Returns the active page (starting from 0).
      Specified by:
      getActivePage in interface Pageable
    • setActivePage

      public void setActivePage(int pg) throws org.zkoss.zk.ui.WrongValueException
      Description copied from interface: Pageable
      Sets the active page (starting from 0).
      Specified by:
      setActivePage in interface Pageable
      Throws:
      org.zkoss.zk.ui.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 interface PageableModel
    • 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 interface PageableModel