T
- the type of values in this combo box modelpublic class SwingFilteredComboBoxModel<T> extends java.lang.Object implements FilteredComboBoxModel<T>, javax.swing.ComboBoxModel<T>
FilteredComboBoxModel
implementation.Constructor and Description |
---|
SwingFilteredComboBoxModel()
Instantiates a new SwingFilteredComboBoxModel, without a nullValueString.
|
SwingFilteredComboBoxModel(T nullValue)
Instantiates a new SwingFilteredComboBoxModel, without a nullValueString.
|
SwingFilteredComboBoxModel(T nullValue,
java.util.Comparator<T> sortComparator)
Instantiates a new SwingFilteredComboBoxModel with the given nullValueString.
|
Modifier and Type | Method and Description |
---|---|
void |
addFilteringListener(EventListener listener) |
void |
addItem(T item)
Adds the given item to this model, respecting the sorting order if specified
|
void |
addListDataListener(javax.swing.event.ListDataListener listener) |
void |
addSelectionListener(EventDataListener<T> listener) |
protected boolean |
allowSelectionChange(T itemToSelect) |
void |
clear()
Clears all data from this refreshable instance
|
boolean |
contains(T item,
boolean includeFiltered)
Returns true if this model contains the given item, visible or filtered.
|
void |
filterContents()
Filters the table according to the condition returned by
getFilterCondition() . |
protected void |
fireContentsChanged()
Fires a
ListDataEvent.CONTENTS_CHANGED event on all registered listeners |
java.util.List<T> |
getAllItems() |
T |
getElementAt(int index) |
FilterCondition<T> |
getFilterCondition()
Returns the filter condition defined by this model, null if no filter condition has been set.
|
int |
getFilteredItemCount() |
java.util.List<T> |
getFilteredItems() |
T |
getNullValue() |
T |
getSelectedItem() |
T |
getSelectedValue() |
int |
getSize() |
java.util.Comparator<T> |
getSortComparator() |
int |
getVisibleItemCount() |
java.util.List<T> |
getVisibleItems() |
protected java.util.List<T> |
initializeContents() |
boolean |
isCleared() |
boolean |
isFiltered(T item)
Returns true if the given item is being filtered in this model, that is, is not visible
|
boolean |
isFilterSelectedItem()
Specifies whether or not 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 |
isNullValueSelected()
Returns true if the value representing null is selected, false if no such value has been
specified or if it is not selected.
|
boolean |
isSelectionEmpty() |
boolean |
isVisible(T item)
Returns true if the given item is visible, that is, not filtered in this model
|
void |
refresh()
Performs a refresh, reloading the relevant data
|
void |
removeFilteringListener(EventListener listener) |
void |
removeItem(T item)
Removes the given item from this model
|
void |
removeListDataListener(javax.swing.event.ListDataListener listener) |
void |
removeSelectionListener(EventDataListener listener) |
void |
setContents(java.util.Collection<T> contents)
Resets the contents of this model using the values found in
contents ,
if contents is null then the model is considered to be cleared. |
void |
setFilterCondition(FilterCondition<T> filterCondition)
Sets the filter condition and filters the model
|
void |
setFilterSelectedItem(boolean value)
Specifies whether or not 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 |
setNullValue(T nullValue)
Sets the value which should represent a null value, a refresh is required for it to show up
|
void |
setSelectedItem(java.lang.Object anItem) |
void |
setSortComparator(java.util.Comparator<T> sortComparator)
Sets the Comparator used when sorting the items visible in this model and sorts the model accordingly.
|
protected T |
translateSelectionItem(java.lang.Object item) |
public SwingFilteredComboBoxModel()
public SwingFilteredComboBoxModel(T nullValue)
nullValue
- a value representing a null value, which is shown at the top of the item listpublic SwingFilteredComboBoxModel(T nullValue, java.util.Comparator<T> sortComparator)
nullValue
- a value representing a null value, which is shown at the top of the item listsortComparator
- the Comparator used to sort the contents of this combo box model, if null then
the contents are not sortedisNullValueSelected()
public final void refresh()
refresh
in interface Refreshable
public final void clear()
clear
in interface Refreshable
public final boolean isCleared()
isCleared
in interface FilteredComboBoxModel<T>
public final void setContents(java.util.Collection<T> contents)
contents
,
if contents is null then the model is considered to be cleared.setContents
in interface FilteredComboBoxModel<T>
contents
- the contents to display in this combo box modelFilteredComboBoxModel.isCleared()
public final void filterContents()
getFilterCondition()
.
If no filter condition is specified this method does nothing.
This method does not interfere with the internal ordering of the visible items.filterContents
in interface FilteredModel<T>
FilteredModel.getFilterCondition()
,
FilteredModel.setFilterCondition(FilterCondition)
,
FilteredModel.addFilteringListener(EventListener)
public final java.util.List<T> getVisibleItems()
getVisibleItems
in interface FilteredModel<T>
public final java.util.List<T> getFilteredItems()
getFilteredItems
in interface FilteredModel<T>
public final java.util.List<T> getAllItems()
getAllItems
in interface FilteredModel<T>
public final void setFilterCondition(FilterCondition<T> filterCondition)
setFilterCondition
in interface FilteredModel<T>
filterCondition
- the FilterCondition to use, null if no filtering should be performedpublic final FilterCondition<T> getFilterCondition()
getFilterCondition
in interface FilteredModel<T>
public final int getFilteredItemCount()
getFilteredItemCount
in interface FilteredModel<T>
public final int getVisibleItemCount()
getVisibleItemCount
in interface FilteredModel<T>
public final boolean isVisible(T item)
isVisible
in interface FilteredModel<T>
item
- the itempublic final boolean isFiltered(T item)
isFiltered
in interface FilteredModel<T>
item
- the itempublic final void addItem(T item)
addItem
in interface FilteredComboBoxModel<T>
item
- the item to addpublic final void removeItem(T item)
removeItem
in interface FilteredComboBoxModel<T>
item
- the item to removepublic final boolean contains(T item, boolean includeFiltered)
contains
in interface FilteredModel<T>
item
- the itemincludeFiltered
- if true then the filtered items are includedpublic final java.util.Comparator<T> getSortComparator()
getSortComparator
in interface FilteredComboBoxModel<T>
public final void setSortComparator(java.util.Comparator<T> sortComparator)
nullValueString
is specified.
If a null sortComparator
is provided no sorting will be performed.setSortComparator
in interface FilteredComboBoxModel<T>
sortComparator
- the Comparator, null if the contents of this model should not be sortedpublic final T getNullValue()
getNullValue
in interface FilteredComboBoxModel<T>
public final void setNullValue(T nullValue)
setNullValue
in interface FilteredComboBoxModel<T>
nullValue
- a value which is used to represent a null valuepublic final boolean isNullValueSelected()
isNullValueSelected
in interface FilteredComboBoxModel<T>
FilteredComboBoxModel.setNullValue(Object)
public final boolean isSelectionEmpty()
isSelectionEmpty
in interface FilteredComboBoxModel<T>
public final T getSelectedValue()
getSelectedValue
in interface FilteredComboBoxModel<T>
FilteredComboBoxModel.setNullValue(Object)
public final T getSelectedItem()
getSelectedItem
in interface javax.swing.ComboBoxModel<T>
getSelectedItem
in interface FilteredComboBoxModel<T>
nullValue
in case it has been set, getSelectedValue()
is usually what you wantpublic final void setSelectedItem(java.lang.Object anItem)
setSelectedItem
in interface javax.swing.ComboBoxModel<T>
setSelectedItem
in interface FilteredComboBoxModel<T>
anItem
- the item to selectpublic void setFilterSelectedItem(boolean value)
setFilterSelectedItem
in interface FilteredComboBoxModel<T>
value
- if true then the selected item is changed when it is filtered out,public boolean isFilterSelectedItem()
isFilterSelectedItem
in interface FilteredComboBoxModel<T>
public final void addListDataListener(javax.swing.event.ListDataListener listener)
addListDataListener
in interface javax.swing.ListModel<T>
public final void removeListDataListener(javax.swing.event.ListDataListener listener)
removeListDataListener
in interface javax.swing.ListModel<T>
public final T getElementAt(int index)
getElementAt
in interface javax.swing.ListModel<T>
getElementAt
in interface FilteredComboBoxModel<T>
index
- the indexpublic final int getSize()
getSize
in interface javax.swing.ListModel<T>
getSize
in interface FilteredComboBoxModel<T>
public final void addFilteringListener(EventListener listener)
addFilteringListener
in interface FilteredModel<T>
listener
- a listener notified each time this model is filteredpublic final void removeFilteringListener(EventListener listener)
removeFilteringListener
in interface FilteredModel<T>
listener
- the listener to removepublic final void addSelectionListener(EventDataListener<T> listener)
addSelectionListener
in interface FilteredComboBoxModel<T>
listener
- a listener notified each time the selection changespublic final void removeSelectionListener(EventDataListener listener)
removeSelectionListener
in interface FilteredComboBoxModel<T>
listener
- a selection listener to removeprotected java.util.List<T> initializeContents()
protected boolean allowSelectionChange(T itemToSelect)
itemToSelect
- the item to be selectedprotected T translateSelectionItem(java.lang.Object item)
item
- the item to be selectedprotected final void fireContentsChanged()
ListDataEvent.CONTENTS_CHANGED
event on all registered listeners