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.
-
-
Field Summary
Fields Modifier and Type Field Description static org.apache.logging.log4j.Logger
LOG
-
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
void
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()
NonMaskedEventSupport
getNonMaskedModelListeners()
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)
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.
-
-
-
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
-
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)
-
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
-
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.
-
-