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 Object
Notifications on model contents changes. Instances of this class cannot be created directly rather than being obtained from ModelManagement.
Author:
Holger Eichelberger
  • Field Details

  • Constructor Details

    • ModelEvents

      ModelEvents()
      Prevents creation outside this package.
  • Method Details

    • 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 object
      start - whether processing started or ended
      type - 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 replaced
      newModel - the new model replacing oldModel
    • updateListeners

      private <T> void updateListeners(List<T> oldListeners, Map<M,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 model
      listeners - map of all listeners currently registered
      oldModel - the old model being replaced
      newModel - the new model replacing oldModell
    • 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 by ModelManagement.updateModel(IModel, java.net.URI, IModelLoader) before. A listener may be added multiple times (whyever).
      Parameters:
      model - the model to add the listener for
      listener - 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 about
      listener - 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 from
      listener - the listener
      Returns:
      true if the listener was removed, false if 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 by ModelManagement.reload(IModel). A listener may be added multiple times (whyever).
      Parameters:
      model - the model to add the listener for
      listener - 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 from
      listener - the listener
      Returns:
      true if the listener was removed, false if 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 removed
      listener - the listener
      Returns:
      true if the listener was removed, false if not (for any reason)
    • add

      private static <T, I> void add(I identifier, Map<I,List<T>> listeners, T listener)
      Adds the listener for identifier to listeners.
      Type Parameters:
      T - the listener type
      I - the identifier type
      Parameters:
      identifier - the identifier
      listeners - the listeners map
      listener - the listener to be removed
    • remove

      private static <T, I> boolean remove(I identifier, Map<I,List<T>> listeners, T listener)
      Removes the listener for identifier from listeners.
      Type Parameters:
      T - the listener type
      I - the identifier type
      Parameters:
      identifier - the identifier
      listeners - the listeners map
      listener - the listener to be removed
      Returns:
      true if the listener was removed, false if not (for any reason)