org.springframework.richclient.list
Class FilteredListModel

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by org.springframework.richclient.list.AbstractFilteredListModel
          extended by org.springframework.richclient.list.FilteredListModel
All Implemented Interfaces:
Serializable, EventListener, Observer, ListDataListener, ListModel
Direct Known Subclasses:
FilteredComboBoxListModel

public class FilteredListModel
extends AbstractFilteredListModel
implements Observer

Decorates an existing ListModel by applying a constraint. The constraint can implement Observable to notify a change of the filter condition.

Author:
Keith Donald, Mathias Broekelmann
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.springframework.richclient.list.AbstractFilteredListModel
filteredModel, logger
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
FilteredListModel(ListModel listModel, Constraint constraint)
          Constructs a new instance
 
Method Summary
 void contentsChanged(ListDataEvent e)
           
protected  void fireContentsChanged(Object source, int index0, int index1)
           
 Constraint getConstraint()
           
 int getElementIndex(int filteredIndex)
          Returns the element index for a filtered index
 int getSize()
          Returns the size of the elements which passes the filter constraint.
 void intervalAdded(ListDataEvent e)
           
 void intervalRemoved(ListDataEvent e)
           
protected  void onMatchingElement(Object element)
          Called to notify that an element has matched the filter constraint.
protected  void postConstraintApplied()
          Called to notify that the constraint was applied to all elements.
protected  void reallocateIndexes()
          Internally called to reallocate the indexes.
 void setConstraint(Constraint constraint)
          Defines the constraint which is applied to the list model elements
 void update(Observable changed, Object arg)
          If the constraint implements Observable this method is called and will apply the constraint to the list model elements
 
Methods inherited from class org.springframework.richclient.list.AbstractFilteredListModel
getElementAt, getFilteredModel, setFilteredModel
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilteredListModel

public FilteredListModel(ListModel listModel,
                         Constraint constraint)
Constructs a new instance

Parameters:
listModel - the list model to filter.
constraint - the constraint which is applied to the list model elements
Throws:
IllegalArgumentException - if list model or constraint parameters where null
Method Detail

fireContentsChanged

protected void fireContentsChanged(Object source,
                                   int index0,
                                   int index1)
Overrides:
fireContentsChanged in class AbstractListModel

setConstraint

public final void setConstraint(Constraint constraint)
Defines the constraint which is applied to the list model elements

Parameters:
constraint - the constraint to set
Throws:
IllegalArgumentException - if constraint is null

getConstraint

public Constraint getConstraint()
Returns:
the constraint

reallocateIndexes

protected void reallocateIndexes()
Internally called to reallocate the indexes. This method should be called when the filtered model changes its element size


update

public void update(Observable changed,
                   Object arg)
If the constraint implements Observable this method is called and will apply the constraint to the list model elements

Specified by:
update in interface Observer

onMatchingElement

protected void onMatchingElement(Object element)
Called to notify that an element has matched the filter constraint. This implementation does nothing.

Parameters:
element - the element which was accepted by the filter

postConstraintApplied

protected void postConstraintApplied()
Called to notify that the constraint was applied to all elements. This implementation does nothing.


getSize

public int getSize()
Returns the size of the elements which passes the filter constraint.

Specified by:
getSize in interface ListModel
Overrides:
getSize in class AbstractFilteredListModel

getElementIndex

public int getElementIndex(int filteredIndex)
Returns the element index for a filtered index

Overrides:
getElementIndex in class AbstractFilteredListModel
Parameters:
filteredIndex - the filtered index
Returns:
the unfiltered index of the filtered model

contentsChanged

public void contentsChanged(ListDataEvent e)
Specified by:
contentsChanged in interface ListDataListener
Overrides:
contentsChanged in class AbstractFilteredListModel

intervalAdded

public void intervalAdded(ListDataEvent e)
Specified by:
intervalAdded in interface ListDataListener
Overrides:
intervalAdded in class AbstractFilteredListModel

intervalRemoved

public void intervalRemoved(ListDataEvent e)
Specified by:
intervalRemoved in interface ListDataListener
Overrides:
intervalRemoved in class AbstractFilteredListModel


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.