Package org.zkoss.stateless.state

## Class IComboboxController<DataT>

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

- All Implemented Interfaces:
    `ItemController<DataT,​ListModel<DataT>,​ICombobox,​IComboitem>`

      public class IComboboxController<DataT>
      extends java.lang.Object
      implements ItemController<DataT,​ListModel<DataT>,​ICombobox,​IComboitem>

  An `ICombobox` 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
    --- | --- | ---
    `ICombobox` | `build()` | Returns the immutable combobox instance that the controller to build with.
    `void` | `clear()` | Clears all the rendered data.
    `ListModel<DataT>` | `getModel()` | Returns the list model associated with this combobox, or null if this combobox is not associated with any list data model.
    `CheckedFunction2<DataT,​java.lang.Integer,​IComboitem>` | `getRenderer()` | Returns the renderer to render each row, or null if the default renderer is used.
    `int` | `getSelectedIndex()` | Returns the index of the selected item, or -1 if not selected.
    `DataT` | `getSelectedObject()` | Returns the data object which is selected or null.
    `static <D> IComboboxController<D>` | `of​(ICombobox owner, ListModel<D> model)` | Returns the controller instance with the given `combobox`, and `ListModel`.
    `static <D> IComboboxController<D>` | `of​(ICombobox owner, ListModel<D> model, CheckedFunction2<D,​java.lang.Integer,​IComboitem> renderer)` | Returns the controller instance with the given `combobox`, `ListModel`, and `CheckedFunction2`
    `void` | `setInvalidateThreshold​(int invalidateThreshold)` | Sets the threshold number of changed items of a model to invalidate a widget's DOM elements
    `void` | `setModel​(ListModel<DataT> model)` | Sets the list model associated with this combobox.
    `void` | `setRenderer​(CheckedFunction2<DataT,​java.lang.Integer,​IComboitem> renderer)` | Sets the renderer which is used to render each row if `getModel()` is not null.
    `void` | `setSelectedIndex​(int index)` | Deselects the currently selected items and selects the item with the given index.
    `void` | `setSelectedObject​(DataT data)` | Sets the selected data object, or deselects it by passing a null value.

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

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

- - ### Method Detail

    - #### of

          public static <D> IComboboxController<D> of​(ICombobox owner,
                                                      ListModel<D> model)

      Returns the controller instance with the given `combobox`, and `ListModel`.
      Parameters:
        `owner` - The controller to control with
        `model` - The data model for the combobox.

    - #### of

          public static <D> IComboboxController<D> of​(ICombobox owner,
                                                      ListModel<D> model,
                                                      CheckedFunction2<D,​java.lang.Integer,​IComboitem> renderer)

      Returns the controller instance with the given `combobox`, `ListModel`, and `CheckedFunction2`
      Parameters:
        `owner` - The controller to control with
        `model` - The data model for the combobox.
        `renderer` - The data renderer for the combobox.

    - #### setModel

          public void setModel​(ListModel<DataT> model)

      Sets the list model associated with this combobox. If a non-null model is assigned, no matter whether it is the same as the previous, it will always cause re-render.
      Specified by:
        `setModel` in interface `ItemController<DataT,​ListModel<DataT>,​ICombobox,​IComboitem>`
      Parameters:
        `model` - the list model to associate, or null to dissociate any previous model.
      Throws:
        `UiException` - if failed to initialize with the model

    - #### setInvalidateThreshold

          public void setInvalidateThreshold​(int invalidateThreshold)

      Sets the threshold number of changed items of a model to invalidate a widget's DOM elements

      Default: `10`

      Parameters:
        `invalidateThreshold` - The threshold number

    - #### getModel

          public ListModel<DataT> getModel()

      Returns the list model associated with this combobox, or null if this combobox is not associated with any list data model.
      Specified by:
        `getModel` in interface `ItemController<DataT,​ListModel<DataT>,​ICombobox,​IComboitem>`

    - #### setRenderer

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

      Sets the renderer which is used to render each row if `getModel()` is not null.

      Note: changing a render will not cause the combobox to re-render. If you want it to re-render, you could assign the same model again (i.e., setModel(getModel())), or fire an `ListDataEvent` event.

      Specified by:
        `setRenderer` in interface `ItemController<DataT,​ListModel<DataT>,​ICombobox,​IComboitem>`
      Parameters:
        `renderer` - the renderer, or null to use the default.

    - #### getRenderer

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

      Returns the renderer to render each row, or null if the default renderer is used.
      Specified by:
        `getRenderer` in interface `ItemController<DataT,​ListModel<DataT>,​ICombobox,​IComboitem>`

    - #### build

          public ICombobox build()

      Returns the immutable combobox instance that the controller to build with.
      Specified by:
        `build` in interface `ItemController<DataT,​ListModel<DataT>,​ICombobox,​IComboitem>`

    - #### clear

          public void clear()

      Description copied from interface: `ItemController`
      Clears all the rendered data.
      Specified by:
        `clear` in interface `ItemController<DataT,​ListModel<DataT>,​ICombobox,​IComboitem>`

    - #### getSelectedObject

          public DataT getSelectedObject()

      Returns the data object which is selected or null.

      Default: `null`

    - #### setSelectedObject

          public void setSelectedObject​(DataT data)

      Sets the selected data object, or deselects it by passing a null value.
      Parameters:
        `data` - The data object that contains in the model.

    - #### getSelectedIndex

          public int getSelectedIndex()

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

    - #### setSelectedIndex

          public void setSelectedIndex​(int index)

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

      Note: if the data has the same more than one, the first data item will be selected at client side, it is a limitation of `ICombobox` and it is different from `IListbox`.