Griffon 0.9 sneak peek: runtime enhancements - No Fluff Just Stuff

Griffon 0.9 sneak peek: runtime enhancements

Posted by: Andres Almiray on July 12, 2010

Today's post on Griffon 0.9 updates is related to runtime enhancements, previous posts were all about build time. Be warned that there are some breaking changes here too, all for the best of course.

1. Addon enhancements

The first update has to do with Addons. Contributing new nodes, methods and properties to builders is fairly simple, the following line is added to the plugin's install script by the create-addon command:

root.'MyGriffonAddon'.addon = true

Given that addons are a natural extension to builders, and that builders can contribute methods and properties to other MVC members (like controllers for example), it follows that addons should do the same, but the syntax was not that pretty. Assuming MyGriffonAddon contributes 2 factories (foo and bar) plus an additional method (hello), this is how you would added them to a controller:

root.'MyGriffonAddon'.controller = ['foo', 'bar', 'hello']

In other words, you have to enumerate all entries that should be contributed :-(
This is the problem addressed by this enhancement. Now you only need to write '*' to mixin all addon contributions to a particular MVC member. The previous code can be rewritten as:

root.'MyGriffonAddon'.controller = '*'

You might be thinking, what if all methods should be contributed only? This does the trick

root.'MyGriffonAddon'.controller = '*:methods'

The whole list of these new contribution qualifiers follows:
  • * - all nodes, methods and properties
  • *:factories - nodes only
  • *:methods - methods only
  • *:props - properties only

2. UIThread method shortcuts in scripts

Griffon 0.3 introduced UIThreadHelper, a handy abstraction for executing code inside/outside the UI thread, designed as a singleton. This helper class provides the following methods
  • isUIThread() - true if the current thread is identified as the UI thread for the current toolkit. Equivalent to SwingUtilities.isEventDispatchThread() when running Swing
  • executeSync() - execute code synchronously inside the UI thread. Equivalent to SwingBuilder.edt() when running Swing
  • executeAsync() - execute code asynchronously inside the UI thread. Equivalent to SwingBuilder.doLater() when running Swing
  • executeOutside() - execute code outside of the UI thread. Equivalent to SwingBuilder.doOutside() when running Swing
These methods can be called like this

UIThreadHelper.instance.executeSync { model.enabled = true }

Griffon 0.3.1 added shortcut versions (execSync, execAsync, execOutside, execFuture) to all MVC members and the application instance, thus allowing the following snippets to work

This update allows the shortcut methods to be used inside life cycle scripts, thus pushing down the need to call UIThreadHelper.instance directly.


3. Application phase

There's a new enum (griffon.core.ApplicationPhase) that can be used to know in which phase the application is currently is. Its values are INITIALIZE, STARTUP, READY, MAIN and SHUTDOWN; you can query it by calling getPahse() on the application instance.

4. Application locale

All applications now have a bound java.util.Locale property. This means you can register PropertyChangeListeners on an application and be notified whenever their locale changes value.

5. Swing enhancements

While all previous updates are applied to all applications, the following one is Swing specific (remember that Griffon can support more toolkits other than Swing via plugins).

5.1 Shortcut for registering PropertyChangeListeners

Registering PropertyChangeListeners just got a bit easier, thanks to the new @Listener AST transformation. Before this enhancement you had to write the following code

Basically you were forced to register the listeners inside a constructor, you also had to cast any closures to an appropriate value. Well, not anymore. Here's the same behavior using @Listener instead

A List of property closures or inline closures is also supported as value for the @Listener annotation.

5.2 Window management

There's a new set of helper classes, WindowManager and WindowDisplayHandler that let you change the default behavior for showing and hiding windows. This new feature receives a boost from the upcoming Effects plugin. For example this is all that you have to do for enabling a dropIn/dropOut effect when showing/hiding windows

1. install the Effects plugin
2. Create a class that implements WindowDisplayHandler with the following contents

3. Register an instance of this handler with the application. It can be done on a life cycle script (like Initialize or Startup) or by using an application event handler (griffon-app/conf/Events.groovy)

WindowManager is now responsible for holding a reference to all application windows that are created using the application node. This used to be the job of app.appFrames which is no longer available, developers should rely on app.windowManager.windows from now one. Windoes that were not created using the application node can still be handled by WindowManager, just call its attach() method with the window instance that should be handled.
Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »