Class PluggableList<E>
- java.lang.Object
-
- ca.odell.glazedlists.AbstractEventList<E>
-
- ca.odell.glazedlists.TransformedList<E,E>
-
- ca.odell.glazedlists.PluggableList<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 PluggableList<E> extends TransformedList<E,E>
AnEventListwhich delegates all List methods to a given sourceEventListthat may be replaced at runtime usingsetSource(EventList).Note that the source
EventListmust use the sameListEventPublisherandReadWriteLock, particularly if thisEventListis to be used by multiple threads concurrently. To construct anEventListthat shares theListEventPublisherandReadWriteLockwith thisPluggableList, usecreateSourceList().Warning: This class is thread ready but not thread safe. See
EventListfor an example of thread safe code.EventList Overview Writable: yes Concurrency: only setSource(EventList)Performance: delegates to source EventList Memory: N/A Unit Tests: N/A Issues: - Author:
- James Lemieux
-
-
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 PluggableList(ListEventPublisher publisher, ReadWriteLock lock)Constructs a PluggableList which uses the givenpublisherandlock.PluggableList(EventList<E> source)Constructs a PluggableList which delegates all List methods to the givensource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EventList<E>createSourceList()Creates a newEventListthat shares itsReadWriteLockandListEventPublisherwith thisPluggableList.voiddispose()Releases the resources consumed by thisTransformedListso that it may eventually be garbage collected.protected booleanisWritable()Gets whether the sourceEventListis writable via this API.voidlistChanged(ListEvent<E> listChanges)When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.voidsetSource(EventList<E> source)Sets the source EventList to which this PluggableList will delegate all calls.-
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
-
PluggableList
public PluggableList(ListEventPublisher publisher, ReadWriteLock lock)
Constructs a PluggableList which uses the givenpublisherandlock. The PluggableList will default to use aBasicEventListthat also uses the samepublisherandlock.- Parameters:
publisher- theListEventPublisherto use within thePluggableListlock- theReadWriteLockto use within thePluggableList
-
PluggableList
public PluggableList(EventList<E> source)
Constructs a PluggableList which delegates all List methods to the givensource. At some future time, the source EventList may be replaced usingsetSource(EventList)and this PluggableList will produce aListEventdescribing the change in data.- Parameters:
source- the source of data to this PluggableList
-
-
Method Detail
-
createSourceList
public EventList<E> createSourceList()
Creates a newEventListthat shares itsReadWriteLockandListEventPublisherwith thisPluggableList. This is necessary when thisPluggableListwill be used by multiple threads.Note that the created
EventListmust be explicitly set as the source of thisPluggableListusingsetSource(EventList).- Returns:
- a new EventList appropriate for use as the
sourceof this PluggableList
-
setSource
public void setSource(EventList<E> source)
Sets the source EventList to which this PluggableList will delegate all calls. This method is the entire reason that PluggableList exists. It allows the data source of the remaining pipeline to be altered.To ensure correct behaviour when this
PluggableListis used by multiple threads, the givensourcemust share the sameReadWriteLockandListEventPublisherwith this PluggableList.- Parameters:
source- the new source of data for this PluggableList, and all downstream EventLists- Throws:
java.lang.IllegalStateException- if this PluggableList is already disposedjava.lang.IllegalArgumentException- if any of the following are true- the given source is null
- the given source has a different ListEventPublisher than this PluggableList
- the given source has a different ReadWriteLock than this PluggableList
-
isWritable
protected boolean isWritable()
Description copied from class:TransformedListGets whether the sourceEventListis writable via this API.Extending classes must override this method in order to make themselves writable.
- Specified by:
isWritablein classTransformedList<E,E>
-
listChanged
public void listChanged(ListEvent<E> listChanges)
Description copied from class:TransformedListWhen 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:
listChangedin interfaceListEventListener<E>- Specified by:
listChangedin classTransformedList<E,E>- Parameters:
listChanges- aListEventdescribing the changes to the list
-
dispose
public void dispose()
Description copied from class:TransformedListReleases the resources consumed by thisTransformedListso that it may eventually be garbage collected.A
TransformedListwill be garbage collected without a call toTransformedList.dispose(), but not before its sourceEventListis garbage collected. By callingTransformedList.dispose(), you allow theTransformedListto be garbage collected before its sourceEventList. This is necessary for situations where aTransformedListis short-lived but its sourceEventListis long-lived.Warning: It is an error to call any method on a
TransformedListafter it has been disposed.
-
-