@Retention(value=SOURCE)
@Target(value=FIELD)
public @interface ChangeListener
Annotates a property.
This transformation provides a convenient way to register ChangeListeners on an observable bean by leveraging Groovy's closures and the Groovy cast operator.
The following code exemplifies what must be written by hand in order to register a ChangeListener.
import griffon.transform.FXObservable import javafx.beans.value.ChangeListener class MyModel { @FXObservable String name @FXObservable String lastname private def snoopAll = { ob, ov, nv -> ... } MyModel() { nameProperty().addListener(snoopAll as ChangeListener) lastnameProperty().addListener({ ob, ov, nv -> controller.someAction(nv) } as ChangeListener) } }
Applying @ChangeListener to the previous snippet results in the following code
import griffon.transform.FXObservable import griffon.transform.ChangeListener class MyModel { @FXObservable @ChangeListener(snoopAll) String name @FXObservable @ChangeListener({ ob, ov, nv -> controller.someAction(nv)}) String lastname private def snoopAll = { ob, ov, nv -> ... } }
Any closures found as the annotation's value will be either transformed into inner classes that implement ChangeListener (when the value is a closure defined in place) or be casted as a proxy of ChangeListener (when the value is a property reference found in the same class).
List of closures are also supported.