Platinum Partner
java

Getting Started with Swing MVC Development on Griffon

Griffon is to the desktop what Grails is to the web. (And its 0.0 release was today.) That's more or less all that needs to be said about it, if you're familiar with Grails. If you're not, Griffon is an MVC framework for Swing applications, using "convention over configuration" for its source structure and Groovy as its language. It's new and fun, in the same way that Grails is.

Here's some recent (colorfully titled) reading, i.e., all of it published in the last 24 hours or so:

So much being similar to Grails, creating tools for Griffon is as simple as tweaking the tools for Grails. Here's the NetBeans project template that sets up the source structure by calling "griffon create-app":

Complete the wizard and here's your application, looking similar to Grails, of course:

Let's look at those three files. First, an empty model:

import groovy.beans.Bindable

class HelloGriffonModel {

}

Then, a controller:

class HelloGriffonController {

// these will be injected by Griffon
def model
def view

}

Finally, the view:

application(title:'HelloGriffon',  pack:true, locationByPlatform:true) {
// add content here
label("Content Goes Here") // deleteme
}

Run it and you see this:

Now, let's do something with the model:

import groovy.beans.Bindable

class HelloGriffonModel {

@Bindable def greeting = "Hello world"

}

Then, we'll change the view to show the above simple message in our label:

application(title:'HelloGriffon',  pack:true, locationByPlatform:true) {
// add content here
label(text:bind {model.greeting})
}


That's all. Just run it and you'll have your static message replaced by the text set in the model. Next, see the Griffon Quick Start for details on creating your own initial application based on the above. The NetBeans Groovy Editor comes in handy:

Three cool samples are part of the Griffon distro, in the "samples" folder. I simply opened them in the IDE (i.e., thanks to "convention over configuration", NetBeans IDE knows exactly what a Griffon application consists of, so there's no import process, no NetBeans project metadata is added to the source structure, one simply opens it via the tweaked Grails modules for NetBeans IDE):

For example, the "GrailsSnoop" sample lets you browse the Grails documentation in a Swing application:

However, in addition to a Swing application, thanks to the "griffon run-app" (i.e., in my case, I simply choose "Run" inside NetBeans IDE) you also have a JNLP application, as well as an applet:

That's not bad! Here's wishing this new framework all the best! I'm also hoping that there will be many more Grails-like frameworks coming out. The Grails approach really gives one the very best of all worlds in hiding the complexities beneath DSLs, Groovy as your language (with all the advantages that that brings, such as not needing to throw out all your Java books), MVC as the structure and the possibility to use different widget sets (in fact, one of the samples uses JIDE, specifically, com.jidesoft.swing.TristateCheckBox).

And what about the tools I showed above? I.e., the integration with NetBeans IDE? Once the NetBeans Grails support has been officialy released as part of 6.5, i.e., all those tools will then be stable, I will fork them and provide a new set of plugins for Griffon.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}