Package groovy.swing.model
Class ClosureModel
java.lang.Object
groovy.swing.model.ClosureModel
- All Implemented Interfaces:
NestedValueModel,ValueModel
Represents a value model using a closure to extract
the value from some source model and an optional write closure
for updating the value.
-
Constructor Summary
ConstructorsConstructorDescriptionClosureModel(ValueModel sourceModel, Closure readClosure) Creates a read-only closure-backed model.ClosureModel(ValueModel sourceModel, Closure readClosure, Closure writeClosure) Creates a closure-backed model with explicit read and write closures.ClosureModel(ValueModel sourceModel, Closure readClosure, Closure writeClosure, Class type) Creates a closure-backed model with an explicit declared type. -
Method Summary
Modifier and TypeMethodDescriptionReturns the model that supplies the source object consumed by the closures.getType()Returns the declared value type for this derived model.getValue()Evaluates the current source object through the read closure.booleanIndicates whether this model has a write closure.voidApplies the write closure to the current source object when the model is editable.
-
Constructor Details
-
ClosureModel
Creates a read-only closure-backed model.- Parameters:
sourceModel- the model that supplies the source objectreadClosure- the closure used to read the derived value
-
ClosureModel
Creates a closure-backed model with explicit read and write closures.- Parameters:
sourceModel- the model that supplies the source objectreadClosure- the closure used to read the derived valuewriteClosure- the closure used to write back a new value, ornullfor read-only access
-
ClosureModel
Creates a closure-backed model with an explicit declared type.- Parameters:
sourceModel- the model that supplies the source objectreadClosure- the closure used to read the derived valuewriteClosure- the closure used to write back a new value, ornullfor read-only accesstype- the declared type of the derived value
-
-
Method Details
-
getSourceModel
Returns the model that supplies the source object consumed by the closures.- Specified by:
getSourceModelin interfaceNestedValueModel- Returns:
- the nested source model
-
getValue
Evaluates the current source object through the read closure.- Specified by:
getValuein interfaceValueModel- Returns:
- the derived value, or
nullif the source model currently holdsnull
-
setValue
Applies the write closure to the current source object when the model is editable.- Specified by:
setValuein interfaceValueModel- Parameters:
value- the value to write
-
getType
Returns the declared value type for this derived model.- Specified by:
getTypein interfaceValueModel- Returns:
- the model type
-
isEditable
public boolean isEditable()Indicates whether this model has a write closure.- Specified by:
isEditablein interfaceValueModel- Returns:
truewhen a write closure is available
-