Class CollectionList<S,E>
- java.lang.Object
-
- ca.odell.glazedlists.AbstractEventList<E>
-
- ca.odell.glazedlists.TransformedList<S,E>
-
- ca.odell.glazedlists.CollectionList<S,E>
-
- All Implemented Interfaces:
ListEventListener<S>
,EventList<E>
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.EventListener
,java.util.List<E>
- Direct Known Subclasses:
CompositeList
public class CollectionList<S,E> extends TransformedList<S,E> implements ListEventListener<S>
A list that acts like a tree in that it contains child elements to nodes contained in another list. An example usage would be to wrap a parent list containing albums and use the CollectionList to display the songs on the album.The actual mapping from the parent list to the child list (album to songs in the above example) is done by a
CollectionList.Model
that is provided to the constructor.Note that any
EventList
s returned by theCollectionList.Model
must use the sameListEventPublisher
andReadWriteLock
as thisCollectionList
. This is necessary in order for CollectionList to operate correctly under mult-threaded conditions. AnIllegalArgumentException
will be raised if this invariant is violated.Warning: This class is thread ready but not thread safe. See
EventList
for an example of thread safe code.EventList Overview Writable: only set(int,Object)
andremove(int)
Concurrency: thread ready, not thread safe Performance: reads: O(log N), writes O(log N) Memory: 96 bytes per element Unit Tests: N/A Issues: 96 162 257 265 - Author:
- Rob Eden, Jesse Wilson
- See Also:
CollectionList.Model
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CollectionList.Model<E,S>
Provides the logic to map a parent object (e.g.
-
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 CollectionList(EventList<S> source, CollectionList.Model<S,E> model)
Create aCollectionList
with its contents being the children of the elements in the specified sourceEventList
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
childEndingIndex(int parentIndex)
Return the index of the last child in the CollectionList for the given parent index.int
childStartingIndex(int parentIndex)
Return the index of the first child in the CollectionList for the given parent index.void
dispose()
Releases the resources consumed by thisTransformedList
so that it may eventually be garbage collected.E
get(int index)
Returns the element at the specified position in this list.protected boolean
isWritable()
Gets whether the sourceEventList
is writable via this API.void
listChanged(ListEvent<S> listChanges)
Handle changes in the parent list.E
remove(int index)
Removes the element at the specified position in this list (optional operation).E
set(int index, E value)
Replaces the element at the specified position in this list with the specified element (optional operation).int
size()
Returns the number of elements in this list.-
Methods inherited from class ca.odell.glazedlists.TransformedList
add, addAll, clear, getSourceIndex, removeAll, retainAll
-
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
-
CollectionList
public CollectionList(EventList<S> source, CollectionList.Model<S,E> model)
Create aCollectionList
with its contents being the children of the elements in the specified sourceEventList
.- Parameters:
source
- an EventList of Objects from each of which themodel
can extract child elementsmodel
- the logic for extracting children from eachsource
element
-
-
Method Detail
-
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<S,E>
- Returns:
- false because we cannot support
TransformedList.add(int, Object)
; though we do supportset(int, Object)
andremove(int)
-
size
public int size()
Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
-
get
public E get(int index)
Returns the element at the specified position in this list.- Specified by:
get
in interfacejava.util.List<S>
- Overrides:
get
in classTransformedList<S,E>
- Parameters:
index
- index of element to return.- Returns:
- the element at the specified position in this list.
-
set
public E set(int index, E value)
Replaces the element at the specified position in this list with the specified element (optional operation).- Specified by:
set
in interfacejava.util.List<S>
- Overrides:
set
in classTransformedList<S,E>
- Parameters:
index
- index of element to replace.value
- element to be stored at the specified position.- Returns:
- the element previously at the specified position.
-
remove
public E remove(int index)
Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.- Specified by:
remove
in interfacejava.util.List<S>
- Overrides:
remove
in classTransformedList<S,E>
- Parameters:
index
- the index of the element to removed.- Returns:
- the element previously at the specified position.
-
childStartingIndex
public int childStartingIndex(int parentIndex)
Return the index of the first child in the CollectionList for the given parent index. This can be very useful for things like selecting the children in a CollectionList when the parent is selected in another list.- See Also:
childEndingIndex(int)
-
childEndingIndex
public int childEndingIndex(int parentIndex)
Return the index of the last child in the CollectionList for the given parent index. This can be very useful for things like selecting the children in a CollectionList when the parent is selected in another list.- See Also:
childStartingIndex(int)
-
listChanged
public void listChanged(ListEvent<S> listChanges)
Handle changes in the parent list. We'll need to update our node list sizes.- Specified by:
listChanged
in interfaceListEventListener<S>
- Specified by:
listChanged
in classTransformedList<S,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.
-
-