Griffon 0.9.5-rc2

griffon.transform
[Java] Annotation Type PropertyListener

java.lang.Object
  griffon.transform.PropertyListener

@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.FIELD, ElementType.TYPE})
@GroovyASTTransformationClass("org.codehaus.griffon.ast.PropertyListenerASTTransformation")
public @interface PropertyListener

Annotates a class.

This transformation provides a convenient way to register PropertyChangeListeners 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 pair of PropertyChangeListeners. One of them is a catch-all handler while the second is property specific.

 import groovy.beans.Bindable
 import java.beans.PropertyChangeListener

 class MyModel {
     @Bindable String name
     @Bindable String lastname

     def snoopAll = { evt -> ... }

     MyModel() {
         addPropertyChangeListener(snoopAll as PropertyChangeListener)
         addPropertyChangeListener('lastname', {
             controller.someAction(it)
         } as PropertyChangeListener)
     }
 }
 

Applying @PropertyListener to the previous snippet results in the following code

 import griffon.transform.PropertyListener
 import groovy.beans.Bindable

 @PropertyListener(snoopAll)
 class MyModel {
     @Bindable String name

     @Bindable
     @PropertyListener({controller.someAction(it)})
     String lastname

     def snoopAll = { evt -> ... }
 }
 
Any closures found as the annotation's value will be either transformed into inner classes that implement PropertyChangeListener (when the value is a closure defined in place) or be casted as a proxy of PropertyChangeListener (when the value is a property reference found in the same class).

List of closures are also supported.

Authors:
Andres Almiray
See Also:
org.codehaus.griffon.ast.PropertyListenerASTTransformation


Required Element Summary
java.lang.String value

   
Method Summary
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Element Detail

value

String value


 

Groovy Documentation