|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.events.observable.ModificationHandler
public class ModificationHandler
Defines a handler for collection modification events.
This class defines the event handling methods, following the
preXxx
and postXxx
naming convention.
It also provides a default implementation that forwards to single methods.
To write your own handler, you will normally subclass and override the
preEvent
and postEvent
methods. However, you
could choose to override any individual event method.
This class could have been implemented as an interface, however to do so would prevent the addition of extra events in the future. It does mean that if you subclass this class, you must check it when you upgrade to a later release.
Nested Class Summary | |
---|---|
protected static class |
ModificationHandler.SetViewHandler
Inner class for views. |
protected static class |
ModificationHandler.SubListHandler
Inner class for subLists. |
Constructor Summary | |
---|---|
protected |
ModificationHandler()
Constructor. |
protected |
ModificationHandler(ModificationHandler rootHandler,
int viewOffset)
Constructor. |
Method Summary | |
---|---|
void |
addPostModificationListener(Object listener)
Adds a post listener to the list held in the handler. |
void |
addPreModificationListener(Object listener)
Adds a pre listener to the list held in the handler. |
protected ModificationHandler |
createHeadSetHandler(Object toElement)
Creates a new handler for SortedSet headSet. |
protected ModificationHandler |
createSubListHandler(int fromIndex,
int toIndex)
Creates a new handler for subLists that is aware of the offset. |
protected ModificationHandler |
createSubSetHandler(Object fromElement,
Object toElement)
Creates a new handler for SortedSet subSet. |
protected ModificationHandler |
createTailSetHandler(Object fromElement)
Creates a new handler for SortedSet tailSet. |
protected Collection |
getBaseCollection()
Gets the base collection. |
ObservableCollection |
getObservedCollection()
Gets the observed collection. |
Object[] |
getPostModificationListeners()
Gets an array of all the post listeners active in the handler. |
Object[] |
getPreModificationListeners()
Gets an array of all the pre listeners active in the handler. |
protected ModificationHandler |
getRootHandler()
Gets the root handler. |
protected int |
getViewOffset()
Gets the view offset. |
protected void |
postAdd(Object object,
boolean result)
Send an event after add(obj) is called. |
protected void |
postAddAll(Collection coll,
boolean collChanged)
Send an event after addAll(coll) is called. |
protected void |
postAddAllIndexed(int index,
Collection coll,
boolean collChanged)
Send an event after addAll(int,coll) is called on a List. |
protected void |
postAddIndexed(int index,
Object object)
Send an event after add(int,obj) is called on a List. |
protected void |
postAddIterated(int index,
Object object)
Send an event after add(obj) is called on a ListIterator. |
protected void |
postAddNCopies(Object object,
int nCopies,
boolean result)
Send an event after add(obj,int) is called on a Bag. |
protected void |
postClear()
Send an event after clear() is called. |
protected void |
postEvent(boolean modified,
int type,
int index,
Object object,
int repeat,
Object previous,
ObservableCollection view,
int viewOffset)
Handles the post event. |
protected void |
postRemove(Object object,
boolean collChanged)
Send an event after remove(obj) is called. |
protected void |
postRemoveAll(Collection coll,
boolean collChanged)
Send an event after removeAll(coll) is called. |
protected void |
postRemoveIndexed(int index,
Object previousValue)
Send an event after remove(int) is called on a List. |
protected void |
postRemoveIterated(int index,
Object removedValue)
Send an event after remove(obj) is called on an Iterator. |
protected void |
postRemoveNCopies(Object object,
int nCopies,
boolean collChanged)
Send an event after remove(obj,int) is called on a Bag. |
protected void |
postRemoveNext(Object removedValue)
Send an event after remove() is called on a Buffer. |
protected void |
postRetainAll(Collection coll,
boolean collChanged)
Send an event after retainAll(coll) is called. |
protected void |
postSetIndexed(int index,
Object object,
Object previousValue)
Send an event after set(int,obj) is called on a List. |
protected void |
postSetIterated(int index,
Object object,
Object previousValue)
Send an event after set(obj) is called on a ListIterator. |
protected boolean |
preAdd(Object object)
Store data and send event before add(obj) is called. |
protected boolean |
preAddAll(Collection coll)
Store data and send event before addAll(coll) is called. |
protected boolean |
preAddAllIndexed(int index,
Collection coll)
Store data and send event before addAll(int,coll) is called on a List. |
protected boolean |
preAddIndexed(int index,
Object object)
Store data and send event before add(int,obj) is called on a List. |
protected boolean |
preAddIterated(int index,
Object object)
Store data and send event before add(obj) is called on a ListIterator. |
protected boolean |
preAddNCopies(Object object,
int nCopies)
Store data and send event before add(obj,int) is called on a Bag. |
protected boolean |
preClear()
Store data and send event before clear() is called. |
protected boolean |
preEvent(int type,
int index,
Object object,
int repeat,
Object previous,
ObservableCollection view,
int viewOffset)
Handles the pre event. |
protected boolean |
preRemove(Object object)
Store data and send event before remove(obj) is called. |
protected boolean |
preRemoveAll(Collection coll)
Store data and send event before removeAll(coll) is called. |
protected boolean |
preRemoveIndexed(int index)
Store data and send event before remove(int) is called on a List. |
protected boolean |
preRemoveIterated(int index,
Object removedValue)
Store data and send event before remove(obj) is called on an Iterator. |
protected boolean |
preRemoveNCopies(Object object,
int nCopies)
Store data and send event before remove(obj,int) is called on a Bag. |
protected boolean |
preRemoveNext()
Store data and send event before remove() is called on a Buffer. |
protected boolean |
preRetainAll(Collection coll)
Store data and send event before retainAll(coll) is called. |
protected boolean |
preSetIndexed(int index,
Object object)
Store data and send event before set(int,obj) is called on a List. |
protected boolean |
preSetIterated(int index,
Object object,
Object previousValue)
Store data and send event before set(obj) is called on a ListIterator. |
void |
removePostModificationListener(Object listener)
Removes a post listener to the list held in the handler. |
void |
removePreModificationListener(Object listener)
Removes a pre listener to the list held in the handler. |
String |
toString()
Gets a debugging string version of this object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected ModificationHandler()
protected ModificationHandler(ModificationHandler rootHandler, int viewOffset)
rootHandler
- the base underlying handlerviewOffset
- the offset on the base collectionMethod Detail |
---|
public ObservableCollection getObservedCollection()
protected Collection getBaseCollection()
protected ModificationHandler getRootHandler()
protected int getViewOffset()
public Object[] getPreModificationListeners()
This implementation throws UnsupportedOperationException.
UnsupportedOperationException
- if the handler does not support listenerspublic void addPreModificationListener(Object listener)
No error occurs if the listener is null
.
The listener does not necessarily have to be a listener in the classic JavaBean sense. It is entirely up to the handler as to how it interprets the listener parameter. A ClassCastException is thrown if the handler cannot interpret the parameter.
This implementation throws UnsupportedOperationException.
listener
- the listener to add, may be null (ignored)
ClassCastException
- if the listener is not of the correct type
UnsupportedOperationException
- if the handler does not support listenerspublic void removePreModificationListener(Object listener)
No error occurs if the listener is not in the list or the type of the listener is incorrect.
This implementation throws UnsupportedOperationException.
listener
- the listener to remove, may be null (ignored)
UnsupportedOperationException
- if the handler does not support listenerspublic Object[] getPostModificationListeners()
This implementation throws UnsupportedOperationException.
UnsupportedOperationException
- if the handler does not support listenerspublic void addPostModificationListener(Object listener)
No error occurs if the listener is null
.
The listener does not necessarily have to be a listener in the classic JavaBean sense. It is entirely up to the handler as to how it interprets the listener parameter. A ClassCastException is thrown if the handler cannot interpret the parameter.
This implementation throws UnsupportedOperationException.
listener
- the listener to add, may be null (ignored)
ClassCastException
- if the listener is not of the correct type
UnsupportedOperationException
- if the handler does not support listenerspublic void removePostModificationListener(Object listener)
No error occurs if the listener is not in the list or the type of the listener is incorrect.
This implementation throws UnsupportedOperationException.
listener
- the listener to remove, may be null (ignored)
UnsupportedOperationException
- if the handler does not support listenersprotected boolean preEvent(int type, int index, Object object, int repeat, Object previous, ObservableCollection view, int viewOffset)
This implementation does nothing.
type
- the event type to sendindex
- the index where the change starts, the method param or derivedobject
- the object that will be added/removed/set, the method param or derivedrepeat
- the number of repeats of the add/remove, the method param or derivedprevious
- the previous value that will be removed/replaced, must exist in collview
- the view collection that the change was actioned on, null if no viewviewOffset
- the offset of the subList view, -1 if unknownprotected void postEvent(boolean modified, int type, int index, Object object, int repeat, Object previous, ObservableCollection view, int viewOffset)
This implementation does nothing.
modified
- true if the method succeeded in changing the collectiontype
- the event type to sendindex
- the index where the change starts, the method param or derivedobject
- the object that was added/removed/set, the method param or derivedrepeat
- the number of repeats of the add/remove, the method param or derivedprevious
- the previous value that was removed/replace, must have existed in collview
- the view collection that the change was actioned on, null if no viewviewOffset
- the offset of the subList view, -1 if unknownprotected boolean preAdd(Object object)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
It does not set the index for List implementations.
object
- the object being added
protected void postAdd(Object object, boolean result)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
It does not set the index for List implementations.
object
- the object being addedresult
- the result from the add methodprotected boolean preAddIndexed(int index, Object object)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index to add atobject
- the object being added
protected void postAddIndexed(int index, Object object)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index to add atobject
- the object being addedprotected boolean preAddNCopies(Object object, int nCopies)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
object
- the object being addednCopies
- the number of copies being added
protected void postAddNCopies(Object object, int nCopies, boolean result)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
The method result is not used by this implementation (Bag violates the
Collection contract)
object
- the object being addednCopies
- the number of copies being addedresult
- the method resultprotected boolean preAddIterated(int index, Object object)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index of the iteratorobject
- the object being added
protected void postAddIterated(int index, Object object)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index of the iteratorobject
- the object being addedprotected boolean preAddAll(Collection coll)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
coll
- the collection being added
protected void postAddAll(Collection coll, boolean collChanged)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
coll
- the collection being addedcollChanged
- the result from the addAll methodprotected boolean preAddAllIndexed(int index, Collection coll)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index to addAll atcoll
- the collection being added
protected void postAddAllIndexed(int index, Collection coll, boolean collChanged)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index to addAll atcoll
- the collection being addedcollChanged
- the result from the addAll methodprotected boolean preClear()
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
protected void postClear()
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
protected boolean preRemove(Object object)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
object
- the object being removed
protected void postRemove(Object object, boolean collChanged)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
object
- the object being removedcollChanged
- the result from the remove methodprotected boolean preRemoveIndexed(int index)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index to remove at
protected void postRemoveIndexed(int index, Object previousValue)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index to remove atpreviousValue
- the result from the remove methodprotected boolean preRemoveNCopies(Object object, int nCopies)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
object
- the object being removednCopies
- the number of copies being removed
protected void postRemoveNCopies(Object object, int nCopies, boolean collChanged)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
object
- the object being removednCopies
- the number of copies being removedcollChanged
- the result from the remove methodprotected boolean preRemoveNext()
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
protected void postRemoveNext(Object removedValue)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
removedValue
- the previous value at this indexprotected boolean preRemoveIterated(int index, Object removedValue)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index of the iteratorremovedValue
- the object being removed
protected void postRemoveIterated(int index, Object removedValue)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index of the iteratorremovedValue
- the previous value at this indexprotected boolean preRemoveAll(Collection coll)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
coll
- the collection being removed
protected void postRemoveAll(Collection coll, boolean collChanged)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
coll
- the collection being removedcollChanged
- the result from the removeAll methodprotected boolean preRetainAll(Collection coll)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
coll
- the collection being retained
protected void postRetainAll(Collection coll, boolean collChanged)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
coll
- the collection being retainedcollChanged
- the result from the retainAll methodprotected boolean preSetIndexed(int index, Object object)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index to add atobject
- the object being added
protected void postSetIndexed(int index, Object object, Object previousValue)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index to add atobject
- the object being addedpreviousValue
- the result from the set methodprotected boolean preSetIterated(int index, Object object, Object previousValue)
This implementation forwards to preEvent(int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index to set atobject
- the object being addedpreviousValue
- the previous value at this index
protected void postSetIterated(int index, Object object, Object previousValue)
This implementation forwards to postEvent(boolean, int, int, java.lang.Object, int, java.lang.Object, org.apache.commons.events.observable.ObservableCollection, int)
.
index
- the index to set atobject
- the object being addedpreviousValue
- the previous value at this indexprotected ModificationHandler createSubSetHandler(Object fromElement, Object toElement)
fromElement
- the from elementtoElement
- the to elementprotected ModificationHandler createHeadSetHandler(Object toElement)
toElement
- the to elementprotected ModificationHandler createTailSetHandler(Object fromElement)
fromElement
- the from elementprotected ModificationHandler createSubListHandler(int fromIndex, int toIndex)
fromIndex
- the sublist fromIndex (inclusive)toIndex
- the sublist toIndex (exclusive)public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |