Class FWObservable

java.lang.Object
net.simplace.core.FWObservable

public class FWObservable extends Object
Parameter map of a functionality (form) that notifies registered observers (form components) when a parameter changes. Modelled on java.util.Observable; while the observers are notified, observers that are a FWBusyIndicator show a busy animation.
Author:
Andreas Enders
  • Constructor Details

    • FWObservable

      public FWObservable(Map<String,Object> aFormInputParameterMap, Object aFormFunctionality)
      Creates the observable for a functionality.
      Parameters:
      aFormInputParameterMap - the parameter map (used directly, not copied)
      aFormFunctionality - the owner of the parameters (e.g. the functionality of a GUI form), may be null
    • FWObservable

      public FWObservable()
      Creates an observable with an empty parameter map and without functionality.
  • Method Details

    • addObserver

      public void addObserver(FWObserver aObserver)
      Adds an observer, provided that it is not already registered. Observers are notified in the order of registration.
      Parameters:
      aObserver - the observer to be added
      Throws:
      NullPointerException - if the observer is null
    • getParameterMap

      public Map<String,Object> getParameterMap()
      Returns:
      the parameter map (the live map)
    • getStringParameterValue

      public String getStringParameterValue(String aKey)
      Parameters:
      aKey - the parameter name
      Returns:
      the parameter value as string (see getParameter(String)), or null if not set
    • getIntegerParameterValue

      public Integer getIntegerParameterValue(String aKey)
      Parameters:
      aKey - the parameter name
      Returns:
      the parameter as Integer (decimals are truncated), or null if not set or not a number
    • getDoubleParameterValue

      public Double getDoubleParameterValue(String aKey)
      Parameters:
      aKey - the parameter name
      Returns:
      the parameter as Double, or null if not set or not a number
    • getBooleanParameterValue

      public boolean getBooleanParameterValue(String aParamKey, boolean aDefault)
      Parameters:
      aParamKey - the parameter name
      aDefault - value used if the parameter is not set
      Returns:
      the parameter as boolean, see StringHelper.parseBoolean(String)
    • replaceParamTokens

      public String replaceParamTokens(String aString, Object aDefault)
      Replaces the parameter tokens in a text with the parameters of this observable, see FWParameterResolver.replace(Map, String, Object, boolean).
      Parameters:
      aString - the text with ${...} tokens
      aDefault - default for missing parameters
      Returns:
      the text with replaced tokens
    • replaceParamTokens

      public String replaceParamTokens(String aString, Object aDefault, boolean aIgnoreNull)
      Replaces the parameter tokens in a text with the parameters of this observable, see FWParameterResolver.replace(Map, String, Object, boolean).
      Parameters:
      aString - the text with ${...} tokens
      aDefault - default for missing parameters
      aIgnoreNull - true to replace missing parameters by an empty string
      Returns:
      the text with replaced tokens
    • getParameterContext

      public FWParameterContext getParameterContext()
      Returns:
      the parameters of this observable as context for FWParameterResolver and JEXL expressions (changes of the context's local variables do not change the parameters)
    • evaluateBoolean

      public boolean evaluateBoolean(String aExpression, boolean aDefault)
      Evaluates a control attribute (e.g. visible, enabled, required, if) as JEXL expression with the parameters of this observable, see FWParameterResolver.evaluateBoolean(FWParameterContext, String, boolean).
      Parameters:
      aExpression - the expression, may be null or empty
      aDefault - the result for an empty expression or if it cannot be evaluated
      Returns:
      the result as boolean
    • getParameter

      public Object getParameter(String aKey)
      Parameters:
      aKey - the parameter name
      Returns:
      the parameter value (see FWFrameworkHelper.getParameterFromMap(Map, String, Object)), or null
    • getParameter

      public Object getParameter(String aKey, Object aDefault)
      Parameters:
      aKey - the parameter name
      aDefault - value returned if the parameter is not set
      Returns:
      the parameter value (see FWFrameworkHelper.getParameterFromMap(Map, String, Object)), or the default
    • setParameterValue

      public void setParameterValue(String aKey, Object aValue)
      Sets a parameter and notifies the observers if the value changed.
      Parameters:
      aKey - the parameter name
      aValue - the new value; null is ignored
    • setParameterValue

      public void setParameterValue(String aKey, Object aValue, boolean aShouldNotify)
      Sets a parameter if the value changed.
      Parameters:
      aKey - the parameter name
      aValue - the new value; null is ignored (a parameter cannot be cleared this way)
      aShouldNotify - true to notify the observers of the change
    • getSystemID

      public String getSystemID()
      Returns:
      the system id (parameter SYSTEM_ID)
    • notifyObservers

      public void notifyObservers()
      If this object has changed, as indicated by the hasChanged method, then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed.

      Each observer has its update method called with two arguments: this observable object and null. In other words, this method is equivalent to:

      notifyObservers(null)
      See Also:
    • notifyObservers

      public void notifyObservers(Object arg)
      If this object has changed, as indicated by the hasChanged method, then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed.

      Each observer has its update method called with two arguments: this observable object and the arg argument.

      Parameters:
      arg - any object.
      See Also:
    • setChanged

      protected void setChanged()
      Marks this Observable object as having been changed; the hasChanged method will now return true.
    • clearChanged

      protected void clearChanged()
      Indicates that this object has no longer changed, or that it has already notified all of its observers of its most recent change, so that the hasChanged method will now return false. This method is called automatically by the notifyObservers methods.
      See Also:
    • hasChanged

      public boolean hasChanged()
      Tests if this object has changed.
      Returns:
      true if and only if the setChanged method has been called more recently than the clearChanged method on this object; false otherwise.
      See Also:
    • countObservers

      public int countObservers()
      Returns the number of observers of this Observable object.
      Returns:
      the number of observers of this object.
    • getFunctionality

      public Object getFunctionality()
      Returns:
      the owner of the parameters (e.g. the functionality of a GUI form), may be null
    • clone

      public FWObservable clone()
      Overrides:
      clone in class Object
      Returns:
      a new observable with a copy of the parameter map and the same functionality, without observers
    • removeParameter

      public void removeParameter(String aElement)
      Removes a parameter (without notification).
      Parameters:
      aElement - the parameter name
    • putAllParameters

      public void putAllParameters(Map<String,Object> aParamMap)
      Adds all parameters of a map (without notification).
      Parameters:
      aParamMap - the parameters to add
    • isParameterSet

      public boolean isParameterSet(String aKey)
      Parameters:
      aKey - the parameter name
      Returns:
      true if the parameter has a non-empty value that is not an unresolved ${...} token
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      system id, parameters and observers as text