11. @Log
@groovy.util.logging.Log
class Person {
String name
void talk() {
log.info("$name is talking…")
}
}
def person = new Person(name: "Duke")
person.talk()
// Oct 7, 2010 10:36:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
// INFO: Duke is talking…
16. @Bindable
@groovy.beans.Bindable
class Book {
String title
}
def book = new Book()
book.addPropertyChangeListener({e ->
println "$e.propertyName $e.oldValue ->
$e.newValue"
} as java.beans.PropertyChangeListener)
book.title = "Foo” // prints "title Foo"
book.title = "Bar” // prints "title Foo Bar"
17. @Listener
@groovy.beans.Bindable
class Book {
@griffon.beans.Listener(snooper)
String title
private snooper = {e ->
println "$e.propertyName $e.oldValue ->
$e.newValue"
}
}
def book = new Book()
book.title = "Foo" // prints "title Foo"
book.title = "Bar" // prints "title Foo Bar"
18. @EventPublisher
@Singleton
@griffon.util.EventPublisher
class AccountManager {
void process(Account account) {
publishEvent("AccountProcessed", [account)]
}
}
def am = AccountManager.instance
am.addEventListener("AccountProcessed") { account ->
println "Processed account $account"
}
def acc = new Account()
AccountManager.instance.process(acc)
// prints "Processed account Account:1"
19. @Scaffold
class Book {
String title
}
@griffon.presentation.Scaffold
class BookBeanModel {}
def model = new BookBeanModel()
def book = new Book(title: "Foo")
model.value = book
assert book.title == model.title.value
model.value = null
assert !model.title.value
assert model.title