Interface WidgetModel

  • All Superinterfaces:
    Observable, java.io.Serializable
    All Known Implementing Classes:
    DefaultWidgetModel

    public interface WidgetModel
    extends java.io.Serializable, Observable
    The widget model holds all data related to a single widget instance. It has a scope of a widget instance which basically means session scope limited to the existence of the widget instance (widget instance can be created and destroyed dynamically when widget templates are used). Also, the visibility of the widget model is limited to the widget instance which it belongs to. Use it as a MVC model to store all data needed by the controller and view but nothing related to the view itself. Changes of the model are observed by widget and used to notify components like editor and actions. If you change any of the objects stored in the widget model directly (by not calling setValue(String, Object) or put(String, Object) on the widget model - which notifies the observers automatically) you can call the method Observable.changed() to trigger the notification.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      <T> T getValue​(java.lang.String expression, java.lang.Class<T> valueType)
      Retrieves the value from this model using the given expression.
      <T> java.lang.Class<T> getValueType​(java.lang.String expression)
      Retrieves the type of the value of this model using the given expression.
      java.lang.Object put​(java.lang.String attribute, java.lang.Object data)
      Adds given data to this widget model and registers it to the given attribute name.
      java.lang.Object remove​(java.lang.String attribute)
      Removes the object registered to the given attribute name.
      void removeAllObservers()
      Removes a previously registered ModelObservers.
      default void removeObserver​(java.lang.Object observerId)
      Removes a previously registered ModelObserver.
      default void removeObserver​(java.lang.String key, java.lang.Object observerId)
      Removes a previously registered ModelObserver.
      void setValue​(java.lang.String expression, java.lang.Object value)
      Stores the given value to this model using the given expression.
    • Method Detail

      • put

        java.lang.Object put​(java.lang.String attribute,
                             java.lang.Object data)
        Adds given data to this widget model and registers it to the given attribute name.
        Parameters:
        attribute - the attribute to register given object to
        data - the object to add
        Returns:
        the previously put data
      • remove

        java.lang.Object remove​(java.lang.String attribute)
        Removes the object registered to the given attribute name.
        Parameters:
        attribute - the attribute to which the data to be removed are registered
        Returns:
        the removed object
      • setValue

        void setValue​(java.lang.String expression,
                      java.lang.Object value)
        Stores the given value to this model using the given expression. You can use expressions like 'product.media.code' to navigate through data structures. See implementations for detail. It also notifies the widget about the change. This is used to keep cockpit NG components like editors and actions uptodate.
        Parameters:
        expression - the expression, can be like 'product.media.code'
        value - the value to store
      • getValue

        <T> T getValue​(java.lang.String expression,
                       java.lang.Class<T> valueType)
        Retrieves the value from this model using the given expression. You can use expressions like 'product.media.code' to navigate through data structures. See implementations for detail.
        Parameters:
        expression - the expression, can be like 'product.media.code'
        valueType - expected value type
        Returns:
        the value
      • getValueType

        <T> java.lang.Class<T> getValueType​(java.lang.String expression)
        Retrieves the type of the value of this model using the given expression.
        Parameters:
        expression - the expression, can be like 'product.media.code'
        Returns:
        the type of the value
      • removeObserver

        default void removeObserver​(java.lang.String key,
                                    java.lang.Object observerId)
        Removes a previously registered ModelObserver.
        Parameters:
        key - attribute for changes of which the observer was interested
        observerId - id of the observer to remove. The object which represents the id should override equals method.
      • removeObserver

        default void removeObserver​(java.lang.Object observerId)
        Removes a previously registered ModelObserver.
        Parameters:
        observerId - id of the observer to remove. The object which represents the id should override equals method.
      • removeAllObservers

        void removeAllObservers()
        Removes a previously registered ModelObservers.