public class FilterProxyListModel<T>
- Object
- FilterProxyListModel
ImplementsDataChangedListener, ListModel<T>
This class allows filtering/sorting a list model dynamically using a text field
Constructors
public FilterProxyListModel(ListModel<T> underlying) | The proxy is applied to the actual model and effectively hides it |
Methods
public static void install(TextField search, List l) | Installs a search field on a list making sure the filter method is invoked properly |
public static void install(TextField search, ContainerList l) | Installs a search field on a list making sure the filter method is invoked properly |
public void sort(boolean ascending) | This method performs a sort of the list, to determine the sort order this class should be derived and the compare() method should be overriden |
protected int compare(Object a, Object b, boolean ascending) | This method can be overriden by subclasses to allow sorting arbitrary objects within the list, it follows the traditional contract of the compare method in Java |
public ListModel getUnderlying() | Returns the underlying model which is needed to perform mutations on the list. |
protected boolean check(Object o, String str) | Checks whether the filter condition is matched, receives an uppercase version of the filter string to match against |
public void filter(String str) | Filters the list based on the given string |
public T getItemAt(int index) | Returns the item at the given offset |
public int getSize() | Returns the number of items in the list |
public int getSelectedIndex() | Returns the selected list offset |
public void setSelectedIndex(int index) | Sets the selected list offset can be set to -1 to clear selection |
public void addDataChangedListener(DataChangedListener l) | Invoked to indicate interest in future change events |
public void removeDataChangedListener(DataChangedListener l) | Invoked to indicate no further interest in future change events |
public void addSelectionListener(SelectionListener l) | Invoked to indicate interest in future selection events |
public void removeSelectionListener(SelectionListener l) | Invoked to indicate no further interest in future selection events |
public void addItem(T item) | Adds the specified item to the end of this list. |
public void removeItem(int index) | Removes the item at the specified position in this list. |
public void dataChanged(int type, int index) | Invoked when there was a change in the underlying model |
public boolean isStartsWithMode() | When enabled this makes the filter check that the string starts with rather than within the index |
public void setStartsWithMode(boolean startsWithMode) | When enabled this makes the filter check that the string starts with rather than within the index |
Inherited fields
Inherited methods
Constructor details
FilterProxyListModel
public FilterProxyListModel(ListModel<T> underlying)The proxy is applied to the actual model and effectively hides it
Parameters
underlyingListModel<T>- the “real” model for the list
Method details
install
public static void install(TextField search, List l)Installs a search field on a list making sure the filter method is invoked properly
install
public static void install(TextField search, ContainerList l)Installs a search field on a list making sure the filter method is invoked properly
sort
public void sort(boolean ascending)This method performs a sort of the list, to determine the sort order this class should be derived
and the compare() method should be overriden
Parameters
ascendingboolean- sort in ascending order
compare
protected int compare(Object a, Object b, boolean ascending)This method can be overriden by subclasses to allow sorting arbitrary objects within
the list, it follows the traditional contract of the compare method in Java
Parameters
aObject- first object
bObject- second object
ascendingboolean- direction of sort
Returns
1, 0 or -1 to indicate the larger/smaller object
getUnderlying
public ListModel getUnderlying()Returns the underlying model which is needed to perform mutations on the list.
Returns
the underlying model
check
protected boolean check(Object o, String str)Checks whether the filter condition is matched, receives an uppercase version of the
filter string to match against
Parameters
oObject- the object being compared
strString- the string
Returns
true if match is checked
filter
public void filter(String str)Filters the list based on the given string
Parameters
strString- the string to filter the list by
getItemAt
public T getItemAt(int index)Returns the item at the given offset
Parameters
indexint- an index into this list
Returns
the item at the specified index
getSize
public int getSize()Returns the number of items in the list
Returns
the number of items in the list
getSelectedIndex
public int getSelectedIndex()Returns the selected list offset
Returns
the selected list index
setSelectedIndex
public void setSelectedIndex(int index)Sets the selected list offset can be set to -1 to clear selection
Parameters
indexint- an index into this list
addDataChangedListener
public void addDataChangedListener(DataChangedListener l)Invoked to indicate interest in future change events
Parameters
lDataChangedListener- a data changed listener
removeDataChangedListener
public void removeDataChangedListener(DataChangedListener l)Invoked to indicate no further interest in future change events
Parameters
lDataChangedListener- a data changed listener
addSelectionListener
public void addSelectionListener(SelectionListener l)Invoked to indicate interest in future selection events
Parameters
lSelectionListener- a selection listener
removeSelectionListener
public void removeSelectionListener(SelectionListener l)Invoked to indicate no further interest in future selection events
Parameters
lSelectionListener- a selection listener
addItem
public void addItem(T item)Adds the specified item to the end of this list.
An optional operation for mutable lists, it can throw an unsupported operation
exception if a list model is not mutable.
Parameters
itemT- the item to be added
removeItem
public void removeItem(int index)Removes the item at the specified position in this list.
Parameters
indexint- the index of the item to removed
dataChanged
public void dataChanged(int type, int index)Invoked when there was a change in the underlying model
Parameters
typeint- the type data change; REMOVED, ADDED or CHANGED
indexint- item index in a list model
isStartsWithMode
public boolean isStartsWithMode()When enabled this makes the filter check that the string starts with rather than within the index
Returns
the startsWithMode
setStartsWithMode
public void setStartsWithMode(boolean startsWithMode)When enabled this makes the filter check that the string starts with rather than within the index
Parameters
startsWithModeboolean- the startsWithMode to set