| java.lang.Object com.jgoodies.binding.beans.Model com.jgoodies.binding.list.IndirectListModel
IndirectListModel | public class IndirectListModel extends Model implements ListModel(Code) | | A ListModel implementation that holds a List or ListModel in a ValueModel.
If you hold a List, this class can only report that the List has been
replaced; this is done by firing a PropertyChangeEvent for the list
property. Also, a ListDataEvent is fired that reports
a complete change. In contrast, if you use a ListModel it will report
the same PropertyChangeEvent. But fine grained changes in the ListModel
will be fired by this class to notify observes about changes in the content,
added and removed elements.
If the list content doesn't change at all, or if it always changes
completely, you can work well with both List content and ListModel content.
But if the list structure or content changes, the ListModel reports more
fine grained events to registered ListDataListeners, which in turn allows
list views to chooser better user interface gestures: for example, a table
with scroll pane may retain the current selection and scroll offset.
If you want to combine List operations and the ListModel change reports,
you may consider using an implementation that combines these two interfaces,
for example
ArrayListModel or
LinkedListModel .
Important Note: If you change the ListModel instance,
either by calling #setListModel(ListModel) or by setting
a new value to the underlying list holder, you must ensure that
the list holder throws a PropertyChangeEvent whenever the instance changes.
This event is used to remove a ListDataListener from the old ListModel
instance and is later used to add it to the new ListModel instance.
It is easy to violate this constraint, just because Java's standard
PropertyChangeSupport helper class that is used by many beans, checks
a changed property value via #equals , not == .
For example, if you change the IndirectListModel's list model from an empty
list L1 to another empty list instance L2 ,
the PropertyChangeSupport won't generate a PropertyChangeEvent,
and so, the IndirectListModel won't know about the change, which
may lead to unexpected behavior.
This binding library provides some help for firing PropertyChangeEvents
if the old ListModel and new ListModel are equal but not the same.
Class
com.jgoodies.binding.beans.ExtendedPropertyChangeSupport allows to permanently or individually check the identity (using
== ) instead of checking the equity (using #equals ).
Class
com.jgoodies.binding.beans.Model uses this extended
property change support. And class
ValueHolder uses it too
and can be configured to always test the identity.
This class provides public convenience methods for firing ListDataEvents,
see the methods #fireContentsChanged ,
#fireIntervalAdded , and #fireIntervalRemoved .
These are automatically invoked if the list holder holds a ListModel
that fires these events. If on the other hand the underlying List or
ListModel does not fire a required ListDataEvent, you can use these
methods to notify presentations about a change. It is recommended
to avoid sending duplicate ListDataEvents; hence check if the underlying
ListModel fires the necessary events or not.
Constraints: The list holder holds instances of
List or
ListModel . If the ListModel changes, the underlying ValueModel
must fire a PropertyChangeEvent.
author: Karsten Lentzsch version: $Revision: 1.7 $ See Also: List See Also: ListModel See Also: SelectionInList See Also: ValueModel See Also: com.jgoodies.binding.adapter.ComboBoxAdapter See Also: com.jgoodies.binding.adapter.AbstractTableAdapter See Also: com.jgoodies.binding.beans.ExtendedPropertyChangeSupport See Also: com.jgoodies.binding.beans.Model See Also: com.jgoodies.binding.value.ValueHolder< Parameters: E - > the type of the list elements since: 2.0 |
Constructor Summary | |
public | IndirectListModel() Constructs an IndirectListModel with an empty initial
ArrayListModel . | public | IndirectListModel(E[] listItems) Constructs an IndirectListModel on the given item array. | public | IndirectListModel(List<E> list) Constructs an IndirectListModel on the given list.
Note: Favor ListModel over
List when working with an IndirectListModel.
Why? The IndirectListModel can work with both types. | public | IndirectListModel(ListModel listModel) Constructs an IndirectListModel on the given list model
using a default list holder. | public | IndirectListModel(ValueModel listHolder) Constructs an IndirectListModel on the given list holder.
Constraints:
1) The listHolder must hold instances of List or ListModel and
2) must report a value change whenever the value's identity changes.
Note that many bean properties don't fire a PropertyChangeEvent
if the old and new value are equal - and so would break this constraint.
If you provide a ValueHolder, enable its identityCheck feature
during construction. |
Method Summary | |
final public void | addListDataListener(ListDataListener l) Adds a listener to the list that's notified each time a change
to the data model occurs. | protected ListDataListener | createListDataChangeHandler() Creates and returns the ListDataListener used to observe
changes in the underlying ListModel. | final public void | fireContentsChanged(int index0, int index1) Notifies all registered ListDataListeners that the contents
of one or more list elements has changed.
The changed elements are specified by the closed interval index0, index1
-- the end points are included. | final public void | fireIntervalAdded(int index0, int index1) Notifies all registered ListDataListeners that one or more elements
have been added to this IndirectListModel's List/ListModel.
The new elements are specified by a closed interval index0, index1
-- the end points are included. | final public void | fireIntervalRemoved(int index0, int index1) Notifies all registered ListDataListeners that one or more elements
have been removed from this IndirectListModel's List/ListModel.
index0 and index1 are the end points
of the interval that's been removed. | final protected void | fireListChanged(int oldLastIndex, int newLastIndex) Notifies all registered ListDataListeners that this ListModel
has changed from an old list to a new list content.
If the old and new list size differ, a remove or add event for
the removed or added interval is fired. | final public E | getElementAt(int index) Returns the value at the specified index,
null if the list model is
null . | final public List<E> | getList() Returns the list holder's List or an empty List, if it
holds
null . | final public ListDataListener[] | getListDataListeners() Returns an array of all the list data listeners
registered on this IndirectListModel . | final public ValueModel | getListHolder() Returns the model that holds the List/ListModel. | final public ListModel | getListModel() Returns the list holder's ListModel or an empty ListModel, if it
holds
null . | final public int | getSize() Returns the length of the list, 0 if the list model
is
null . | final protected int | getSize(Object aListListModelOrNull) Returns the length of the given list, 0 if the list model
is
null . | final public boolean | isEmpty() Checks and answers if the list is empty or
null . | public void | release() Removes the internal listeners from the list holder. | final public void | removeListDataListener(ListDataListener l) Removes a listener from the list that's notified each time a
change to the data model occurs. | final public void | setList(List<E> newList) Sets the given list as value of the list holder.
Note: Favor ListModel over
List when working with an IndirectListModel.
Why? The IndirectListModel can work with both types. | final public void | setListHolder(ValueModel newListHolder) Sets a new list holder. | final public void | setListModel(ListModel newListModel) Sets the given list model as value of the list holder. | protected void | updateList(Object oldList, int oldSize, Object newList) Removes the list data change handler from the old list in case
it is a ListModel and adds it to new one in case
it is a ListModel . |
PROPERTYNAME_LIST | final public static String PROPERTYNAME_LIST(Code) | | The name of the bound write-only list property.
|
PROPERTYNAME_LIST_HOLDER | final public static String PROPERTYNAME_LIST_HOLDER(Code) | | The name of the bound read-write listHolder property.
|
IndirectListModel | public IndirectListModel()(Code) | | Constructs an IndirectListModel with an empty initial
ArrayListModel .
|
IndirectListModel | public IndirectListModel(E[] listItems)(Code) | | Constructs an IndirectListModel on the given item array.
The specified array will be converted to a List.
Changes to the list "write through" to the array, and changes
to the array contents will be reflected in the list.
Parameters: listItems - the array of initial items throws: NullPointerException - if listItems is null |
IndirectListModel | public IndirectListModel(List<E> list)(Code) | | Constructs an IndirectListModel on the given list.
Note: Favor ListModel over
List when working with an IndirectListModel.
Why? The IndirectListModel can work with both types. What's the
difference? ListModel provides all list access features
required by the IndirectListModel's. In addition it reports more
fine grained change events, instances of ListDataEvents .
In contrast developer often create Lists and operate on them
and the ListModel may be inconvenient for these operations.
A convenient solution for this situation is to use the
ArrayListModel and LinkedListModel classes.
These implement both List and ListModel, offer the standard List
operations and report the fine grained ListDataEvents.
Parameters: list - the initial list |
IndirectListModel | public IndirectListModel(ListModel listModel)(Code) | | Constructs an IndirectListModel on the given list model
using a default list holder.
Parameters: listModel - the initial list model |
IndirectListModel | public IndirectListModel(ValueModel listHolder)(Code) | | Constructs an IndirectListModel on the given list holder.
Constraints:
1) The listHolder must hold instances of List or ListModel and
2) must report a value change whenever the value's identity changes.
Note that many bean properties don't fire a PropertyChangeEvent
if the old and new value are equal - and so would break this constraint.
If you provide a ValueHolder, enable its identityCheck feature
during construction. If you provide an adapted bean property from
a bean that extends the JGoodies Model class,
you can enable the identity check feature in the methods
#firePropertyChange by setting the trailing boolean
parameter to true .
Parameters: listHolder - holds the list or list model throws: NullPointerException - if listHolder is null |
addListDataListener | final public void addListDataListener(ListDataListener l)(Code) | | Adds a listener to the list that's notified each time a change
to the data model occurs.
Parameters: l - the ListDataListener to be added |
createListDataChangeHandler | protected ListDataListener createListDataChangeHandler()(Code) | | Creates and returns the ListDataListener used to observe
changes in the underlying ListModel. It is re-registered
in #updateListModel .
the ListDataListener that handles changesin the underlying ListModel |
fireContentsChanged | final public void fireContentsChanged(int index0, int index1)(Code) | | Notifies all registered ListDataListeners that the contents
of one or more list elements has changed.
The changed elements are specified by the closed interval index0, index1
-- the end points are included. Note that index0 need not be less than
or equal to index1.
If the list holder holds a ListModel, this IndirectListModel listens
to ListDataEvents fired by that ListModel, and forwards these events
by invoking the associated #fireXXX method, which in turn
notifies all registered ListDataListeners. Therefore if you fire
ListDataEvents in an underlying ListModel, you don't need this method
and should not use it to avoid sending duplicate ListDataEvents.
Parameters: index0 - one end of the new interval Parameters: index1 - the other end of the new interval See Also: ListModel See Also: ListDataListener See Also: ListDataEvent since: 1.0.2 |
fireIntervalAdded | final public void fireIntervalAdded(int index0, int index1)(Code) | | Notifies all registered ListDataListeners that one or more elements
have been added to this IndirectListModel's List/ListModel.
The new elements are specified by a closed interval index0, index1
-- the end points are included. Note that index0 need not be less than
or equal to index1.
If the list holder holds a ListModel, this IndirectListModel listens
to ListDataEvents fired by that ListModel, and forwards these events
by invoking the associated #fireXXX method, which in turn
notifies all registered ListDataListeners. Therefore if you fire
ListDataEvents in an underlying ListModel, you don't need this method
and should not use it to avoid sending duplicate ListDataEvents.
Parameters: index0 - one end of the new interval Parameters: index1 - the other end of the new interval See Also: ListModel See Also: ListDataListener See Also: ListDataEvent since: 1.0.2 |
fireIntervalRemoved | final public void fireIntervalRemoved(int index0, int index1)(Code) | | Notifies all registered ListDataListeners that one or more elements
have been removed from this IndirectListModel's List/ListModel.
index0 and index1 are the end points
of the interval that's been removed. Note that index0
need not be less than or equal to index1 .
If the list holder holds a ListModel, this IndirectListModel listens
to ListDataEvents fired by that ListModel, and forwards these events
by invoking the associated #fireXXX method, which in turn
notifies all registered ListDataListeners. Therefore if you fire
ListDataEvents in an underlying ListModel, you don't need this method
and should not use it to avoid sending duplicate ListDataEvents.
Parameters: index0 - one end of the removed interval,including index0 Parameters: index1 - the other end of the removed interval,including index1 See Also: ListModel See Also: ListDataListener See Also: ListDataEvent since: 1.0.2 |
fireListChanged | final protected void fireListChanged(int oldLastIndex, int newLastIndex)(Code) | | Notifies all registered ListDataListeners that this ListModel
has changed from an old list to a new list content.
If the old and new list size differ, a remove or add event for
the removed or added interval is fired. A content change
is reported for the interval common to the old and new list.
This method is invoked by #updateList during the transition
from an old List(Model) to a new List(Model).
Note:
The order of the events fired ensures that after each event
the size described by the ListDataEvents equals the ListModel size.
Parameters: oldLastIndex - the last index of the old list Parameters: newLastIndex - the last index of the new list |
getElementAt | final public E getElementAt(int index)(Code) | | Returns the value at the specified index,
null if the list model is
null .
Parameters: index - the requested index the value at index , null if the list model is null throws: NullPointerException - if the list holder's content is null |
getListHolder | final public ValueModel getListHolder()(Code) | | Returns the model that holds the List/ListModel.
the model that holds the List/ListModel |
getSize | final public int getSize()(Code) | | Returns the length of the list, 0 if the list model
is
null .
the size of the list, 0 if the list model is null |
getSize | final protected int getSize(Object aListListModelOrNull)(Code) | | Returns the length of the given list, 0 if the list model
is
null .
Parameters: aListListModelOrNull - a List, ListModel or null the size of the given list, 0 if the list model is null |
isEmpty | final public boolean isEmpty()(Code) | | Checks and answers if the list is empty or
null .
true if the list is empty or null , false otherwise |
release | public void release()(Code) | | Removes the internal listeners from the list holder. If the current list
is a ListModel, the internal ListDataListener is removed from it.
This IndirectListModel must not be used after calling
#release .
To avoid memory leaks it is recommended to invoke this method,
if the list holder, selection holder, or selection index holder
live much longer than this IndirectListModel.
Instead of releasing the IndirectListModel, you typically make the
list holder obsolete by releasing the PresentationModel or BeanAdapter
that has created them before.
As an alternative you may use ValueModels that in turn use
event listener lists implemented using WeakReference .
Basically this release method performs the reverse operation
performed during the IndirectListModel construction.
See Also: PresentationModel.release See Also: BeanAdapter.release See Also: java.lang.ref.WeakReference since: 1.2 |
removeListDataListener | final public void removeListDataListener(ListDataListener l)(Code) | | Removes a listener from the list that's notified each time a
change to the data model occurs.
Parameters: l - the ListDataListener to be removed |
setList | final public void setList(List<E> newList)(Code) | | Sets the given list as value of the list holder.
Note: Favor ListModel over
List when working with an IndirectListModel.
Why? The IndirectListModel can work with both types. What's the
difference? ListModel provides all list access features
required by the IndirectListModel's. In addition it reports more
fine grained change events, instances of ListDataEvents .
In contrast developer often create Lists and operate on them
and the ListModel may be inconvenient for these operations.
A convenient solution for this situation is to use the
ArrayListModel and LinkedListModel classes.
These implement both List and ListModel, offer the standard List
operations and report the fine grained ListDataEvents.
Parameters: newList - the list to be set as new list content See Also: IndirectListModel.getList() See Also: IndirectListModel.getListModel() See Also: IndirectListModel.setListModel(ListModel) |
setListHolder | final public void setListHolder(ValueModel newListHolder)(Code) | | Sets a new list holder. Does nothing if old and new holder are equal.
Removes the list change handler from the old holder and adds
it to the new one. In case the list holder contents is a ListModel,
the list data change handler is updated too by invoking
#updateListDataRegistration in the same way as done in the
list change handler.
TODO: Check and verify whether the list data registration update
can be performed in one step after the listHolder has been
changed - instead of remove the list data change handler, then
changing the listHolder, and finally adding the list data change handler.
Parameters: newListHolder - the list holder to be set throws: NullPointerException - if the new list holder is null throws: IllegalArgumentException - if the listHolder is a ValueHolderthat doesn't check the identity when changing its value |
updateList | protected void updateList(Object oldList, int oldSize, Object newList)(Code) | | Removes the list data change handler from the old list in case
it is a ListModel and adds it to new one in case
it is a ListModel .
It then fires a property change for the list and a contents change event
for the list content.
Parameters: oldList - the old list content Parameters: oldSize - the size of the old List content Parameters: newList - the new list content See Also: javax.swing.JTable.tableChanged(javax.swing.event.TableModelEvent) |
Methods inherited from com.jgoodies.binding.beans.Model | final public synchronized void addPropertyChangeListener(PropertyChangeListener listener)(Code)(Java Doc) final public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)(Code)(Java Doc) final public synchronized void addVetoableChangeListener(VetoableChangeListener listener)(Code)(Java Doc) final public synchronized void addVetoableChangeListener(String propertyName, VetoableChangeListener listener)(Code)(Java Doc) final protected boolean equals(Object o1, Object o2)(Code)(Java Doc) final protected void fireIndexedPropertyChange(String propertyName, int index, Object oldValue, Object newValue)(Code)(Java Doc) final protected void fireIndexedPropertyChange(String propertyName, int index, int oldValue, int newValue)(Code)(Java Doc) final protected void fireIndexedPropertyChange(String propertyName, int index, boolean oldValue, boolean newValue)(Code)(Java Doc) final protected void fireMultiplePropertiesChanged()(Code)(Java Doc) final protected void firePropertyChange(PropertyChangeEvent event)(Code)(Java Doc) final protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)(Code)(Java Doc) final protected void firePropertyChange(String propertyName, Object oldValue, Object newValue, boolean checkIdentity)(Code)(Java Doc) final protected void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)(Code)(Java Doc) final protected void firePropertyChange(String propertyName, double oldValue, double newValue)(Code)(Java Doc) final protected void firePropertyChange(String propertyName, float oldValue, float newValue)(Code)(Java Doc) final protected void firePropertyChange(String propertyName, int oldValue, int newValue)(Code)(Java Doc) final protected void firePropertyChange(String propertyName, long oldValue, long newValue)(Code)(Java Doc) final protected void fireVetoableChange(PropertyChangeEvent event) throws PropertyVetoException(Code)(Java Doc) final protected void fireVetoableChange(String propertyName, Object oldValue, Object newValue) throws PropertyVetoException(Code)(Java Doc) final protected void fireVetoableChange(String propertyName, boolean oldValue, boolean newValue) throws PropertyVetoException(Code)(Java Doc) final protected void fireVetoableChange(String propertyName, double oldValue, double newValue) throws PropertyVetoException(Code)(Java Doc) final protected void fireVetoableChange(String propertyName, int oldValue, int newValue) throws PropertyVetoException(Code)(Java Doc) final protected void fireVetoableChange(String propertyName, float oldValue, float newValue) throws PropertyVetoException(Code)(Java Doc) final protected void fireVetoableChange(String propertyName, long oldValue, long newValue) throws PropertyVetoException(Code)(Java Doc) final public synchronized PropertyChangeListener[] getPropertyChangeListeners()(Code)(Java Doc) final public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName)(Code)(Java Doc) final public synchronized VetoableChangeListener[] getVetoableChangeListeners()(Code)(Java Doc) final public synchronized VetoableChangeListener[] getVetoableChangeListeners(String propertyName)(Code)(Java Doc) final public synchronized void removePropertyChangeListener(PropertyChangeListener listener)(Code)(Java Doc) final public synchronized void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)(Code)(Java Doc) final public synchronized void removeVetoableChangeListener(VetoableChangeListener listener)(Code)(Java Doc) final public synchronized void removeVetoableChangeListener(String propertyName, VetoableChangeListener listener)(Code)(Java Doc)
|
|
|