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.ItemFinder<T,
V> Nested classes/interfaces inherited from interface is.codion.common.model.FilterModel
FilterModel.AbstractRefresher<T>, FilterModel.Refresher<T>
-
Field Summary
Fields inherited from interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel
COMBO_BOX_NULL_CAPTION
Fields inherited from interface is.codion.common.model.FilterModel
ASYNC_REFRESH
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
Adds the given item to this model, respecting the sorting order if specified.final 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 void
clear()
Clears all items from this combo box model, including the null item and sets the selected item to nullfinal boolean
cleared()
final Value<Comparator<Item<T>>>
Controls the Comparator used when sorting the visible items in this model and sorts the model accordingly.final boolean
containsItem
(Item<T> item) Returns true if this model contains the given item, visible or filtered.final <V> Value<V>
createSelectorValue
(FilterComboBoxModel.ItemFinder<Item<T>, V> itemFinder) final boolean
Returns true if this model contains the given item, and it is filtered, that is, is not visiblefinal int
final Collection<Item<T>>
final void
Filters this model according to the condition specified byFilterModel.includeCondition()
.final State
Specifies whether filtering can change the selected item, if true then the selected item is set to null when the currently selected item is filtered from the model, otherwise the selected item can potentially represent a value which is not currently visible in the model.getElementAt
(int index) final int
getSize()
final State
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 Collection<Item<T>>
items()
nullItem()
Controls the item that should represent the null value in this model.final boolean
Returns true if this model contains null and it is selected.final void
refresh()
Refreshes the items in this filtered model using itsFilterModel.Refresher
.final FilterModel.Refresher<Item<T>>
final void
refreshThen
(Consumer<Collection<Item<T>>> afterRefresh) Refreshes the data in this filter model using itsFilterModel.Refresher
.final void
Removes the given item from this modelfinal void
removeListDataListener
(ListDataListener listener) final void
Replaces the given item in this combo box modelProvides a way for the combo box model to translate an item when it is selected, such as selecting the String "1" in a String based model when selected item is set to the number 1.final StateObserver
final EventObserver<Item<T>>
final void
setItems
(Collection<Item<T>> items) Resets the items of this model using the values found initems
.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) final void
Sorts the items in this modelProvides a way for the model to prevent the addition of certain items.Provides a way for the combo box model to prevent the selection of certain items.final boolean
Returns true if this model contains the given item, and it is visible, that is, not filteredfinal int
-
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 filtered model using itsFilterModel.Refresher
.- Specified by:
refresh
in interfaceFilterModel<T>
- See Also:
-
refreshThen
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.refreshFailedEvent()
to listen for exceptions that happen during asynchronous refresh.- Specified by:
refreshThen
in interfaceFilterModel<T>
- Parameters:
afterRefresh
- called after a successful refresh, may be null- See Also:
-
clear
public final void clear()Description copied from interface:FilterComboBoxModel
Clears all items from this combo box model, including the null item and sets the selected item to null- Specified by:
clear
in interfaceFilterComboBoxModel<T>
-
cleared
public final boolean cleared()- Specified by:
cleared
in interfaceFilterComboBoxModel<T>
- Returns:
- true if the model data has been cleared and needs to be refreshed
-
setItems
Description copied from interface:FilterComboBoxModel
Resets the items of this model using the values found initems
.- Specified by:
setItems
in interfaceFilterComboBoxModel<T>
- Parameters:
items
- the items to display in this combo box model- See Also:
-
filterItems
public final void filterItems()Description copied from interface:FilterModel
Filters this model according to the condition specified byFilterModel.includeCondition()
. If no include condition is specified this method does nothing. This method does not interfere with the internal ordering of the visible items.- Specified by:
filterItems
in interfaceFilterModel<T>
- See Also:
-
visibleItems
- Specified by:
visibleItems
in interfaceFilterModel<T>
- Returns:
- an unmodifiable view of the visible items, in the order they appear in the model
-
filteredItems
- Specified by:
filteredItems
in interfaceFilterModel<T>
- Returns:
- an unmodifiable view of the filtered items
-
items
- Specified by:
items
in interfaceFilterModel<T>
- Returns:
- an unmodifiable view of all visible and filtered items in this model
- See Also:
-
includeCondition
- Specified by:
includeCondition
in interfaceFilterModel<T>
- Returns:
- the include condition value
-
filteredCount
public final int filteredCount()- Specified by:
filteredCount
in interfaceFilterModel<T>
- Returns:
- the number of currently filtered items
-
visibleCount
public final int visibleCount()- Specified by:
visibleCount
in interfaceFilterModel<T>
- Returns:
- the number of currently visible items
-
visible
Description copied from interface:FilterModel
Returns true if this model contains the given item, and it is visible, that is, not filtered- Specified by:
visible
in interfaceFilterModel<T>
- Parameters:
item
- the item- Returns:
- true if the given item is visible
-
filtered
Description copied from interface:FilterModel
Returns true if this model contains the given item, and it is filtered, that is, is not visible- Specified by:
filtered
in interfaceFilterModel<T>
- Parameters:
item
- the item- Returns:
- true if the given item is filtered
-
add
Description copied from interface:FilterComboBoxModel
Adds the given item to this model, respecting the sorting order if specified. If this model already contains the item, calling this method has no effect. Note that if the item does not satisfy the include condition, it will be filtered right away.- Specified by:
add
in interfaceFilterComboBoxModel<T>
- Parameters:
item
- the item to add- See Also:
-
remove
Description copied from interface:FilterComboBoxModel
Removes the given item from this model- Specified by:
remove
in interfaceFilterComboBoxModel<T>
- Parameters:
item
- the item to remove
-
replace
Description copied from interface:FilterComboBoxModel
Replaces the given item in this combo box model- Specified by:
replace
in interfaceFilterComboBoxModel<T>
- Parameters:
item
- the item to replacereplacement
- the replacement item
-
sortItems
public final void sortItems()Description copied from interface:FilterComboBoxModel
Sorts the items in this model- Specified by:
sortItems
in interfaceFilterComboBoxModel<T>
- See Also:
-
containsItem
Description copied from interface:FilterModel
Returns true if this model contains the given item, visible or filtered.- Specified by:
containsItem
in interfaceFilterModel<T>
- Parameters:
item
- the item- Returns:
- true if this model contains the item
-
comparator
Description copied from interface:FilterComboBoxModel
Controls the Comparator used when sorting the visible items in this model and sorts the model accordingly. This Comparator must take into account the null value if a null item has been set viaFilterComboBoxModel.nullItem()
. If a nullcomparator
is provided no sorting will be performed.- Specified by:
comparator
in interfaceFilterComboBoxModel<T>
- Returns:
- the Value controlling the comparator used when sorting, value may be null if the items of this model should not be sorted
-
validator
Description copied from interface:FilterComboBoxModel
Provides a way for the model to prevent the addition of certain items. Trying to add items that fail validation will result in an exception. Note that any translation of the selected item is done before validation.- Specified by:
validator
in interfaceFilterComboBoxModel<T>
- Returns:
- the Value controlling the item validator
-
selectedItemTranslator
Description copied from interface:FilterComboBoxModel
Provides a way for the combo box model to translate an item when it is selected, such as selecting the String "1" in a String based model when selected item is set to the number 1.- Specified by:
selectedItemTranslator
in interfaceFilterComboBoxModel<T>
- Returns:
- the Value controlling the selected item translator
-
validSelectionPredicate
Description copied from interface:FilterComboBoxModel
Provides a way for the combo box model to prevent the selection of certain items.- Specified by:
validSelectionPredicate
in interfaceFilterComboBoxModel<T>
- Returns:
- the Value controlling the valid selection predicate
-
includeNull
- Specified by:
includeNull
in interfaceFilterComboBoxModel<T>
- Returns:
- the State controlling whether a null value is included as the first item
- See Also:
-
nullItem
Description copied from interface:FilterComboBoxModel
Controls the item that should represent the null value in this model. Note thatFilterComboBoxModel.includeNull()
must be used as well to enable the null value.- Specified by:
nullItem
in interfaceFilterComboBoxModel<T>
- Returns:
- the Value controlling the item representing null
- See Also:
-
nullSelected
public final boolean nullSelected()Description copied from interface:FilterComboBoxModel
Returns true if this model contains null and it is selected.- Specified by:
nullSelected
in interfaceFilterComboBoxModel<T>
- Returns:
- true if this model contains null and it is selected, false otherwise
- See Also:
-
selectionEmpty
- Specified by:
selectionEmpty
in interfaceFilterComboBoxModel<T>
- Returns:
- a StateObserver indicating whether the selection is empty or the value representing null is selected
-
selectedValue
- Specified by:
selectedValue
in interfaceFilterComboBoxModel<T>
- Returns:
- the selected value, null in case the value representing null is selected
- See Also:
-
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.nullItem()
,FilterComboBoxModel.selectedValue()
is usually what you want
-
setSelectedItem
- Specified by:
setSelectedItem
in interfaceComboBoxModel<T>
-
filterSelectedItem
Description copied from interface:FilterComboBoxModel
Specifies whether filtering can change the selected item, if true then the selected item is set to null when the currently selected item is filtered from the model, otherwise the selected item can potentially represent a value which is not currently visible in the model. This is true by default.- Specified by:
filterSelectedItem
in interfaceFilterComboBoxModel<T>
- Returns:
- the State controlling whether the selected item is changed when it is filtered
-
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 via the given finder instance
-
selectionEvent
- Specified by:
selectionEvent
in interfaceFilterComboBoxModel<T>
- Returns:
- an observer notified each time the selection changes
-