|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.collections.collection.AbstractCollectionDecorator
org.apache.commons.events.observable.ObservableCollection
public class ObservableCollection
Decorates a Collection
implementation to observe modifications.
Each modifying method call made on this Collection
is forwarded to a
ModificationHandler
.
The handler manages the event, notifying listeners and optionally vetoing changes.
The default handler is StandardModificationHandler
.
See this class for details of configuration available.
Nested Class Summary | |
---|---|
protected class |
ObservableCollection.ObservableIterator
Inner class Iterator for the ObservableCollection. |
Field Summary | |
---|---|
protected ModificationHandler |
handler
The handler to delegate event handling to |
Fields inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator |
---|
collection |
Constructor Summary | |
---|---|
protected |
ObservableCollection(Collection coll,
Object listener)
Constructor that wraps (not copies) and takes a handler. |
protected |
ObservableCollection(ModificationHandler handler,
Collection coll)
Constructor used by subclass views, such as subList. |
Method Summary | |
---|---|
boolean |
add(Object object)
|
boolean |
addAll(Collection coll)
|
void |
clear()
|
protected ModificationHandler |
createHandler(Collection coll,
Object listener)
Creates a handler subclass based on the specified listener. |
static ObservableCollection |
decorate(Collection coll)
Factory method to create an observable collection. |
static ObservableCollection |
decorate(Collection coll,
Object listener)
Factory method to create an observable collection using a listener or a handler. |
ModificationHandler |
getHandler()
Gets the handler that is observing this collection. |
Iterator |
iterator()
|
static void |
registerFactory(ModificationHandlerFactory factory)
Registers a handler factory to be used for looking up a listener to a handler. |
boolean |
remove(Object object)
|
boolean |
removeAll(Collection coll)
|
boolean |
retainAll(Collection coll)
|
Methods inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator |
---|
contains, containsAll, equals, getCollection, hashCode, isEmpty, size, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected final ModificationHandler handler
Constructor Detail |
---|
protected ObservableCollection(Collection coll, Object listener)
The handler implementation is determined by the listener parameter via
the registered factories. The listener may be a manually configured
ModificationHandler
instance.
coll
- the collection to decorate, must not be nulllistener
- the observing handler, may be null
IllegalArgumentException
- if the collection is nullprotected ObservableCollection(ModificationHandler handler, Collection coll)
handler
- the observing handler, may be nullcoll
- the collection to decorate, must not be null
IllegalArgumentException
- if the collection is nullMethod Detail |
---|
public static ObservableCollection decorate(Collection coll)
A StandardModificationHandler
will be created.
This can be accessed by getHandler()
to add listeners.
coll
- the collection to decorate, must not be null
IllegalArgumentException
- if the collection is nullpublic static ObservableCollection decorate(Collection coll, Object listener)
A lot of functionality is available through this method.
If you don't need the extra functionality, simply implement the
StandardModificationListener
interface and pass it in as the second parameter.
Internally, an ObservableCollection
relies on a ModificationHandler
.
The handler receives all the events and processes them, typically by
calling listeners. Different handler implementations can be plugged in
to provide a flexible event system.
The handler implementation is determined by the listener parameter via
the registered factories. The listener may be a manually configured
ModificationHandler
instance.
The listener is defined as an Object for maximum flexibility. It does not have to be a listener in the classic JavaBean sense. It is entirely up to the factory and handler as to how the parameter is interpretted. An IllegalArgumentException is thrown if no suitable handler can be found for this listener.
A null
listener will create a StandardModificationHandler
.
coll
- the collection to decorate, must not be nulllistener
- collection listener, may be null
IllegalArgumentException
- if the collection is null
IllegalArgumentException
- if there is no valid handler for the listenerpublic static void registerFactory(ModificationHandlerFactory factory)
This method is used to add your own event handler to the supplied ones.
Registering the factory will enable the decorate(Collection, Object)
method to create your handler.
Each handler added becomes the first in the lookup chain. Thus it is possible to override the default setup. Obviously this should be done with care in a shared web environment!
This method is not guaranteed to be threadsafe. It should only be called during initialization. Problems will occur if two threads call this method at the same time.
factory
- the factory to add, may be nullprotected ModificationHandler createHandler(Collection coll, Object listener)
The method is defined in terms of an Object to allow for unusual listeners, such as a Swing model object.
listener
- a listener object to create a handler for
IllegalArgumentException
- if no suitable handlerpublic ModificationHandler getHandler()
public boolean add(Object object)
add
in interface Collection
add
in class org.apache.commons.collections.collection.AbstractCollectionDecorator
public boolean addAll(Collection coll)
addAll
in interface Collection
addAll
in class org.apache.commons.collections.collection.AbstractCollectionDecorator
public void clear()
clear
in interface Collection
clear
in class org.apache.commons.collections.collection.AbstractCollectionDecorator
public Iterator iterator()
iterator
in interface Iterable
iterator
in interface Collection
iterator
in class org.apache.commons.collections.collection.AbstractCollectionDecorator
public boolean remove(Object object)
remove
in interface Collection
remove
in class org.apache.commons.collections.collection.AbstractCollectionDecorator
public boolean removeAll(Collection coll)
removeAll
in interface Collection
removeAll
in class org.apache.commons.collections.collection.AbstractCollectionDecorator
public boolean retainAll(Collection coll)
retainAll
in interface Collection
retainAll
in class org.apache.commons.collections.collection.AbstractCollectionDecorator
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |