@Retention(value=SOURCE) @Target(value=FIELD) public @interface MapChangeListener
Annotates a property.
This transformation provides a convenient way to register MapChangeListeners on an ObservableMap 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.MapChangeListener import griffon.transform.FXObservable import javafx.collections.FXCollections import javafx.collections.ObservableMap import griffon.core.artifact.GriffonModel @griffon.metadata.ArtifactProviderFor(GriffonModel) class SampleModel { def controller @FXObservable @MapChangeListener(snoop) ObservableMap map = FXCollections.observableHashMap() def snoop = { change -> ... } }
Applying @ChangeListener to the previous snippet results in the following code
import javafx.collections.MapChangeListener import javafx.collections.FXCollections import javafx.collections.ObservableMap import griffon.core.artifact.GriffonModel @griffon.metadata.ArtifactProviderFor(GriffonModel) class SampleModel { def controller @FXObservable ObservableMap map = FXCollections.observableHashMap() def snoop = { change -> ... } SampleModel() { mapProperty().addListener(snoopAll as MapChangeListener) } }
Any closures found as the annotation's value will be either transformed into inner classes that implement MapChangeListener (when the value is a closure defined in place) or be casted as a proxy of MapChangeListener (when the value is a property reference found in the same class).
List of closures are also supported.
public abstract String value