Module is.codion.swing.common.model
Class FilteredComboBoxModel<T>
java.lang.Object
is.codion.swing.common.model.component.combobox.FilteredComboBoxModel<T>
- Type Parameters:
T- the type of values in this combo box model
- All Implemented Interfaces:
is.codion.common.model.FilteredModel<T>,ComboBoxModel<T>,ListModel<T>
- Direct Known Subclasses:
ItemComboBoxModel
public class FilteredComboBoxModel<T>
extends Object
implements is.codion.common.model.FilteredModel<T>, ComboBoxModel<T>
A default combo box model implementation based on
FilteredModel.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceResponsible for finding an item of typeFilteredComboBoxModel.ItemFinderby a single value of typeFilteredComboBoxModel.ItemFinder. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final is.codion.common.property.PropertyValue<String>Specifies the caption used by default to represent null in combo box models.Fields inherited from interface is.codion.common.model.FilteredModel
ASYNC_REFRESH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdds the given item to this model, respecting the sorting order if specified.final voidaddListDataListener(ListDataListener listener) 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<T>>Controls the Comparator used when sorting the visible items in this model and sorts the model accordingly.final booleancontainsItem(T item) final <V> is.codion.common.value.Value<V>createSelectorValue(FilteredComboBoxModel.ItemFinder<T, V> itemFinder) final booleanfinal intfinal Collection<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 TgetElementAt(int index) final Tfinal intgetSize()final is.codion.common.state.Statefinal Collection<T>items()Provides a way for the model to prevent the addition of certain items.final is.codion.common.value.Value<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.FilteredModel.Refresher<T>final voidrefreshThen(Consumer<Collection<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 Tfinal is.codion.common.state.StateObserverfinal is.codion.common.event.EventObserver<T>final voidsetItems(Collection<T> items) Resets the items of this model using the values found initems.final voidsetSelectedItem(Object item) Provides a way for the combo box model to prevent the selection of certain items.final booleanfinal int
-
Field Details
-
COMBO_BOX_NULL_CAPTION
Specifies the caption used by default to represent null in combo box models. Value type: String
Default value: -
-
-
Constructor Details
-
FilteredComboBoxModel
public FilteredComboBoxModel()Instantiates a new FilteredComboBoxModel. The model items are sorted automatically with a default collation based comparator. To prevent sorting set the comparator to null viacomparator()before adding items.
-
-
Method Details
-
refresher
- Specified by:
refresherin interfaceis.codion.common.model.FilteredModel<T>
-
refresh
public final void refresh()- Specified by:
refreshin interfaceis.codion.common.model.FilteredModel<T>
-
refreshThen
- Specified by:
refreshThenin interfaceis.codion.common.model.FilteredModel<T>
-
clear
public final void clear()Clears all items from this combo box model, including the null item and sets the selected item to null -
cleared
public final boolean cleared()- Returns:
- true if the model data has been cleared and needs to be refreshed
-
setItems
Resets the items of this model using the values found initems.- Parameters:
items- the items to display in this combo box model- Throws:
IllegalArgumentException- in case an item fails validation- See Also:
-
filterItems
public final void filterItems()- Specified by:
filterItemsin interfaceis.codion.common.model.FilteredModel<T>
-
visibleItems
- Specified by:
visibleItemsin interfaceis.codion.common.model.FilteredModel<T>
-
filteredItems
- Specified by:
filteredItemsin interfaceis.codion.common.model.FilteredModel<T>
-
items
- Specified by:
itemsin interfaceis.codion.common.model.FilteredModel<T>
-
includeCondition
- Specified by:
includeConditionin interfaceis.codion.common.model.FilteredModel<T>
-
filteredCount
public final int filteredCount()- Specified by:
filteredCountin interfaceis.codion.common.model.FilteredModel<T>
-
visibleCount
public final int visibleCount()- Specified by:
visibleCountin interfaceis.codion.common.model.FilteredModel<T>
-
visible
- Specified by:
visiblein interfaceis.codion.common.model.FilteredModel<T>
-
filtered
- Specified by:
filteredin interfaceis.codion.common.model.FilteredModel<T>
-
add
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.- Parameters:
item- the item to add- Throws:
IllegalArgumentException- in case the item fails validation- See Also:
-
remove
Removes the given item from this model- Parameters:
item- the item to remove
-
replace
Replaces the given item in this combo box model- Parameters:
item- the item to replacereplacement- the replacement item- Throws:
IllegalArgumentException- in case the replacement item fails validation
-
containsItem
- Specified by:
containsItemin interfaceis.codion.common.model.FilteredModel<T>
-
comparator
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 vianullItem(). If a nullcomparatoris provided no sorting will be performed.- Returns:
- the Value controlling the comparator used when sorting, value may be null if the items of this model should not be sorted
-
itemValidator
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.- Returns:
- the Value controlling the item validator
-
selectedItemTranslator
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.- Returns:
- the Value controlling the selected item translator
-
validSelectionPredicate
Provides a way for the combo box model to prevent the selection of certain items.- Returns:
- the Value controlling the valid selection predicate
-
includeNull
public final is.codion.common.state.State includeNull()- Returns:
- the State controlling whether a null value is included as the first item
- See Also:
-
nullItem
Controls the item that should represent the null value in this model. Note thatincludeNull()must be used as well to enable the null value.- Returns:
- the Value controlling the item representing null
- See Also:
-
nullSelected
public final boolean nullSelected()Returns true if this model contains null and it is selected.- Returns:
- true if this model contains null and it is selected, false otherwise
- See Also:
-
selectionEmpty
public final is.codion.common.state.StateObserver selectionEmpty()- Returns:
- a StateObserver indicating whether the selection is empty or the value representing null is selected
-
selectedValue
- Returns:
- the selected value, null in case the value representing null is selected
- See Also:
-
getSelectedItem
- Specified by:
getSelectedItemin interfaceComboBoxModel<T>- Returns:
- the selected item, N.B. this can include the
nullItemin case it has been set vianullItem(),selectedValue()is usually what you want
-
setSelectedItem
- Specified by:
setSelectedItemin interfaceComboBoxModel<T>- Parameters:
item- the item to select
-
filterSelectedItem
public final is.codion.common.state.State filterSelectedItem()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.- 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>- Parameters:
index- the index- Returns:
- the item at the given index
-
getSize
public final int getSize() -
createSelectorValue
public final <V> is.codion.common.value.Value<V> createSelectorValue(FilteredComboBoxModel.ItemFinder<T, V> itemFinder) - 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
- Returns:
- an observer notified each time the selection changes
-