Class ObservableElementList<E>
- java.lang.Object
-
- ca.odell.glazedlists.AbstractEventList<E>
-
- ca.odell.glazedlists.TransformedList<E,E>
-
- ca.odell.glazedlists.ObservableElementList<E>
-
- All Implemented Interfaces:
ListEventListener<E>
,EventList<E>
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.EventListener
,java.util.List<E>
public class ObservableElementList<E> extends TransformedList<E,E>
A list that fires update events whenever elements are modified in place. Changes to list elements are detected by registering an appropriate listener on every list element. Listeners are registered as elements are added to this list and unregistered as elements are removed from this list. Users must specify an implementation of aObservableElementList.Connector
in the constructor which contains the necessary logic for registering and unregistering a listener capable of detecting modifications to an observable list element.Warning: This class is thread ready but not thread safe. See
EventList
for an example of thread safe code.EventList Overview Writable: yes Concurrency: thread ready, not thread safe; elementChanged(), however, is thread ready Performance: inserts: O(1), deletes: O(1), updates: O(1), elementChanged: O(n) Memory: 8 bytes per element Unit Tests: ObservableElementListTest Issues: N/A - Author:
- Jesse Wilson, James Lemieux
- See Also:
GlazedLists.beanConnector(Class)
,GlazedLists.beanConnector(Class, String, String)
, RFE 157
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ObservableElementList.Connector<E>
An interface defining the methods required for registering and unregistering change listeners on list elements within anObservableElementList
.
-
Field Summary
-
Fields inherited from class ca.odell.glazedlists.TransformedList
source
-
Fields inherited from class ca.odell.glazedlists.AbstractEventList
publisher, readWriteLock, updates
-
-
Constructor Summary
Constructors Constructor Description ObservableElementList(EventList<E> source, ObservableElementList.Connector<? super E> elementConnector)
Constructs anObservableElementList
which wraps the givensource
and uses the givenelementConnector
to register/unregister change listeners on elements of thesource
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
Releases the resources consumed by thisTransformedList
so that it may eventually be garbage collected.void
elementChanged(java.lang.Object listElement)
Handle a listener being notified for the specifiedlistElement
.protected boolean
isWritable()
Gets whether the sourceEventList
is writable via this API.void
listChanged(ListEvent<E> listChanges)
When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.-
Methods inherited from class ca.odell.glazedlists.TransformedList
add, addAll, clear, get, getSourceIndex, remove, removeAll, retainAll, set, size
-
Methods inherited from class ca.odell.glazedlists.AbstractEventList
add, addAll, addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeListEventListener, subList, toArray, toArray, toString
-
-
-
-
Constructor Detail
-
ObservableElementList
public ObservableElementList(EventList<E> source, ObservableElementList.Connector<? super E> elementConnector)
Constructs anObservableElementList
which wraps the givensource
and uses the givenelementConnector
to register/unregister change listeners on elements of thesource
.- Parameters:
source
- theEventList
to transformelementConnector
- theObservableElementList.Connector
to consult when list elements are added or removed and thus element listeners must be registered or unregistered. Note that this constructor attachs this list to the givenelementConnector
by callingObservableElementList.Connector.setObservableElementList(ObservableElementList)
.
-
-
Method Detail
-
listChanged
public void listChanged(ListEvent<E> listChanges)
Description copied from class:TransformedList
When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.It is mandatory that the calling thread has obtained the write lock on the source list. This is because the calling thread will have written to the source list to cause this event. This condition guarantees that no writes can occur while the listener is handling this event. It is an error to write to the source list while processing an event.
- Specified by:
listChanged
in interfaceListEventListener<E>
- Specified by:
listChanged
in classTransformedList<E,E>
- Parameters:
listChanges
- aListEvent
describing the changes to the list
-
isWritable
protected boolean isWritable()
Description copied from class:TransformedList
Gets whether the sourceEventList
is writable via this API.Extending classes must override this method in order to make themselves writable.
- Specified by:
isWritable
in classTransformedList<E,E>
-
dispose
public void dispose()
Releases the resources consumed by thisTransformedList
so that it may eventually be garbage collected. In this case of thisTransformedList
, it uses theObservableElementList.Connector
to remove all listeners from their associated list elements and finally removes the reference to this list from the Connector by callingObservableElementList.Connector.setObservableElementList(ObservableElementList)
with anull
argument.Warning: It is an error to call any method on a
TransformedList
after it has been disposed.
-
elementChanged
public void elementChanged(java.lang.Object listElement)
Handle a listener being notified for the specifiedlistElement
. This method causes a ListEvent to be fired from this EventList indicating an update occurred at all locations of the givenlistElement
.Note that listElement must be the exact object located within this list (i.e.
listElement == get(i) for some i >= 0
).This method acquires the write lock for this list before locating the
listElement
and broadcasting its update. It is assumed that this method may be called on any Thread, so to decrease the burdens of the caller in achieving multi-threaded correctness, this method is Thread ready.- Parameters:
listElement
- the list element which has been modified
-
-