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:
is.codion.common.model.FilterModel<is.codion.common.item.Item<T>>,FilterComboBoxModel<is.codion.common.item.Item<T>>,ComboBoxModel<is.codion.common.item.Item<T>>,ListModel<is.codion.common.item.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> -
Field Summary
Fields inherited from interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel
COMBO_BOX_NULL_CAPTIONFields inherited from interface is.codion.common.model.FilterModel
ASYNC_REFRESH -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdds the given item to this model, respecting the sorting order if specified.final voidaddListDataListener(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 voidclear()Clears all items from this combo box model, including the null item and sets the selected item to nullfinal booleancleared()final is.codion.common.value.Value<Comparator<is.codion.common.item.Item<T>>>Controls the Comparator used when sorting the visible items in this model and sorts the model accordingly.final booleancontainsItem(is.codion.common.item.Item<T> item) final <V> is.codion.common.value.Value<V>createSelectorValue(FilterComboBoxModel.ItemFinder<is.codion.common.item.Item<T>, V> itemFinder) final booleanfinal intfinal Collection<is.codion.common.item.Item<T>>final voidfinal is.codion.common.state.StateSpecifies 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.final is.codion.common.item.Item<T>getElementAt(int index) final is.codion.common.item.Item<T>final intgetSize()final is.codion.common.state.StateintReturns 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<is.codion.common.item.Item<T>> items) final Collection<is.codion.common.item.Item<T>>items()final is.codion.common.value.Value<is.codion.common.item.Item<T>>nullItem()Controls the item that should represent the null value in this model.final booleanReturns true if this model contains null and it is selected.final voidrefresh()final is.codion.common.model.FilterModel.Refresher<is.codion.common.item.Item<T>>final voidrefreshThen(Consumer<Collection<is.codion.common.item.Item<T>>> afterRefresh) final voidRemoves the given item from this modelfinal voidremoveListDataListener(ListDataListener listener) final voidReplaces 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 is.codion.common.item.Item<T>final is.codion.common.state.StateObserverfinal is.codion.common.event.EventObserver<is.codion.common.item.Item<T>>final voidsetItems(Collection<is.codion.common.item.Item<T>> items) Resets the items of this model using the values found initems.final voidsetSelectedItem(Object item) static <T> ItemComboBoxModel<T>static <T> ItemComboBoxModel<T>sortedItemComboBoxModel(Comparator<is.codion.common.item.Item<T>> comparator) static <T> ItemComboBoxModel<T>sortedItemComboBoxModel(List<is.codion.common.item.Item<T>> items) static <T> ItemComboBoxModel<T>sortedItemComboBoxModel(List<is.codion.common.item.Item<T>> items, Comparator<is.codion.common.item.Item<T>> comparator) final voidSorts 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 booleanfinal 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
public static <T> ItemComboBoxModel<T> sortedItemComboBoxModel(List<is.codion.common.item.Item<T>> items) - Type Parameters:
T- the Item value type- Parameters:
items- the items- Returns:
- a new combo box model
-
sortedItemComboBoxModel
public static <T> ItemComboBoxModel<T> sortedItemComboBoxModel(Comparator<is.codion.common.item.Item<T>> comparator) - 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<is.codion.common.item.Item<T>> items, Comparator<is.codion.common.item.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
public final is.codion.common.model.FilterModel.Refresher<is.codion.common.item.Item<T>> refresher()- Specified by:
refresherin interfaceis.codion.common.model.FilterModel<T>
-
refresh
public final void refresh()- Specified by:
refreshin interfaceis.codion.common.model.FilterModel<T>
-
refreshThen
- Specified by:
refreshThenin interfaceis.codion.common.model.FilterModel<T>
-
clear
public final void clear()Description copied from interface:FilterComboBoxModelClears all items from this combo box model, including the null item and sets the selected item to null- Specified by:
clearin interfaceFilterComboBoxModel<T>
-
cleared
public final boolean cleared()- Specified by:
clearedin interfaceFilterComboBoxModel<T>- Returns:
- true if the model data has been cleared and needs to be refreshed
-
setItems
Description copied from interface:FilterComboBoxModelResets the items of this model using the values found initems.- Specified by:
setItemsin interfaceFilterComboBoxModel<T>- Parameters:
items- the items to display in this combo box model- See Also:
-
filterItems
public final void filterItems()- Specified by:
filterItemsin interfaceis.codion.common.model.FilterModel<T>
-
visibleItems
- Specified by:
visibleItemsin interfaceis.codion.common.model.FilterModel<T>
-
filteredItems
- Specified by:
filteredItemsin interfaceis.codion.common.model.FilterModel<T>
-
items
- Specified by:
itemsin interfaceis.codion.common.model.FilterModel<T>
-
includeCondition
public final is.codion.common.value.Value<Predicate<is.codion.common.item.Item<T>>> includeCondition()- Specified by:
includeConditionin interfaceis.codion.common.model.FilterModel<T>
-
filteredCount
public final int filteredCount()- Specified by:
filteredCountin interfaceis.codion.common.model.FilterModel<T>
-
visibleCount
public final int visibleCount()- Specified by:
visibleCountin interfaceis.codion.common.model.FilterModel<T>
-
visible
- Specified by:
visiblein interfaceis.codion.common.model.FilterModel<T>
-
filtered
- Specified by:
filteredin interfaceis.codion.common.model.FilterModel<T>
-
add
Description copied from interface:FilterComboBoxModelAdds 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:
addin interfaceFilterComboBoxModel<T>- Parameters:
item- the item to add- See Also:
-
FilterModel.includeCondition()
-
remove
Description copied from interface:FilterComboBoxModelRemoves the given item from this model- Specified by:
removein interfaceFilterComboBoxModel<T>- Parameters:
item- the item to remove
-
replace
public final void replace(is.codion.common.item.Item<T> item, is.codion.common.item.Item<T> replacement) Description copied from interface:FilterComboBoxModelReplaces the given item in this combo box model- Specified by:
replacein interfaceFilterComboBoxModel<T>- Parameters:
item- the item to replacereplacement- the replacement item
-
sortItems
public final void sortItems()Description copied from interface:FilterComboBoxModelSorts the items in this model- Specified by:
sortItemsin interfaceFilterComboBoxModel<T>- See Also:
-
containsItem
- Specified by:
containsItemin interfaceis.codion.common.model.FilterModel<T>
-
comparator
Description copied from interface:FilterComboBoxModelControls 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 nullcomparatoris provided no sorting will be performed.- Specified by:
comparatorin 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:FilterComboBoxModelProvides 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:
validatorin interfaceFilterComboBoxModel<T>- Returns:
- the Value controlling the item validator
-
selectedItemTranslator
public final is.codion.common.value.Value<Function<Object,is.codion.common.item.Item<T>>> selectedItemTranslator()Description copied from interface:FilterComboBoxModelProvides 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:
selectedItemTranslatorin interfaceFilterComboBoxModel<T>- Returns:
- the Value controlling the selected item translator
-
validSelectionPredicate
public final is.codion.common.value.Value<Predicate<is.codion.common.item.Item<T>>> validSelectionPredicate()Description copied from interface:FilterComboBoxModelProvides a way for the combo box model to prevent the selection of certain items.- Specified by:
validSelectionPredicatein interfaceFilterComboBoxModel<T>- Returns:
- the Value controlling the valid selection predicate
-
includeNull
public final is.codion.common.state.State includeNull()- Specified by:
includeNullin interfaceFilterComboBoxModel<T>- Returns:
- the State controlling whether a null value is included as the first item
- See Also:
-
nullItem
Description copied from interface:FilterComboBoxModelControls 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:
nullItemin interfaceFilterComboBoxModel<T>- Returns:
- the Value controlling the item representing null
- See Also:
-
nullSelected
public final boolean nullSelected()Description copied from interface:FilterComboBoxModelReturns true if this model contains null and it is selected.- Specified by:
nullSelectedin interfaceFilterComboBoxModel<T>- Returns:
- true if this model contains null and it is selected, false otherwise
- See Also:
-
selectionEmpty
public final is.codion.common.state.StateObserver selectionEmpty()- Specified by:
selectionEmptyin interfaceFilterComboBoxModel<T>- Returns:
- a StateObserver indicating whether the selection is empty or the value representing null is selected
-
selectedValue
- Specified by:
selectedValuein interfaceFilterComboBoxModel<T>- Returns:
- the selected value, null in case the value representing null is selected
- See Also:
-
getSelectedItem
- Specified by:
getSelectedItemin interfaceComboBoxModel<T>- Specified by:
getSelectedItemin interfaceFilterComboBoxModel<T>- Returns:
- the selected item, N.B. this can include the
nullItemin case it has been set viaFilterComboBoxModel.nullItem(),FilterComboBoxModel.selectedValue()is usually what you want
-
setSelectedItem
- Specified by:
setSelectedItemin interfaceComboBoxModel<T>
-
filterSelectedItem
public final is.codion.common.state.State filterSelectedItem()Description copied from interface:FilterComboBoxModelSpecifies 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:
filterSelectedItemin interfaceFilterComboBoxModel<T>- Returns:
- the State controlling whether the selected item is changed when it is filtered
-
addListDataListener
- Specified by:
addListDataListenerin interfaceListModel<T>
-
removeListDataListener
- Specified by:
removeListDataListenerin interfaceListModel<T>
-
getElementAt
- Specified by:
getElementAtin interfaceListModel<T>
-
getSize
public final int getSize() -
createSelectorValue
public final <V> is.codion.common.value.Value<V> createSelectorValue(FilterComboBoxModel.ItemFinder<is.codion.common.item.Item<T>, V> itemFinder) - Specified by:
createSelectorValuein 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:
selectionEventin interfaceFilterComboBoxModel<T>- Returns:
- an observer notified each time the selection changes
-