Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • source <Object> The object that trigers triggers the binding update
  • sourceProperty <String> A property that is read for the update and whose change triggers the update
  • sourceEvent <String> The event name trigger an update
  • sourceValue <Closure> A closure providing the value whn when sourceEvent triggers
  • target <Object> The object to be updated when a bound value changes
  • targetProperty <String> The property on the target update to which the queried value will be written
  • validator <Closure> If the closure returns null or Boolean.FALSE then a triggered binding will be canceled
  • converter <Closure> Takes the queried value and converts it to another object to be written to the targetProperty. The queried value is passed in "it" to the closure.

Content

bind accepts no content

...

Code Block
swing.frame() {
  panel {
    textField('Change Me!', id:'tf')
    button(text: bind(source:tf.document, sourceEvent:'undoableEditHappened', sourceValue:{tf.text}))
  }
}

Example with validator and converter:

Code Block

swing.frame() {
 panel
  {
   textField('Change Me!', id:'tf')
   button(text: bind(source:tf.document, sourceEvent:'undoableEditHappened', sourceValue:{tf.text},
     validator: { tf.text.length() >= 1}, converter: { it.toLowerCase() } ))
  }
}

The validator prevents the button text from having less than 1 char and the converter makes the button text all lowercase.

Note: Tested on Groovy 1.5.1