public class FilterProxyListModel<T>

  1. Object
  2. 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

underlying ListModel<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

ascending boolean
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

a Object
first object
b Object
second object
ascending boolean
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

o Object
the object being compared
str String
the string

Returns

true if match is checked

filter

public void filter(String str)
Filters the list based on the given string

Parameters

str String
the string to filter the list by

getItemAt

public T getItemAt(int index)
Returns the item at the given offset

Parameters

index int
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

index int
an index into this list

addDataChangedListener

public void addDataChangedListener(DataChangedListener l)
Invoked to indicate interest in future change events

Parameters

l DataChangedListener
a data changed listener

removeDataChangedListener

public void removeDataChangedListener(DataChangedListener l)
Invoked to indicate no further interest in future change events

Parameters

l DataChangedListener
a data changed listener

addSelectionListener

public void addSelectionListener(SelectionListener l)
Invoked to indicate interest in future selection events

Parameters

l SelectionListener
a selection listener

removeSelectionListener

public void removeSelectionListener(SelectionListener l)
Invoked to indicate no further interest in future selection events

Parameters

l SelectionListener
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

item T
the item to be added

removeItem

public void removeItem(int index)
Removes the item at the specified position in this list.

Parameters

index int
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

type int
the type data change; REMOVED, ADDED or CHANGED
index int
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

startsWithMode boolean
the startsWithMode to set