T
- the type of values in this combo box modelpublic class FilteredComboBoxModel<T> extends Object implements FilteredModel<T>, ComboBoxModel<T>
FilteredModel
.setIncludeCondition(Predicate)
Modifier and Type | Class and Description |
---|---|
static interface |
FilteredComboBoxModel.ItemFinder<T,V>
Responsible for finding an item of type
T by a single value of type V . |
Modifier and Type | Field and Description |
---|---|
static PropertyValue<String> |
COMBO_BOX_NULL_CAPTION
Specifies the caption used by default to represent null in combo box models.
|
ASYNC_REFRESH
Constructor and Description |
---|
FilteredComboBoxModel()
Instantiates a new FilteredComboBoxModel.
|
Modifier and Type | Method and Description |
---|---|
void |
addFilterListener(EventListener listener) |
void |
addItem(T item)
Adds the given item to this model, respecting the sorting order if specified.
|
void |
addListDataListener(ListDataListener listener) |
void |
addRefreshFailedListener(EventDataListener<Throwable> listener) |
void |
addRefreshListener(EventListener listener) |
void |
addSelectionListener(EventDataListener<T> listener) |
protected boolean |
allowSelectionChange(T itemToSelect) |
void |
clear()
Clears all items from this combo box model
|
boolean |
containsItem(T item)
Returns true if this model contains the given item, visible or filtered.
|
<V> Value<V> |
createSelectorValue(FilteredComboBoxModel.ItemFinder<T,V> itemFinder) |
int |
filteredItemCount() |
List<T> |
filteredItems() |
void |
filterItems()
Filters this model according to the condition returned by
FilteredModel.getIncludeCondition() . |
protected void |
fireContentsChanged()
Fires a
ListDataEvent.CONTENTS_CHANGED event on all registered listeners |
T |
getElementAt(int index) |
Predicate<T> |
getIncludeCondition()
Returns the include condition used by this model, null if no include condition has been set.
|
T |
getSelectedItem() |
int |
getSize() |
Comparator<T> |
getSortComparator() |
boolean |
isAsyncRefresh() |
boolean |
isCleared() |
boolean |
isFiltered(T item)
Returns true if this model contains the given item, and it is filtered, that is, is not visible
|
boolean |
isFilterSelectedItem()
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.
|
boolean |
isIncludeNull() |
boolean |
isNullSelected()
Returns true if this model contains null and it is selected.
|
boolean |
isSelectionEmpty() |
boolean |
isVisible(T item)
Returns true if this model contains the given item, and it is visible, that is, not filtered
|
List<T> |
items() |
void |
refresh()
Refreshes the items in this combo box model.
|
StateObserver |
refreshingObserver() |
protected Collection<T> |
refreshItems() |
void |
refreshThen(Consumer<Collection<T>> afterRefresh)
Refreshes the data in this model.
|
void |
removeFilterListener(EventListener listener) |
void |
removeItem(T item)
Removes the given item from this model
|
void |
removeListDataListener(ListDataListener listener) |
void |
removeRefreshFailedListener(EventDataListener<Throwable> listener) |
void |
removeRefreshListener(EventListener listener) |
void |
removeSelectionListener(EventDataListener<T> listener) |
void |
replaceItem(T item,
T replacement)
Replaces the given item in this combo box model
|
T |
selectedValue() |
void |
setAsyncRefresh(boolean asyncRefresh)
Sometimes we'd like to be able to refresh one or more models and perform some action on
the refreshed data, after the refresh has finished, such as selecting a particular item or such.
|
void |
setFilterSelectedItem(boolean 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.
|
void |
setIncludeCondition(Predicate<T> includeCondition)
Sets the include condition and filters the model
|
void |
setIncludeNull(boolean includeNull) |
void |
setItems(Collection<T> items)
Resets the items of this model using the values found in
items ,
if items is null then the model is considered to be cleared. |
void |
setNullItem(T nullItem)
Sets the item that should represent the null value in this model.
|
void |
setSelectedItem(Object item) |
void |
setSortComparator(Comparator<T> sortComparator)
Sets the Comparator used when sorting the items visible in this model and sorts the model accordingly.
|
protected T |
translateSelectionItem(Object item) |
int |
visibleItemCount() |
List<T> |
visibleItems() |
public static final PropertyValue<String> COMBO_BOX_NULL_CAPTION
public FilteredComboBoxModel()
setSortComparator(Comparator)
with a null argument before adding items.public final boolean isAsyncRefresh()
isAsyncRefresh
in interface FilteredModel<T>
FilteredModel.ASYNC_REFRESH
public final void setAsyncRefresh(boolean asyncRefresh)
FilteredModel
setAsyncRefresh
in interface FilteredModel<T>
asyncRefresh
- true if asynchronous refreshing should be enabled, true by defaultFilteredModel.ASYNC_REFRESH
public final void refresh()
refresh
in interface FilteredModel<T>
RuntimeException
- in case of an exception when running refresh synchronously, as in, not on the Event Dispatch ThreadaddRefreshFailedListener(EventDataListener)
,
setAsyncRefresh(boolean)
public final void refreshThen(Consumer<Collection<T>> afterRefresh)
FilteredModel
FilteredModel.addRefreshFailedListener(EventDataListener)
to listen for exceptions that happen during asynchronous refresh.refreshThen
in interface FilteredModel<T>
afterRefresh
- called after a successful refresh, may be nullFilteredModel.refreshingObserver()
,
FilteredModel.addRefreshListener(EventListener)
,
FilteredModel.addRefreshFailedListener(EventDataListener)
,
FilteredModel.setAsyncRefresh(boolean)
public final StateObserver refreshingObserver()
refreshingObserver
in interface FilteredModel<T>
public final void clear()
public final boolean isCleared()
public final void setItems(Collection<T> items)
items
,
if items is null then the model is considered to be cleared.items
- the items to display in this combo box modelisCleared()
public final void filterItems()
FilteredModel
FilteredModel.getIncludeCondition()
.
If no include condition is specified this method does nothing.
This method does not interfere with the internal ordering of the visible items.filterItems
in interface FilteredModel<T>
FilteredModel.getIncludeCondition()
,
FilteredModel.setIncludeCondition(Predicate)
,
FilteredModel.addFilterListener(EventListener)
public final List<T> visibleItems()
visibleItems
in interface FilteredModel<T>
public final List<T> filteredItems()
filteredItems
in interface FilteredModel<T>
public final List<T> items()
items
in interface FilteredModel<T>
FilteredModel.visibleItems()
,
FilteredModel.filteredItems()
public final void setIncludeCondition(Predicate<T> includeCondition)
FilteredModel
setIncludeCondition
in interface FilteredModel<T>
includeCondition
- the Predicate to use when filtering, null if no filtering should be performedpublic final Predicate<T> getIncludeCondition()
FilteredModel
getIncludeCondition
in interface FilteredModel<T>
public final int filteredItemCount()
filteredItemCount
in interface FilteredModel<T>
public final int visibleItemCount()
visibleItemCount
in interface FilteredModel<T>
public final boolean isVisible(T item)
FilteredModel
isVisible
in interface FilteredModel<T>
item
- the itempublic final boolean isFiltered(T item)
FilteredModel
isFiltered
in interface FilteredModel<T>
item
- the itempublic final void addItem(T item)
item
- the item to addsetIncludeCondition(Predicate)
public final void removeItem(T item)
item
- the item to removepublic final void replaceItem(T item, T replacement)
item
- the item to replacereplacement
- the replacement itempublic final boolean containsItem(T item)
FilteredModel
containsItem
in interface FilteredModel<T>
item
- the itempublic final Comparator<T> getSortComparator()
public final void setSortComparator(Comparator<T> sortComparator)
nullValueString
is specified.
If a null sortComparator
is provided no sorting will be performed.sortComparator
- the Comparator, null if the items of this model should not be sortedpublic final void setIncludeNull(boolean includeNull)
includeNull
- if true then a null value is included as the first itemsetNullItem(Object)
public final boolean isIncludeNull()
public final void setNullItem(T nullItem)
setIncludeNull(boolean)
must be called as well to enable the null value.nullItem
- the item representing nullsetIncludeNull(boolean)
public final boolean isNullSelected()
isIncludeNull()
public final boolean isSelectionEmpty()
public final T selectedValue()
isNullSelected()
public final T getSelectedItem()
getSelectedItem
in interface ComboBoxModel<T>
nullItem
in case it has been set
via setNullItem(Object)
, selectedValue()
is usually what you wantpublic final void setSelectedItem(Object item)
setSelectedItem
in interface ComboBoxModel<T>
item
- the item to selectpublic final void setFilterSelectedItem(boolean filterSelectedItem)
filterSelectedItem
- if true then the selected item is changed when it is filtered out,public final boolean isFilterSelectedItem()
public final void addListDataListener(ListDataListener listener)
addListDataListener
in interface ListModel<T>
public final void removeListDataListener(ListDataListener listener)
removeListDataListener
in interface ListModel<T>
public final T getElementAt(int index)
getElementAt
in interface ListModel<T>
index
- the indexpublic final int getSize()
public final <V> Value<V> createSelectorValue(FilteredComboBoxModel.ItemFinder<T,V> itemFinder)
V
- the value typeitemFinder
- responsible for finding the item to selectpublic final void addFilterListener(EventListener listener)
addFilterListener
in interface FilteredModel<T>
listener
- a listener notified each time this model is filteredpublic final void removeFilterListener(EventListener listener)
removeFilterListener
in interface FilteredModel<T>
listener
- the listener to removepublic final void addRefreshListener(EventListener listener)
addRefreshListener
in interface FilteredModel<T>
listener
- a listener to be notified each time this model has been successfully refreshedFilteredModel.refresh()
public final void removeRefreshListener(EventListener listener)
removeRefreshListener
in interface FilteredModel<T>
listener
- the listener to removeFilteredModel.refresh()
public final void addRefreshFailedListener(EventDataListener<Throwable> listener)
addRefreshFailedListener
in interface FilteredModel<T>
listener
- a listener to be notified each time an asynchronous refresh has failedFilteredModel.refresh()
public final void removeRefreshFailedListener(EventDataListener<Throwable> listener)
removeRefreshFailedListener
in interface FilteredModel<T>
listener
- the listener to removepublic final void addSelectionListener(EventDataListener<T> listener)
listener
- a listener notified each time the selection changespublic final void removeSelectionListener(EventDataListener<T> listener)
listener
- a selection listener to removeprotected Collection<T> refreshItems()
protected boolean allowSelectionChange(T itemToSelect)
itemToSelect
- the item to be selectedprotected T translateSelectionItem(Object item)
item
- the item to be selectedprotected final void fireContentsChanged()
ListDataEvent.CONTENTS_CHANGED
event on all registered listeners