Class ChangeSupport
java.lang.Object
org.eclipse.persistence.jpa.jpql.tools.model.query.ChangeSupport
This
ChangeSupport is responsible to notifies registered listeners upon changes made
to a StateObject, those changes are either a property has changed (IPropertyChangeListener)
or the content of a list has changed (IListChangeListener).- Since:
- 2.4
- Version:
- 2.4
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> voidaddItem(ListHolderStateObject<T> source, List<T> items, String listName, T item) Adds the given item as a child to the given list.<T> voidaddItems(ListHolderStateObject<T> source, List<T> list, String listName, List<? extends T> items) Adds the given items as children to the given list.voidaddListChangeListener(String listName, IListChangeListener<?> listener) Registers the givenIListChangeListenerfor the specified list.protected <T> voidRegisters the given list for the specified name.voidaddPropertyChangeListener(String propertyName, IPropertyChangeListener<?> listener) Registers the givenIPropertyChangeListenerfor the specified property.<T> booleancanMoveDown(List<T> list, T stateObject) Determines whether the given item can be moved down by one position in the list owned by its parent.<T> booleanDetermines whether the given item can be moved up by one position in the list owned by its parent.protected <T> voidfireListChangeEvent(IListChangeEvent<T> event) voidfirePropertyChanged(String propertyName, Object oldValue, Object newValue) Notifies theIPropertyChangeListenersthat have been registered with the given property name that the property has changed.booleanhasListChangeListeners(String listName) Determines whether there are at least oneIListChangeListenerregistered to listen for changes made to the list with the given list name.protected booleanhasListeners(Map<String, ?> listeners, String name) Determines whether there are at least one listener registered.booleanhasPropertyChangeListeners(String propertyName) Determines whether there are at least oneIPropertyChangeListenerregistered to listen for changes made to the property with the given property name.protected voidinitialize(StateObject source) Initializes thisChangeSupport.protected <T> ListIterable<IListChangeListener<T>> listChangeListeners(String listName) <T> voidmoveDown(ListHolderStateObject<T> source, List<T> items, String listName, T item) Moves the givenStateObjectdown by one position in the list owned by its parent.protected <T> voidmoveItem(ListHolderStateObject<T> source, List<T> items, IListChangeEvent.EventType eventType, String listName, T item, int oldIndex, int newIndex) Moves the given item from its current position to a new position in the list owned by its parent.<T> voidmoveUp(ListHolderStateObject<T> source, List<T> items, String listName, T item) Moves the given item up by one position in the list owned by its parent.protected ListIterable<IPropertyChangeListener<?>> propertyChangeListeners(String propertyName) <T> voidremoveItem(ListHolderStateObject<T> source, List<T> items, String listName, T item) Removes the given item from the list of children.<T> voidremoveItems(ListHolderStateObject<T> source, List<? extends T> list, String listName, Collection<? extends T> items) Removes the given items from the list of children.voidremoveListChangeListener(String listName, IListChangeListener<?> listener) Unregisters the givenIListChangeListenerthat was registered for the specified list.protected <T> voidUnregisters the given listener that was registered for the specified name.voidremovePropertyChangeListener(String propertyName, IPropertyChangeListener<?> listener) Unregisters the givenIPropertyChangeListenerthat was registered for the specified property.<T> voidreplaceItem(ListHolderStateObject<T> source, List<T> items, String listName, int index, T item) Replaces the item at the given position by a new one.<T> voidreplaceItems(ListHolderStateObject<T> source, List<T> items, String listName, List<T> newItems) Replaces the given list by removing any existing items and adding the items contained in the second list.
-
Constructor Details
-
ChangeSupport
Creates a newChangeSupport.- Parameters:
source- The object for which this object will take care of notifying the listeners upon changes made to the object's internal state- Throws:
NullPointerException- The sourceStateObjectcannot benull
-
-
Method Details
-
addItem
Adds the given item as a child to the given list.- Type Parameters:
T- The type of the items- Parameters:
source- TheListHolderStateObjectfrom where the change is comingitems- The list of to which the child is addedlistName- The name associated with the listitem- The child to become a child of this one
-
addItems
public <T> void addItems(ListHolderStateObject<T> source, List<T> list, String listName, List<? extends T> items) Adds the given items as children to the given list.- Type Parameters:
T- The type of the items- Parameters:
source- TheListHolderStateObjectfrom where the change is cominglist- The list of items to which the child is addedlistName- The name associated with the listitems- The child to become children of this one
-
addListChangeListener
Registers the givenIListChangeListenerfor the specified list. The listener will be notified only when items are added, removed, moved from the list.- Parameters:
listName- The name of the list for which the listener will be notified when the content of the list has changedlistener- The listener to be notified upon changes- Throws:
NullPointerException-IListChangeListenercannot benullIllegalArgumentException- The listener is already registered with the list name
-
addListener
protected <T> void addListener(Map<String, List<T>> listeners, Class<?> listenerType, String name, T listener) Registers the given list for the specified name. The listener will be notified upon changes.- Parameters:
listeners- The list of listeners from which the given listener is addedlistenerType- The type of the listener, which is only used in the exception's messagename- The name of the event for which the listener is registeredlistener- The listener to register- Throws:
NullPointerException-IPropertyChangeListenercannot benullIllegalArgumentException- The listener is already registered with the given name
-
addPropertyChangeListener
Registers the givenIPropertyChangeListenerfor the specified property. The listener will be notified only for changes to the specified property.- Parameters:
propertyName- The name of the property for which the listener was registeredlistener- The listener to be notified upon changes- Throws:
NullPointerException-IPropertyChangeListenercannot benullIllegalArgumentException- The listener is already registered with the property name
-
canMoveDown
Determines whether the given item can be moved down by one position in the list owned by its parent.- Parameters:
list- The list used to determine if the given item can be moved down in that liststateObject- The item that could potentially be moved down- Returns:
trueif the object can be moved down by one unit;falseotherwise
-
canMoveUp
Determines whether the given item can be moved up by one position in the list owned by its parent.- Parameters:
list- The list used to determine if the given item can be moved up in that listitem- The item that could potentially be moved up- Returns:
trueif the object can be moved up by one unit;falseotherwise
-
fireListChangeEvent
-
firePropertyChanged
Notifies theIPropertyChangeListenersthat have been registered with the given property name that the property has changed.- Parameters:
propertyName- The name of the property associated with the property changeoldValue- The old value of the property that changednewValue- The new value of the property that changed
-
hasListChangeListeners
Determines whether there are at least oneIListChangeListenerregistered to listen for changes made to the list with the given list name.- Parameters:
listName- The name of the list to check if it has registered listeners- Returns:
trueif listeners have been registered for the given list name;falseotherwise
-
hasListeners
Determines whether there are at least one listener registered.- Parameters:
name- The name of the property or list to check if it has registered listeners- Returns:
trueif listeners have been registered for the given name;falseotherwise
-
hasPropertyChangeListeners
Determines whether there are at least oneIPropertyChangeListenerregistered to listen for changes made to the property with the given property name.- Parameters:
propertyName- The name of the property to check if it has registered listeners- Returns:
trueif listeners have been registered for the given property name;falseotherwise
-
initialize
Initializes thisChangeSupport.- Parameters:
source- The object for which this object will take care of notifying the listeners upon changes made to the object's internal state- Throws:
NullPointerException- The sourceStateObjectcannot benull
-
listChangeListeners
-
moveDown
Moves the givenStateObjectdown by one position in the list owned by its parent.- Type Parameters:
T- The type of the items- Parameters:
source- TheListHolderStateObjectfrom where the change is comingitems- The list of items to which the child is moved downlistName- The name associated with the listitem- The child to move down within the list
-
moveItem
protected <T> void moveItem(ListHolderStateObject<T> source, List<T> items, IListChangeEvent.EventType eventType, String listName, T item, int oldIndex, int newIndex) Moves the given item from its current position to a new position in the list owned by its parent.- Type Parameters:
T- The type of the items- Parameters:
source- TheListHolderStateObjectfrom where the change is comingitems- The list of items to which the child is movedeventType- The type describing how the item was moved (up or down)listName- The name associated with the listitem- The child to move within the listoldIndex- The current position of the item to movenewIndex- The new position within the list
-
moveUp
Moves the given item up by one position in the list owned by its parent.- Type Parameters:
T- The type of the items- Parameters:
source- TheListHolderStateObjectfrom where the change is comingitems- The list of items to which the child is moved uplistName- The name associated with the listitem- The child to move up within the list
-
propertyChangeListeners
-
removeItem
Removes the given item from the list of children.- Type Parameters:
T- The type of the items- Parameters:
source- TheListHolderStateObjectfrom where the change is comingitems- The list of item to which the child is removedlistName- The name associated with the listitem- The child to removed from the list
-
removeItems
public <T> void removeItems(ListHolderStateObject<T> source, List<? extends T> list, String listName, Collection<? extends T> items) Removes the given items from the list of children.- Type Parameters:
T- The type of the items- Parameters:
source- TheListHolderStateObjectfrom where the change is cominglist- The list of items to which the child is removedlistName- The name associated with the listitems- The items to removed from the list
-
removeListChangeListener
Unregisters the givenIListChangeListenerthat was registered for the specified list. The listener will no longer be notified only when items are added, removed, moved from the list.- Parameters:
listName- The name of the list for which the listener was registeredlistener- The listener to unregister- Throws:
NullPointerException-IListChangeListenercannot benullIllegalArgumentException- The listener was never registered with the list name
-
removeListener
protected <T> void removeListener(Map<String, List<T>> listeners, Class<?> listenerType, String name, T listener) Unregisters the given listener that was registered for the specified name. The listener will no longer be notified upon changes.- Parameters:
listeners- The list of listeners from which the given listener is removedlistenerType- The type of the listener, which is only used in the exception's messagename- The name of the event for which the listener was registeredlistener- The listener to unregister- Throws:
NullPointerException-IPropertyChangeListenercannot benullIllegalArgumentException- The listener was never registered with the given name
-
removePropertyChangeListener
Unregisters the givenIPropertyChangeListenerthat was registered for the specified property. The listener will no longer be notified when the property changes.- Parameters:
propertyName- The name of the property for which the listener was registeredlistener- The listener to unregister- Throws:
NullPointerException-IPropertyChangeListenercannot benullIllegalArgumentException- The listener was never registered with the property name
-
replaceItem
public <T> void replaceItem(ListHolderStateObject<T> source, List<T> items, String listName, int index, T item) Replaces the item at the given position by a new one.- Type Parameters:
T- The type of the items- Parameters:
source- TheListHolderStateObjectfrom where the change is comingitems- The list of items to which a child is replacedlistName- The name associated with the listindex- The position of the item to replaceitem- The item to replace the one at the given position
-
replaceItems
public <T> void replaceItems(ListHolderStateObject<T> source, List<T> items, String listName, List<T> newItems) Replaces the given list by removing any existing items and adding the items contained in the second list.- Type Parameters:
T- The type of the items- Parameters:
source- TheListHolderStateObjectfrom where the change is comingitems- The list of items to which the child is removedlistName- The name associated with the listnewItems- The items to removed from the list
-