Grinding Griffon: The Hit

If Griffon delivers on the promise of rapid desktop development, the desktop will see a renewed focus. Griffon is relatively speaking a new project and currently Griffon needs a lot of documentation, tutorials, and use cases which means this is a perfect opportunity for Groovyist and enthusiasts to participate in the community.

Griffon views are created using UI builders. Groovy has a nice set of meta-programming features and the Groovy builder pattern to commonly used to create Domain Specific Languages. The UI builder used by Griffon is generic UberBuilder. Griffon 0.1.1 also uses SwingXBuilder and can theoretically work with other builders such as JideBuilder and FlamingoBuilder.

Lets enhance the default view created in the previous post with something a bit more interesting and interactive. Lets create a view with two buttons, and when the buttons are pressed a corresponding action should be executed. To get started, lets enhance the view to something like the following.

application(title:'gouda',
  pack:true,
  locationByPlatform:true,
) {
    panel(border:emptyBorder(6)) {
        borderLayout()
        hbox(constraints:SOUTH) {
            button("Ok", actionPerformed:controller.&okAction)
            button("Cancel", actionPerformed:controller.&cancelAction)
        }
    }
}

Griffon views are declarative. Notice how you add components to containers. You don’t explicitly add the button to horizontal box layout, but you just declare the the button method to create and add a button.

To declare a button we pass a string used for the label of the button and an action event handler to process the button pressed action. The action event handler is defined in the controller for your MVC group. Open the correct controller under the griffon-app\controllers directory. Adding the doAction and cancelAction methods to support the button press events, the controller looks like the following.

import java.awt.event.ActionEvent</pre>
class GoudaController {
    // these will be injected by Griffon
    def model
    def view

    void mvcGroupInit(Map args) {
        // this method is called after model and view are injected
    }

    def okAction(ActionEvent evt = null) {
        println "Okay Button Pushed!!"
    }

    def cancelAction(ActionEvent evt = null) {
        println "Cancel Button Pushed!!"
    }
}

Griffon seems very promising, it is lacking a strong set of documentation and tutorials but it has a strong legion of evangelists and hackers working on that. That said, I am sure this is enough to get you started and get you going with Griffon.