Package com.nomagic.uml2.ext.jmi
Class EventSupport
- java.lang.Object
-
- com.nomagic.uml2.ext.jmi.EventSupport
-
- All Implemented Interfaces:
RepositoryListenerRegistry
public class EventSupport extends java.lang.Object implements RepositoryListenerRegistry
Class for firing events and handling event listeners.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
EventSupport.EventFireStartEvent
(package private) static class
EventSupport.NotDeliveredEventsSupport
-
Field Summary
Fields Modifier and Type Field Description private AbstractRepository
abstractRepository
private java.util.List<java.beans.PropertyChangeEvent>
dispatchLaterEventsCache
Cache for events will be fired later.private boolean
enableEventFiring
private boolean
eventDeliveryOn
private long
eventsCount
private java.util.List<java.beans.PropertyChangeEvent>
eventsToBeFired
private java.util.List<java.lang.Runnable>
invokeAfterTransaction
private int
lockEventsRequestsCount
How many setters are locked events tracker.static org.apache.logging.log4j.Logger
LOG
private ModelPropertyChangeListeners
modelListeners
private ModelStateTracker
modelStateTracker
private com.nomagic.uml2.ext.jmi.NonMaskedEventSupportImpl
nonMaskedEventSupport
private EventSupport.NotDeliveredEventsSupport
notDeliveredEventsSupport
private java.util.Collection<java.beans.PropertyChangeListener>
repositoryListeners
-
Constructor Summary
Constructors Constructor Description EventSupport(AbstractRepository abstractRepository)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(java.beans.PropertyChangeListener listener, java.lang.String propertyName)
Adds listener to all elements and listens only for one property change.void
addPropertyChangeListener(java.beans.PropertyChangeListener listener, javax.jmi.reflect.RefObject attachTo)
Adds listener for element.void
addPropertyChangeListener(java.beans.PropertyChangeListener listener, javax.jmi.reflect.RefObject attachTo, java.lang.String propertyName)
Adds listener to given element and listens only for given property change.void
addPropertyChangeListener(java.beans.PropertyChangeListener listener, javax.jmi.reflect.RefObject attachTo, java.util.List propertyNames)
Adds listener to given element and listens only for given property change.void
addRepositoryListener(java.beans.PropertyChangeListener listener)
Add new listener which listens for repository events such asUML2MetamodelConstants.EVENT_FIRE_START
orUML2MetamodelConstants.EVENT_FIRE_STOP
private static java.beans.PropertyChangeEvent
createPropertyChangeEvent(javax.jmi.reflect.RefBaseObject source, java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue, int index, int newIndex)
private void
fireChangedEventFiring(boolean enabled)
Notifies event listeners to notify them that event firing has been stopped or startedvoid
fireInstanceDeletedEvent(javax.jmi.reflect.RefBaseObject source, java.lang.Object deleted, java.lang.Object oldDirectContainer)
Fires event about an instance delete.void
firePropertyChange(java.beans.PropertyChangeEvent evt)
Fires property change event.void
firePropertyChange(javax.jmi.reflect.RefBaseObject source, java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
void
firePropertyChange(javax.jmi.reflect.RefBaseObject source, java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue, int index)
void
firePropertyChange(javax.jmi.reflect.RefBaseObject source, java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue, int index, int newIndex)
long
getEventsCount()
private static ModifiedElements
getModifiedElementsFromNotDeliveredEvents(java.util.Collection<java.beans.PropertyChangeEvent> notDeliveredEvents, ModifiedElements modifiedElements)
NonMaskedEventSupport
getNonMaskedModelListeners()
private java.util.List<java.beans.PropertyChangeEvent>
getNotDeliveredEvents()
private java.lang.Iterable<java.beans.PropertyChangeListener>
getRepositoryListeners()
void
invokeAfterTransaction(java.lang.Runnable r)
If at the current moment firing cached events, running runnable after these events are fired.boolean
isEnableEventFiring()
Determines whether event firing is enabled.static boolean
isModelCleanAfterEventsStopped(java.beans.PropertyChangeEvent event)
private void
notifyAboutRestoredDelivery(ModifiedElements modifiedElements, ModelListener transactionModelListener)
void
removeAllPropertyChangeListeners(javax.jmi.reflect.RefObject removeFrom)
Removes all listeners from given element.void
removeListener(java.beans.PropertyChangeListener listener)
Removes given listener.void
removePropertyChangeListener(java.beans.PropertyChangeListener listener, java.lang.String propertyName)
Removes property change listener.void
removePropertyChangeListener(java.beans.PropertyChangeListener listener, javax.jmi.reflect.RefObject removeFrom)
Removes property change listenervoid
removePropertyChangeListener(java.beans.PropertyChangeListener listener, javax.jmi.reflect.RefObject removeFrom, java.lang.String propertyName)
Removes property change listener.void
removePropertyChangeListener(java.beans.PropertyChangeListener listener, javax.jmi.reflect.RefObject removeFrom, java.util.List propertyNames)
Removes property change listenervoid
removeRepositoryListener(java.beans.PropertyChangeListener listener)
Removes listener which listens for repository events such asUML2MetamodelConstants.EVENT_FIRE_START
orUML2MetamodelConstants.EVENT_FIRE_STOP
void
restoreEventDelivery(ModifiedElements modifiedElements)
Restores event delivery.void
setEnableEventFiring(boolean enableEventFiring)
Enables or disables model event firing.void
startLogEvents()
All property change fires after this call will be cached untilstopLogEvents
invoked.void
stopEventDelivery()
Stops event delivery.void
stopLogEvents()
Fires all events cached between startLogEvents and this call.private boolean
willChangeEventFiring(boolean eventDeliveryOn)
-
-
-
Field Detail
-
LOG
public static final org.apache.logging.log4j.Logger LOG
-
modelListeners
private final ModelPropertyChangeListeners modelListeners
-
nonMaskedEventSupport
private final com.nomagic.uml2.ext.jmi.NonMaskedEventSupportImpl nonMaskedEventSupport
-
eventDeliveryOn
private boolean eventDeliveryOn
-
enableEventFiring
private boolean enableEventFiring
-
eventsToBeFired
private final java.util.List<java.beans.PropertyChangeEvent> eventsToBeFired
-
lockEventsRequestsCount
private int lockEventsRequestsCount
How many setters are locked events tracker.
-
dispatchLaterEventsCache
private final java.util.List<java.beans.PropertyChangeEvent> dispatchLaterEventsCache
Cache for events will be fired later.
-
invokeAfterTransaction
private final java.util.List<java.lang.Runnable> invokeAfterTransaction
-
abstractRepository
private final AbstractRepository abstractRepository
-
repositoryListeners
private final java.util.Collection<java.beans.PropertyChangeListener> repositoryListeners
-
notDeliveredEventsSupport
private EventSupport.NotDeliveredEventsSupport notDeliveredEventsSupport
-
eventsCount
private long eventsCount
-
modelStateTracker
@CheckForNull private ModelStateTracker modelStateTracker
-
-
Constructor Detail
-
EventSupport
public EventSupport(AbstractRepository abstractRepository)
-
-
Method Detail
-
startLogEvents
public void startLogEvents()
All property change fires after this call will be cached untilstopLogEvents
invoked. Calls to this method can be nested. If this method is called 2 times stopLogEvents must be called 2 times to fire all accumulated events.
-
stopLogEvents
public void stopLogEvents()
Fires all events cached between startLogEvents and this call.
-
firePropertyChange
public void firePropertyChange(javax.jmi.reflect.RefBaseObject source, java.lang.String propertyName, @CheckForNull java.lang.Object oldValue, @CheckForNull java.lang.Object newValue)
-
fireInstanceDeletedEvent
public void fireInstanceDeletedEvent(javax.jmi.reflect.RefBaseObject source, java.lang.Object deleted, @CheckForNull java.lang.Object oldDirectContainer)
Fires event about an instance delete.- Parameters:
source
- source of the event.deleted
- element that was deleted.oldDirectContainer
- old direct container (feature data set or resource).
-
firePropertyChange
public void firePropertyChange(javax.jmi.reflect.RefBaseObject source, java.lang.String propertyName, @CheckForNull java.lang.Object oldValue, @CheckForNull java.lang.Object newValue, int index)
-
firePropertyChange
public void firePropertyChange(javax.jmi.reflect.RefBaseObject source, java.lang.String propertyName, @CheckForNull java.lang.Object oldValue, @CheckForNull java.lang.Object newValue, int index, int newIndex)
-
firePropertyChange
public void firePropertyChange(java.beans.PropertyChangeEvent evt)
Fires property change event.- Parameters:
evt
- event
-
createPropertyChangeEvent
private static java.beans.PropertyChangeEvent createPropertyChangeEvent(javax.jmi.reflect.RefBaseObject source, java.lang.String propertyName, @CheckForNull java.lang.Object oldValue, @CheckForNull java.lang.Object newValue, int index, int newIndex)
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener, @CheckForNull javax.jmi.reflect.RefObject attachTo)
Description copied from interface:RepositoryListenerRegistry
Adds listener for element. Listens all events for this element.- Specified by:
addPropertyChangeListener
in interfaceRepositoryListenerRegistry
- Parameters:
listener
- listener to addattachTo
- element to listen. Can be null. If null listens all repository elements.
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener, @CheckForNull java.lang.String propertyName)
Description copied from interface:RepositoryListenerRegistry
Adds listener to all elements and listens only for one property change.- Specified by:
addPropertyChangeListener
in interfaceRepositoryListenerRegistry
- Parameters:
listener
- listener to addpropertyName
- property name to listen
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener, @CheckForNull javax.jmi.reflect.RefObject attachTo, java.util.List propertyNames)
Description copied from interface:RepositoryListenerRegistry
Adds listener to given element and listens only for given property change.- Specified by:
addPropertyChangeListener
in interfaceRepositoryListenerRegistry
- Parameters:
listener
- listener to addattachTo
- element to listen. Can be null. If null listens all repository elements.propertyNames
- property names to listen.
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener, @CheckForNull javax.jmi.reflect.RefObject attachTo, @CheckForNull java.lang.String propertyName)
Description copied from interface:RepositoryListenerRegistry
Adds listener to given element and listens only for given property change.- Specified by:
addPropertyChangeListener
in interfaceRepositoryListenerRegistry
- Parameters:
listener
- listenerattachTo
- element which events listener want to listen. In case null it listens all events from repositorypropertyName
- name of the property
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener, @CheckForNull javax.jmi.reflect.RefObject removeFrom)
Description copied from interface:RepositoryListenerRegistry
Removes property change listener- Specified by:
removePropertyChangeListener
in interfaceRepositoryListenerRegistry
- Parameters:
listener
- listener to remove.removeFrom
- element from which listener can be removed. Can be null, then listener will be removed from all repository.
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener, javax.jmi.reflect.RefObject removeFrom, java.util.List propertyNames)
Description copied from interface:RepositoryListenerRegistry
Removes property change listener- Specified by:
removePropertyChangeListener
in interfaceRepositoryListenerRegistry
- Parameters:
listener
- listener to removeremoveFrom
- element from which remove listener. If null removes from all repository.propertyNames
- property names from which remove listener.
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener, @CheckForNull java.lang.String propertyName)
Description copied from interface:RepositoryListenerRegistry
Removes property change listener.- Specified by:
removePropertyChangeListener
in interfaceRepositoryListenerRegistry
- Parameters:
listener
- listenerpropertyName
- name of the property
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener, @CheckForNull javax.jmi.reflect.RefObject removeFrom, @CheckForNull java.lang.String propertyName)
Description copied from interface:RepositoryListenerRegistry
Removes property change listener.- Specified by:
removePropertyChangeListener
in interfaceRepositoryListenerRegistry
- Parameters:
listener
- listenerremoveFrom
- element which events listener do not want to listen. In case null remove listeners all events from repositorypropertyName
- name of the property
-
isEnableEventFiring
public boolean isEnableEventFiring()
Determines whether event firing is enabled. Given that event firing is enabled does not guarantee that events will be actually fired. Events may not be fired if event delivery has been stopped viastopEventDelivery()
- Returns:
true
if event firing is enabled,false
otherwise
-
addRepositoryListener
public void addRepositoryListener(java.beans.PropertyChangeListener listener)
Add new listener which listens for repository events such asUML2MetamodelConstants.EVENT_FIRE_START
orUML2MetamodelConstants.EVENT_FIRE_STOP
- Parameters:
listener
- listener to be added.- See Also:
removeRepositoryListener(PropertyChangeListener)
,setEnableEventFiring(boolean)
-
removeRepositoryListener
public void removeRepositoryListener(java.beans.PropertyChangeListener listener)
Removes listener which listens for repository events such asUML2MetamodelConstants.EVENT_FIRE_START
orUML2MetamodelConstants.EVENT_FIRE_STOP
- Parameters:
listener
- listener to be removed.- See Also:
addRepositoryListener(PropertyChangeListener)
,setEnableEventFiring(boolean)
-
setEnableEventFiring
public void setEnableEventFiring(boolean enableEventFiring)
Enables or disables model event firing. When this method is invokedUML2MetamodelConstants.EVENT_FIRE_START
orUML2MetamodelConstants.EVENT_FIRE_STOP
is fired to repository property change listeners.- Parameters:
enableEventFiring
- enabled firing- See Also:
addRepositoryListener(PropertyChangeListener)
,removeRepositoryListener(PropertyChangeListener)
-
fireChangedEventFiring
private void fireChangedEventFiring(boolean enabled)
Notifies event listeners to notify them that event firing has been stopped or started- Parameters:
enabled
- event fire enabled.
-
getRepositoryListeners
private java.lang.Iterable<java.beans.PropertyChangeListener> getRepositoryListeners()
-
willChangeEventFiring
private boolean willChangeEventFiring(boolean eventDeliveryOn)
-
stopEventDelivery
public void stopEventDelivery()
Stops event delivery. Even non-masked event listeners will not receive events until event delivery is restored.UML2MetamodelConstants.EVENT_FIRE_STOP
is fired to repository property change listeners if event firing was enabled before stopping event delivery
-
restoreEventDelivery
public void restoreEventDelivery(ModifiedElements modifiedElements)
Restores event delivery. Non-masked event listeners will start getting events again. If event firing was not disabled viasetEnableEventFiring(boolean)
then other event listeners will start getting events andUML2MetamodelConstants.EVENT_FIRE_START
will be fired for repository property change listeners- Parameters:
modifiedElements
- provider for changed elements
-
notifyAboutRestoredDelivery
private void notifyAboutRestoredDelivery(ModifiedElements modifiedElements, ModelListener transactionModelListener)
-
getModifiedElementsFromNotDeliveredEvents
private static ModifiedElements getModifiedElementsFromNotDeliveredEvents(java.util.Collection<java.beans.PropertyChangeEvent> notDeliveredEvents, ModifiedElements modifiedElements)
-
getNotDeliveredEvents
private java.util.List<java.beans.PropertyChangeEvent> getNotDeliveredEvents()
-
removeAllPropertyChangeListeners
public void removeAllPropertyChangeListeners(javax.jmi.reflect.RefObject removeFrom)
Description copied from interface:RepositoryListenerRegistry
Removes all listeners from given element.- Specified by:
removeAllPropertyChangeListeners
in interfaceRepositoryListenerRegistry
- Parameters:
removeFrom
- element from which listener should be removed
-
removeListener
public void removeListener(java.beans.PropertyChangeListener listener)
Description copied from interface:RepositoryListenerRegistry
Removes given listener.- Specified by:
removeListener
in interfaceRepositoryListenerRegistry
- Parameters:
listener
- listener to remove.
-
invokeAfterTransaction
public void invokeAfterTransaction(java.lang.Runnable r)
If at the current moment firing cached events, running runnable after these events are fired. Running now in other case.- Parameters:
r
-Runnable
to run.
-
getEventsCount
public long getEventsCount()
- Returns:
- number of changes in repository since its creation. Any change in the model increase this counter;
-
getNonMaskedModelListeners
public NonMaskedEventSupport getNonMaskedModelListeners()
- Returns:
- ModelListener which sends notification even event fire is disabled.
-
isModelCleanAfterEventsStopped
public static boolean isModelCleanAfterEventsStopped(java.beans.PropertyChangeEvent event)
- Parameters:
event
- event with name EVENT_FIRE_START- Returns:
- true if model is the same when EVENT_FIRE_STOP and EVENT_FIRE_START events are fired.
-
-