Class ModelEvents<M extends IModel>
- java.lang.Object
-
- net.ssehub.easy.basics.modelManagement.ModelEvents<M>
-
- Type Parameters:
M- the specific type of model
public class ModelEvents<M extends IModel> extends java.lang.ObjectNotifications on model contents changes. Instances of this class cannot be created directly rather than being obtained fromModelManagement.- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<M,java.util.List<IModelListener<M>>>modelListenersprivate java.util.Map<ModelInfo<M>,java.util.List<IModelProcessingListener<M>>>modelProcessingListenersprivate java.util.Map<M,java.util.List<IModelReloadListener<M>>>modelReloadListeners
-
Constructor Summary
Constructors Constructor Description ModelEvents()Prevents creation outside this package.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static <T,I>
voidadd(I identifier, java.util.Map<I,java.util.List<T>> listeners, T listener)Adds thelistenerforidentifiertolisteners.voidaddModelListener(M model, IModelListener<M> listener)Adds a model listener for the specified model.voidaddProcessingListener(ModelInfo<M> info, IModelProcessingListener<M> listener)Adds a model processing listener for the specified model information object.voidaddReloadListener(M model, IModelReloadListener<M> listener)Adds a model reload listener for the specified model.voidnotifyModelProcessing(ModelInfo<M> info, boolean start, IModelProcessingListener.Type type)Notifies about model processing events.(package private) voidnotifyModelReloadFailed(M model)Notifies registered listeners about a failed model reload.(package private) voidnotifyModelReplacement(M oldModel, M newModel)Notifies registered listeners about replacing a model instance.private static <T,I>
booleanremove(I identifier, java.util.Map<I,java.util.List<T>> listeners, T listener)Removes thelistenerforidentifierfromlisteners.(package private) voidremoveAllListeners(M model)Removes all listeners (no processing listeners).booleanremoveModelListener(M model, IModelListener<M> listener)Removes a model listener from the specified model.booleanremoveModelReloadListener(M model, IModelReloadListener<M> listener)Removes a model reload listener from the specified model.booleanremoveProcessingListener(ModelInfo<M> info, IModelProcessingListener<M> listener)Removes a model processing listener for the specified model information object.private <T> voidupdateListeners(java.util.List<T> oldListeners, java.util.Map<M,java.util.List<T>> listeners, M oldModel, M newModel)Updates the listeners if a model is replaced.
-
-
-
Field Detail
-
modelListeners
private java.util.Map<M extends IModel,java.util.List<IModelListener<M extends IModel>>> modelListeners
-
modelReloadListeners
private java.util.Map<M extends IModel,java.util.List<IModelReloadListener<M extends IModel>>> modelReloadListeners
-
-
Method Detail
-
notifyModelReloadFailed
void notifyModelReloadFailed(M model)
Notifies registered listeners about a failed model reload.- Parameters:
model- the model that cannot be reloaded
-
notifyModelProcessing
public void notifyModelProcessing(ModelInfo<M> info, boolean start, IModelProcessingListener.Type type)
Notifies about model processing events.- Parameters:
info- the model information objectstart- whether processing started or endedtype- the type of the processing
-
notifyModelReplacement
void notifyModelReplacement(M oldModel, M newModel)
Notifies registered listeners about replacing a model instance. Changes the listener registrations accordingly.- Parameters:
oldModel- the old model being replacednewModel- the new model replacingoldModel
-
updateListeners
private <T> void updateListeners(java.util.List<T> oldListeners, java.util.Map<M,java.util.List<T>> listeners, M oldModel, M newModel)Updates the listeners if a model is replaced. Otherwise the listeners would listen to the wrong model.- Type Parameters:
T- the listener type- Parameters:
oldListeners- list of listeners that were listening to the old modellisteners- map of all listeners currently registeredoldModel- the old model being replacednewModel- the new model replacingoldModell
-
removeAllListeners
void removeAllListeners(M model)
Removes all listeners (no processing listeners).- Parameters:
model- the model to remove all listeners for
-
addModelListener
public void addModelListener(M model, IModelListener<M> listener)
Adds a model listener for the specified model. Note that notifications about models will only be issued if the model was added to this instance byModelManagement.updateModel(IModel, java.net.URI, IModelLoader)before. A listener may be added multiple times (whyever).- Parameters:
model- the model to add the listener forlistener- the listener
-
addProcessingListener
public void addProcessingListener(ModelInfo<M> info, IModelProcessingListener<M> listener)
Adds a model processing listener for the specified model information object.- Parameters:
info- the information object to be informed aboutlistener- the listener
-
removeModelListener
public boolean removeModelListener(M model, IModelListener<M> listener)
Removes a model listener from the specified model.- Parameters:
model- the model to remove the listener fromlistener- the listener- Returns:
trueif thelistenerwas removed,falseif not (for any reason)
-
addReloadListener
public void addReloadListener(M model, IModelReloadListener<M> listener)
Adds a model reload listener for the specified model. Note that notifications about models will only be issued if the model was reloaded byModelManagement.reload(IModel). A listener may be added multiple times (whyever).- Parameters:
model- the model to add the listener forlistener- the listener
-
removeModelReloadListener
public boolean removeModelReloadListener(M model, IModelReloadListener<M> listener)
Removes a model reload listener from the specified model.- Parameters:
model- the model to remove the listener fromlistener- the listener- Returns:
trueif thelistenerwas removed,falseif not (for any reason)
-
removeProcessingListener
public boolean removeProcessingListener(ModelInfo<M> info, IModelProcessingListener<M> listener)
Removes a model processing listener for the specified model information object.- Parameters:
info- the information object to be removedlistener- the listener- Returns:
trueif thelistenerwas removed,falseif not (for any reason)
-
add
private static <T,I> void add(I identifier, java.util.Map<I,java.util.List<T>> listeners, T listener)Adds thelistenerforidentifiertolisteners.- Type Parameters:
T- the listener typeI- the identifier type- Parameters:
identifier- the identifierlisteners- the listeners maplistener- the listener to be removed
-
remove
private static <T,I> boolean remove(I identifier, java.util.Map<I,java.util.List<T>> listeners, T listener)Removes thelistenerforidentifierfromlisteners.- Type Parameters:
T- the listener typeI- the identifier type- Parameters:
identifier- the identifierlisteners- the listeners maplistener- the listener to be removed- Returns:
trueif thelistenerwas removed,falseif not (for any reason)
-
-