Class ModelEvents<M extends IModel>

  • Type Parameters:
    M - the specific type of model

    public class ModelEvents<M extends IModel>
    extends java.lang.Object
    Notifications on model contents changes. Instances of this class cannot be created directly rather than being obtained from ModelManagement.
    Author:
    Holger Eichelberger
    • Constructor Detail

      • ModelEvents

        ModelEvents()
        Prevents creation outside this package.
    • 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 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​(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 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,
                                            java.util.Map<I,​java.util.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,
                                                  java.util.Map<I,​java.util.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)