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>
AnEventList
which delegates all List methods to a given sourceEventList
that may be replaced at runtime usingsetSource(EventList)
.Note that the source
EventList
must use the sameListEventPublisher
andReadWriteLock
, particularly if thisEventList
is to be used by multiple threads concurrently. To construct anEventList
that shares theListEventPublisher
andReadWriteLock
with thisPluggableList
, usecreateSourceList()
.Warning: This class is thread ready but not thread safe. See
EventList
for 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 givenpublisher
andlock
.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 newEventList
that shares itsReadWriteLock
andListEventPublisher
with thisPluggableList
.void
dispose()
Releases the resources consumed by thisTransformedList
so that it may eventually be garbage collected.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.void
setSource(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 givenpublisher
andlock
. The PluggableList will default to use aBasicEventList
that also uses the samepublisher
andlock
.- Parameters:
publisher
- theListEventPublisher
to use within thePluggableList
lock
- theReadWriteLock
to 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 aListEvent
describing the change in data.- Parameters:
source
- the source of data to this PluggableList
-
-
Method Detail
-
createSourceList
public EventList<E> createSourceList()
Creates a newEventList
that shares itsReadWriteLock
andListEventPublisher
with thisPluggableList
. This is necessary when thisPluggableList
will be used by multiple threads.Note that the created
EventList
must be explicitly set as the source of thisPluggableList
usingsetSource(EventList)
.- Returns:
- a new EventList appropriate for use as the
source
of 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
PluggableList
is used by multiple threads, the givensource
must share the sameReadWriteLock
andListEventPublisher
with 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: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>
-
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
-
dispose
public void dispose()
Description copied from class:TransformedList
Releases the resources consumed by thisTransformedList
so that it may eventually be garbage collected.A
TransformedList
will be garbage collected without a call toTransformedList.dispose()
, but not before its sourceEventList
is garbage collected. By callingTransformedList.dispose()
, you allow theTransformedList
to be garbage collected before its sourceEventList
. This is necessary for situations where aTransformedList
is short-lived but its sourceEventList
is long-lived.Warning: It is an error to call any method on a
TransformedList
after it has been disposed.
-
-