Package org.zkoss.zul

## Class AbstractGroupsModel<D,​H,​F,​E>

- java.lang.Object
- - org.zkoss.zul.AbstractGroupsModel<D,​H,​F,​E>

- All Implemented Interfaces:
    `java.io.Serializable`, `GroupsSelectableModel<E>`, `Selectable<E>`, `GroupsModel<D,​H,​F>`
  Direct Known Subclasses:
    `GroupsModelArray`, `SimpleGroupsModel`

      public abstract class AbstractGroupsModel<D,​H,​F,​E>
      extends java.lang.Object
      implements GroupsModel<D,​H,​F>, GroupsSelectableModel<E>, java.io.Serializable

  A skeletal implementation for `GroupsModel`.

  Implements `Selectable` interface to handle the selection status. (Since 6.0.0)

  Generics:

  D
    The class of each data
  H
    The class of each group header
  F
    The class of each group footer
  E
    The class of each selection. It is the common base class of D, H, F. In other words, D, H and F must extend from E.
  Since:
    3.5.0
  Author:
    tomyeh
  See Also:
    `Selectable`, Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `AbstractGroupsModel.DefaultSelectionControl<E>` | A default selection control implementation for `AbstractGroupsModel`, 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.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `AbstractGroupsModel()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addGroupsDataListener​(GroupsDataListener l)` | Adds a listener to the groups that's notified each time a change to the data model occurs.
    `boolean` | `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 groupIndex, int index0, int index1)` | Fires a `GroupsDataEvent` for all registered listener (thru `addGroupsDataListener(org.zkoss.zul.event.GroupsDataListener)`.
    `protected void` | `fireSelectionEvent​(E e)` | Selectable's implementor use only.
    `java.util.Set<E>` | `getSelection()` | Returns the current selection.
    `SelectionControl` | `getSelectionControl()` | Returns the selection control for the selection model, if any.
    `boolean` | `isGroupSelectable()` | Returns whether the groups are selectable
    `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` | `removeGroupsDataListener​(GroupsDataListener l)` | Removes a listener from the groups that's notified each time a change to the data model occurs.
    `protected void` | `retainAllSelection​(java.util.Collection<?> c)` | Removes the selection that doesn't belong to the given collection.
    `void` | `setGroupSelectable​(boolean groupSelectable)` | Sets the groups are selectable
    `void` | `setMultiple​(boolean multiple)` | Sets the selection mode to be multiple.
    `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 model
    `protected 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.GroupsModel

      `addOpenGroup, getChild, getChildCount, getGroup, getGroupCount, getGroupfoot, hasGroupfoot, isGroupOpened, removeOpenGroup`

- - ### Field Detail

    - #### _selection

          protected transient java.util.Set<E> _selection

      The current selection.

  - ### Constructor Detail

    - #### AbstractGroupsModel

          protected AbstractGroupsModel()

  - ### Method Detail

    - #### fireEvent

          protected void fireEvent​(int type,
                                   int groupIndex,
                                   int index0,
                                   int index1)

      Fires a `GroupsDataEvent` for all registered listener (thru `addGroupsDataListener(org.zkoss.zul.event.GroupsDataListener)`.

      Note: you can invoke this method only in an event listener.

    - #### 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<D>`

    - #### 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<D>`

    - #### addGroupsDataListener

          public void addGroupsDataListener​(GroupsDataListener l)

      Description copied from interface: `GroupsModel`
      Adds a listener to the groups that's notified each time a change to the data model occurs.
      Specified by:
        `addGroupsDataListener` in interface `GroupsModel<D,​H,​F>`

    - #### removeGroupsDataListener

          public void removeGroupsDataListener​(GroupsDataListener l)

      Description copied from interface: `GroupsModel`
      Removes a listener from the groups that's notified each time a change to the data model occurs.
      Specified by:
        `removeGroupsDataListener` in interface `GroupsModel<D,​H,​F>`

    - #### getSelection

          public java.util.Set<E> getSelection()

      Returns the current selection. It is readonly. Don't modify it directly
      Specified by:
        `getSelection` in interface `Selectable<D>`
      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 interface `Selectable<D>`

    - #### isSelected

          public boolean isSelected​(java.lang.Object obj)

      Returns whether an object is selected.
      Specified by:
        `isSelected` in interface `Selectable<D>`

    - #### isSelectionEmpty

          public boolean isSelectionEmpty()

      Returns true if the selection is currently empty.
      Specified by:
        `isSelectionEmpty` in interface `Selectable<D>`

    - #### 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<D>`
      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 interface `Selectable<D>`
      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<D>`

    - #### 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, 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​(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 interface `Selectable<D>`
      See Also:
        `Selectable.setMultiple(boolean)`

    - #### setMultiple

          public void setMultiple​(boolean multiple)

      Sets the selection mode to be multiple.
      Specified by:
        `setMultiple` in interface `Selectable<D>`

    - #### isGroupSelectable

          public boolean isGroupSelectable()

      Description copied from interface: `GroupsSelectableModel`
      Returns whether the groups are selectable
      Specified by:
        `isGroupSelectable` in interface `GroupsSelectableModel<D>`

    - #### setGroupSelectable

          public void setGroupSelectable​(boolean groupSelectable)

      Description copied from interface: `GroupsSelectableModel`
      Sets the groups are selectable
      Specified by:
        `setGroupSelectable` in interface `GroupsSelectableModel<D>`

    - #### 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 LinkedHashMap. 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 class `java.lang.Object`