Package org.zkoss.stateless.state

## Class ISelectboxController<DataT>

- java.lang.Object
- - org.zkoss.stateless.state.ISelectboxController<DataT>

- All Implemented Interfaces:
    `ItemController<DataT,​ListModel<DataT>,​ISelectbox,​java.lang.String>`

      public class ISelectboxController<DataT>
      extends java.lang.Object
      implements ItemController<DataT,​ListModel<DataT>,​ISelectbox,​java.lang.String>

  An `ISelectbox` controller to control any operation on the given model.

  Note: this class is not thread-safe, so when it's used in multi-threading environment, the developer should handle the threading issue.

  Author:
    katherine

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `ISelectbox` | `build()` | Returns the immutable instance that the controller to build with
    `void` | `clear()` | Clears all the rendered data.
    `void` | `clearSelection()` | Clears the selection.
    `ListModel<DataT>` | `getModel()` | Returns the model, which is set through by `ItemController.setModel(Object)`, or null.
    `CheckedFunction2<DataT,​java.lang.Integer,​java.lang.String>` | `getRenderer()` | Returns the renderer, which is set through by `ItemController.setRenderer(CheckedFunction2)`, or a default one which is depended on implementation.
    `int` | `getSelectedIndex()` | Returns the index of the selected item, or -1 if not selected.
    `DataT` | `getSelectedObject()` | Returns the selected item, or null if no item is selected.
    `java.util.Set<DataT>` | `getSelectedObjects()` | Returns all selected items, or an empty set if no item is selected.
    `boolean` | `isMultiple()` | Returns whether it is multiple selection.
    `static <D> ISelectboxController<D>` | `of​(ISelectbox owner)` | Returns the controller instance with the given `selectbox`.
    `static <D> ISelectboxController<D>` | `of​(ISelectbox owner, ListModel<D> model)` | Returns the controller instance with the given `selectbox`
    `static <D> ISelectboxController<D>` | `of​(ISelectbox owner, ListModel<D> model, CheckedFunction2<java.lang.Object,​java.lang.Integer,​java.lang.String> renderer)` | Returns the controller instance with the given `selectbox`
    `void` | `setModel​(ListModel<DataT> model)` | Sets the given model to this controller.
    `void` | `setMultiple​(boolean multiple)` | Sets whether multiple selections are allowed.
    `void` | `setRenderer​(CheckedFunction2<DataT,​java.lang.Integer,​java.lang.String> renderer)` | Sets the renderer which is used to render each data if `ItemController.getModel()` is not null.
    `void` | `setSelectedIndex​(int jsel)` | Deselects the currently selected items and selects the item with the given index.
    `void` | `setSelectedObject​(DataT item)` | Deselects all the currently selected items and selects the given item.
    `void` | `setSelectedObjects​(java.util.Set<DataT> items)` | Sets all selected items.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### of

          public static <D> ISelectboxController<D> of​(ISelectbox owner,
                                                       ListModel<D> model)

      Returns the controller instance with the given `selectbox`
      Parameters:
        `owner` - The controller to control with
        `model` - The list model to associate with the selectbox.

    - #### of

          public static <D> ISelectboxController<D> of​(ISelectbox owner,
                                                       ListModel<D> model,
                                                       CheckedFunction2<java.lang.Object,​java.lang.Integer,​java.lang.String> renderer)

      Returns the controller instance with the given `selectbox`
      Parameters:
        `owner` - The controller to control with
        `model` - The list model to associate with the selectbox.
        `renderer` - The renderer of the list model.

    - #### of

          public static <D> ISelectboxController<D> of​(ISelectbox owner)

      Returns the controller instance with the given `selectbox`.

      Note: The selectbox must contain as least one child, which will covert them into a model automatically

      Parameters:
        `owner` - The controller to control with

    - #### setModel

          public void setModel​(ListModel<DataT> model)

      Description copied from interface: `ItemController`
      Sets the given model to this controller.

      Note: calling this method after `ItemController.build()`, you should invoke `ItemController.build()` again to take effect to replace the current one at client.
      For example,

           uiAgent.replaceWith(locator, itemController.build());

      Default: `null`

      Specified by:
        `setModel` in interface `ItemController<DataT,​ListModel<DataT>,​ISelectbox,​java.lang.String>`

    - #### getModel

          public ListModel<DataT> getModel()

      Description copied from interface: `ItemController`
      Returns the model, which is set through by `ItemController.setModel(Object)`, or null.
      Specified by:
        `getModel` in interface `ItemController<DataT,​ListModel<DataT>,​ISelectbox,​java.lang.String>`

    - #### setRenderer

          public void setRenderer​(CheckedFunction2<DataT,​java.lang.Integer,​java.lang.String> renderer)

      Description copied from interface: `ItemController`
      Sets the renderer which is used to render each data if `ItemController.getModel()` is not null.

      Note: calling this method after `ItemController.build()`, you should invoke `ItemController.build()` again to take effect to replace the current one at client.
      For example,

           uiAgent.replaceWith(locator, itemController.build());

      Default: `null`, or depended on the implementation

      Specified by:
        `setRenderer` in interface `ItemController<DataT,​ListModel<DataT>,​ISelectbox,​java.lang.String>`

    - #### getRenderer

          public CheckedFunction2<DataT,​java.lang.Integer,​java.lang.String> getRenderer()

      Description copied from interface: `ItemController`
      Returns the renderer, which is set through by `ItemController.setRenderer(CheckedFunction2)`, or a default one which is depended on implementation.
      Specified by:
        `getRenderer` in interface `ItemController<DataT,​ListModel<DataT>,​ISelectbox,​java.lang.String>`

    - #### setMultiple

          public void setMultiple​(boolean multiple)

      Sets whether multiple selections are allowed.

      Notice that, if a model is assigned, it will change the model's state (by `Selectable.setMultiple(boolean)`).

    - #### isMultiple

          public boolean isMultiple()

      Returns whether it is multiple selection.

      Default: `false`

    - #### build

          public ISelectbox build()

      Description copied from interface: `ItemController`
      Returns the immutable instance that the controller to build with
      Specified by:
        `build` in interface `ItemController<DataT,​ListModel<DataT>,​ISelectbox,​java.lang.String>`

    - #### clear

          public void clear()

      Description copied from interface: `ItemController`
      Clears all the rendered data.
      Specified by:
        `clear` in interface `ItemController<DataT,​ListModel<DataT>,​ISelectbox,​java.lang.String>`

    - #### getSelectedIndex

          public int getSelectedIndex()

      Returns the index of the selected item, or -1 if not selected.

    - #### setSelectedIndex

          public void setSelectedIndex​(int jsel)

      Deselects the currently selected items and selects the item with the given index.

    - #### getSelectedObject

          public DataT getSelectedObject()

      Returns the selected item, or null if no item is selected.

    - #### setSelectedObject

          public void setSelectedObject​(DataT item)

      Deselects all the currently selected items and selects the given item.

    - #### getSelectedObjects

          public java.util.Set<DataT> getSelectedObjects()

      Returns all selected items, or an empty set if no item is selected.

    - #### setSelectedObjects

          public void setSelectedObjects​(java.util.Set<DataT> items)

      Sets all selected items.

      Note: `isMultiple()` should be true.

      Parameters:
        `items` - The set of the data in the model.

    - #### clearSelection

          public void clearSelection()

      Clears the selection.