Class FWObservable
java.lang.Object
net.simplace.core.FWObservable
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 Summary
ConstructorsConstructorDescriptionCreates an observable with an empty parameter map and without functionality.FWObservable(Map<String, Object> aFormInputParameterMap, Object aFormFunctionality) Creates the observable for a functionality. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddObserver(FWObserver aObserver) Adds an observer, provided that it is not already registered.protected voidIndicates 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.clone()intReturns the number of observers of this Observable object.booleanevaluateBoolean(String aExpression, boolean aDefault) Evaluates a control attribute (e.g.booleangetBooleanParameterValue(String aParamKey, boolean aDefault) getParameter(String aKey) getParameter(String aKey, Object aDefault) booleanTests if this object has changed.booleanisParameterSet(String aKey) voidIf this object has changed, as indicated by thehasChangedmethod, then notify all of its observers and then call theclearChangedmethod to indicate that this object has no longer changed.voidnotifyObservers(Object arg) If this object has changed, as indicated by thehasChangedmethod, then notify all of its observers and then call theclearChangedmethod to indicate that this object has no longer changed.voidputAllParameters(Map<String, Object> aParamMap) Adds all parameters of a map (without notification).voidremoveParameter(String aElement) Removes a parameter (without notification).replaceParamTokens(String aString, Object aDefault) Replaces the parameter tokens in a text with the parameters of this observable, seeFWParameterResolver.replace(Map, String, Object, boolean).replaceParamTokens(String aString, Object aDefault, boolean aIgnoreNull) Replaces the parameter tokens in a text with the parameters of this observable, seeFWParameterResolver.replace(Map, String, Object, boolean).protected voidMarks this Observable object as having been changed; the hasChanged method will now return true.voidsetParameterValue(String aKey, Object aValue) Sets a parameter and notifies the observers if the value changed.voidsetParameterValue(String aKey, Object aValue, boolean aShouldNotify) Sets a parameter if the value changed.toString()
-
Constructor Details
-
FWObservable
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 benull
-
FWObservable
public FWObservable()Creates an observable with an empty parameter map and without functionality.
-
-
Method Details
-
addObserver
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 isnull
-
getParameterMap
-
getStringParameterValue
- Parameters:
aKey- the parameter name- Returns:
- the parameter value as string (see
getParameter(String)), ornullif not set
-
getIntegerParameterValue
-
getDoubleParameterValue
-
getBooleanParameterValue
- Parameters:
aParamKey- the parameter nameaDefault- value used if the parameter is not set- Returns:
- the parameter as boolean, see
StringHelper.parseBoolean(String)
-
replaceParamTokens
Replaces the parameter tokens in a text with the parameters of this observable, seeFWParameterResolver.replace(Map, String, Object, boolean).- Parameters:
aString- the text with${...}tokensaDefault- default for missing parameters- Returns:
- the text with replaced tokens
-
replaceParamTokens
Replaces the parameter tokens in a text with the parameters of this observable, seeFWParameterResolver.replace(Map, String, Object, boolean).- Parameters:
aString- the text with${...}tokensaDefault- default for missing parametersaIgnoreNull-trueto replace missing parameters by an empty string- Returns:
- the text with replaced tokens
-
getParameterContext
- Returns:
- the parameters of this observable as context for
FWParameterResolverand JEXL expressions (changes of the context's local variables do not change the parameters)
-
evaluateBoolean
Evaluates a control attribute (e.g.visible,enabled,required,if) as JEXL expression with the parameters of this observable, seeFWParameterResolver.evaluateBoolean(FWParameterContext, String, boolean).- Parameters:
aExpression- the expression, may benullor emptyaDefault- the result for an empty expression or if it cannot be evaluated- Returns:
- the result as boolean
-
getParameter
- Parameters:
aKey- the parameter name- Returns:
- the parameter value (see
FWFrameworkHelper.getParameterFromMap(Map, String, Object)), ornull
-
getParameter
- Parameters:
aKey- the parameter nameaDefault- value returned if the parameter is not set- Returns:
- the parameter value (see
FWFrameworkHelper.getParameterFromMap(Map, String, Object)), or the default
-
setParameterValue
-
setParameterValue
-
getSystemID
- Returns:
- the system id (parameter
SYSTEM_ID)
-
notifyObservers
public void notifyObservers()If this object has changed, as indicated by thehasChangedmethod, then notify all of its observers and then call theclearChangedmethod to indicate that this object has no longer changed.Each observer has its
updatemethod called with two arguments: this observable object andnull. In other words, this method is equivalent to:notifyObservers(null)
- See Also:
-
notifyObservers
If this object has changed, as indicated by thehasChangedmethod, then notify all of its observers and then call theclearChangedmethod to indicate that this object has no longer changed.Each observer has its
updatemethod called with two arguments: this observable object and theargargument.- 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 thenotifyObserversmethods.- See Also:
-
hasChanged
public boolean hasChanged()Tests if this object has changed.- Returns:
trueif and only if thesetChangedmethod has been called more recently than theclearChangedmethod on this object;falseotherwise.- See Also:
-
countObservers
public int countObservers()Returns the number of observers of this Observable object.- Returns:
- the number of observers of this object.
-
getFunctionality
- Returns:
- the owner of the parameters (e.g. the functionality of a GUI form), may be
null
-
clone
-
removeParameter
Removes a parameter (without notification).- Parameters:
aElement- the parameter name
-
putAllParameters
-
isParameterSet
- Parameters:
aKey- the parameter name- Returns:
trueif the parameter has a non-empty value that is not an unresolved${...}token
-
toString
-