Module is.codion.swing.common.model
Class ItemComboBoxModel<T>
java.lang.Object
is.codion.swing.common.model.component.combobox.ItemComboBoxModel<T>
- Type Parameters:
T
- the type of value wrapped by this combo box models items
- All Implemented Interfaces:
FilterModel<Item<T>>
,FilterComboBoxModel<Item<T>>
,ComboBoxModel<Item<T>>
,ListModel<Item<T>>
A ComboBoxModel implementation based on the
Item
class.-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel
FilterComboBoxModel.ComboBoxItems<T>, FilterComboBoxModel.ComboBoxSelection<T>, FilterComboBoxModel.ItemFinder<T,
V>, FilterComboBoxModel.NullItem<T> Nested classes/interfaces inherited from interface is.codion.common.model.FilterModel
FilterModel.AbstractRefresher<T>, FilterModel.FilteredItems<T>, FilterModel.Items<T>, FilterModel.Refresher<T>, FilterModel.VisibleItems<T>
-
Field Summary
Fields inherited from interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel
NULL_CAPTION
Fields inherited from interface is.codion.common.model.FilterModel
ASYNC_REFRESH
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
addListDataListener
(ListDataListener listener) static ItemComboBoxModel<Boolean>
Constructs a new Boolean based ItemComboBoxModel with null as the initially selected value.static ItemComboBoxModel<Boolean>
booleanItemComboBoxModel
(String nullCaption) Constructs a new Boolean based ItemComboBoxModel with null as the initially selected value.static ItemComboBoxModel<Boolean>
booleanItemComboBoxModel
(String nullCaption, String trueCaption, String falseCaption) Constructs a new Boolean based ItemComboBoxModel with null as the initially selected value.final <V> Value<V>
createSelectorValue
(FilterComboBoxModel.ItemFinder<Item<T>, V> itemFinder) getElementAt
(int index) final int
getSize()
int
Returns the index of the Item representing the given value, -1 if this model does not contain such an Item.static <T> ItemComboBoxModel<T>
static <T> ItemComboBoxModel<T>
itemComboBoxModel
(List<Item<T>> items) final FilterComboBoxModel.ComboBoxItems<Item<T>>
items()
final void
refresh()
Refreshes the items in this model using itsFilterModel.Refresher
.final void
refresh
(Consumer<Collection<Item<T>>> onRefresh) Refreshes the data in this filter model using itsFilterModel.Refresher
.final FilterModel.Refresher<Item<T>>
final void
removeListDataListener
(ListDataListener listener) final void
setSelectedItem
(Object item) static <T> ItemComboBoxModel<T>
static <T> ItemComboBoxModel<T>
sortedItemComboBoxModel
(Comparator<Item<T>> comparator) static <T> ItemComboBoxModel<T>
sortedItemComboBoxModel
(List<Item<T>> items) static <T> ItemComboBoxModel<T>
sortedItemComboBoxModel
(List<Item<T>> items, Comparator<Item<T>> comparator)
-
Method Details
-
indexOf
Returns the index of the Item representing the given value, -1 if this model does not contain such an Item.- Parameters:
value
- the value- Returns:
- the index of the Item representing the given value, -1 if not found
-
itemComboBoxModel
- Type Parameters:
T
- the Item value type- Returns:
- a new combo box model
-
itemComboBoxModel
- Type Parameters:
T
- the Item value type- Parameters:
items
- the items- Returns:
- a new combo box model
-
sortedItemComboBoxModel
- Type Parameters:
T
- the Item value type- Returns:
- a new combo box model
-
sortedItemComboBoxModel
- Type Parameters:
T
- the Item value type- Parameters:
items
- the items- Returns:
- a new combo box model
-
sortedItemComboBoxModel
- Type Parameters:
T
- the Item value type- Parameters:
comparator
- the comparator to use when sorting- Returns:
- a new combo box model
-
sortedItemComboBoxModel
public static <T> ItemComboBoxModel<T> sortedItemComboBoxModel(List<Item<T>> items, Comparator<Item<T>> comparator) - Type Parameters:
T
- the Item value type- Parameters:
items
- the itemscomparator
- the comparator to use when sorting- Returns:
- a new combo box model
-
booleanItemComboBoxModel
Constructs a new Boolean based ItemComboBoxModel with null as the initially selected value.- Returns:
- a Boolean based ItemComboBoxModel
-
booleanItemComboBoxModel
Constructs a new Boolean based ItemComboBoxModel with null as the initially selected value.- Parameters:
nullCaption
- the string representing a null value- Returns:
- a Boolean based ItemComboBoxModel
-
booleanItemComboBoxModel
public static ItemComboBoxModel<Boolean> booleanItemComboBoxModel(String nullCaption, String trueCaption, String falseCaption) Constructs a new Boolean based ItemComboBoxModel with null as the initially selected value.- Parameters:
nullCaption
- the string representing a null valuetrueCaption
- the string representing the boolean value 'true'falseCaption
- the string representing the boolean value 'false'- Returns:
- a Boolean based ItemComboBoxModel
-
refresher
- Specified by:
refresher
in interfaceFilterModel<T>
- Returns:
- this models Refresher instance
-
refresh
public final void refresh()Description copied from interface:FilterModel
Refreshes the items in this model using itsFilterModel.Refresher
.- Specified by:
refresh
in interfaceFilterModel<T>
- See Also:
-
refresh
Description copied from interface:FilterModel
Refreshes the data in this filter model using itsFilterModel.Refresher
. Note that this method only throws exceptions when run synchronously off the user interface thread. UseFilterModel.Refresher.failure()
to listen for exceptions that happen during asynchronous refresh.- Specified by:
refresh
in interfaceFilterModel<T>
- Parameters:
onRefresh
- called after a successful refresh, may be null- See Also:
-
items
- Specified by:
items
in interfaceFilterComboBoxModel<T>
- Specified by:
items
in interfaceFilterModel<T>
- Returns:
- the model items
-
selection
- Specified by:
selection
in interfaceFilterComboBoxModel<T>
- Specified by:
selection
in interfaceFilterModel<T>
- Returns:
- the
SingleItemSelection
instance used by this filter model
-
getSelectedItem
- Specified by:
getSelectedItem
in interfaceComboBoxModel<T>
- Specified by:
getSelectedItem
in interfaceFilterComboBoxModel<T>
- Returns:
- the selected item, N.B. this can include the
nullItem
in case it has been set viaFilterComboBoxModel.ComboBoxItems.nullItem()
,FilterComboBoxModel.ComboBoxSelection.value()
is usually what you want
-
setSelectedItem
- Specified by:
setSelectedItem
in interfaceComboBoxModel<T>
-
addListDataListener
- Specified by:
addListDataListener
in interfaceListModel<T>
-
removeListDataListener
- Specified by:
removeListDataListener
in interfaceListModel<T>
-
getElementAt
- Specified by:
getElementAt
in interfaceListModel<T>
-
getSize
public final int getSize() -
createSelectorValue
- Specified by:
createSelectorValue
in interfaceFilterComboBoxModel<T>
- Type Parameters:
V
- the value type- Parameters:
itemFinder
- responsible for finding the item to select- Returns:
- a
Value
linked to the selected item using the givenFilterComboBoxModel.ItemFinder
instance
-