Package: groovy.swing.model

## [Java] Class ClosureModel

- groovy.swing.model.ClosureModel

- All Implemented Interfaces and Traits:
    NestedValueModel, ValueModel

      public class ClosureModel
      extends Object
      implements 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

    Constructors
    Constructor and description
    `ClosureModel(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.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public ValueModel` | `getSourceModel()` Returns the model that supplies the source object consumed by the closures.
    `` | `public Class` | `getType()` Returns the declared value type for this derived model.
    `` | `public Object` | `getValue()` Evaluates the current source object through the read closure.
    `` | `public boolean` | `isEditable()` Indicates whether this model has a write closure.
    `` | `public void` | `setValue(Object value)` Applies the write closure to the current source object when the model is editable.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### public ClosureModel(ValueModel sourceModel, Closure readClosure)

      Creates a read-only closure-backed model.

      Parameters:
        `sourceModel` - the model that supplies the source object
        `readClosure` - the closure used to read the derived value

    - #### public ClosureModel(ValueModel sourceModel, Closure readClosure, Closure writeClosure)

      Creates a closure-backed model with explicit read and write closures.

      Parameters:
        `sourceModel` - the model that supplies the source object
        `readClosure` - the closure used to read the derived value
        `writeClosure` - the closure used to write back a new value, or `null` for read-only access

    - #### public ClosureModel(ValueModel sourceModel, Closure readClosure, Closure writeClosure, Class type)

      Creates a closure-backed model with an explicit declared type.

      Parameters:
        `sourceModel` - the model that supplies the source object
        `readClosure` - the closure used to read the derived value
        `writeClosure` - the closure used to write back a new value, or `null` for read-only access
        `type` - the declared type of the derived value

  - ### Method Detail

    - #### public ValueModel getSourceModel()

      Returns the model that supplies the source object consumed by the closures.

      Returns:
        the nested source model

    - #### public Class getType()

      Returns the declared value type for this derived model.

      Returns:
        the model type

    - #### public Object getValue()

      Evaluates the current source object through the read closure.

      Returns:
        the derived value, or `null` if the source model currently holds `null`

    - #### public boolean isEditable()

      Indicates whether this model has a write closure.

      Returns:
        `true` when a write closure is available

    - #### public void setValue(Object value)

      Applies the write closure to the current source object when the model is editable.

      Parameters:
        `value` - the value to write