Class FilterProxyListModel<T>

java.lang.Object
com.codename1.ui.list.FilterProxyListModel<T>
All Implemented Interfaces:
DataChangedListener, ListModel<T>

public class FilterProxyListModel<T> extends Object implements ListModel<T>, DataChangedListener
This class allows filtering/sorting a list model dynamically using a text field
  • Field Summary

    Fields inherited from interface DataChangedListener

    ADDED, CHANGED, REMOVED
  • Constructor Summary

    Constructors
    Constructor
    Description
    The proxy is applied to the actual model and effectively hides it
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Invoked to indicate interest in future change events
    void
    addItem(T item)
    Adds the specified item to the end of this list.
    void
    Invoked to indicate interest in future selection events
    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
    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
    void
    dataChanged(int type, int index)
    Invoked when there was a change in the underlying model
    void
    Filters the list based on the given string
    getItemAt(int index)
    Returns the item at the given offset
    int
    Returns the selected list offset
    int
    Returns the number of items in the list
    Returns the underlying model which is needed to perform mutations on the list.
    static void
    install(TextField search, List l)
    Installs a search field on a list making sure the filter method is invoked properly
    static void
    Installs a search field on a list making sure the filter method is invoked properly
    boolean
    When enabled this makes the filter check that the string starts with rather than within the index
    void
    Invoked to indicate no further interest in future change events
    void
    removeItem(int index)
    Removes the item at the specified position in this list.
    void
    Invoked to indicate no further interest in future selection events
    void
    setSelectedIndex(int index)
    Sets the selected list offset can be set to -1 to clear selection
    void
    setStartsWithMode(boolean startsWithMode)
    When enabled this makes the filter check that the string starts with rather than within the index
    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

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FilterProxyListModel

      public FilterProxyListModel(ListModel<T> underlying)

      The proxy is applied to the actual model and effectively hides it

      Parameters
      • underlying: 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: 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: first object

      • b: second object

      • ascending: 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: the object being compared

      • str: the string

      Returns

      true if match is checked

    • filter

      public void filter(String str)

      Filters the list based on the given string

      Parameters
      • str: the string to filter the list by
    • getItemAt

      public T getItemAt(int index)

      Returns the item at the given offset

      Parameters
      • index: an index into this list
      Returns

      the item at the specified index

      Specified by:
      getItemAt in interface ListModel<T>
    • getSize

      public int getSize()

      Returns the number of items in the list

      Returns

      the number of items in the list

      Specified by:
      getSize in interface ListModel<T>
    • getSelectedIndex

      public int getSelectedIndex()

      Returns the selected list offset

      Returns

      the selected list index

      Specified by:
      getSelectedIndex in interface ListModel<T>
    • setSelectedIndex

      public void setSelectedIndex(int index)

      Sets the selected list offset can be set to -1 to clear selection

      Parameters
      • index: an index into this list
      Specified by:
      setSelectedIndex in interface ListModel<T>
    • addDataChangedListener

      public void addDataChangedListener(DataChangedListener l)

      Invoked to indicate interest in future change events

      Parameters
      • l: a data changed listener
      Specified by:
      addDataChangedListener in interface ListModel<T>
    • removeDataChangedListener

      public void removeDataChangedListener(DataChangedListener l)

      Invoked to indicate no further interest in future change events

      Parameters
      • l: a data changed listener
      Specified by:
      removeDataChangedListener in interface ListModel<T>
    • addSelectionListener

      public void addSelectionListener(SelectionListener l)

      Invoked to indicate interest in future selection events

      Parameters
      • l: a selection listener
      Specified by:
      addSelectionListener in interface ListModel<T>
    • removeSelectionListener

      public void removeSelectionListener(SelectionListener l)

      Invoked to indicate no further interest in future selection events

      Parameters
      • l: a selection listener
      Specified by:
      removeSelectionListener in interface ListModel<T>
    • 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: the item to be added
      Specified by:
      addItem in interface ListModel<T>
    • removeItem

      public void removeItem(int index)

      Removes the item at the specified position in this list.

      Parameters
      • index: the index of the item to removed
      Specified by:
      removeItem in interface ListModel<T>
    • dataChanged

      public void dataChanged(int type, int index)

      Invoked when there was a change in the underlying model

      Parameters
      • type: the type data change; REMOVED, ADDED or CHANGED

      • index: item index in a list model

      Specified by:
      dataChanged in interface DataChangedListener
    • 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: the startsWithMode to set