Griffon Presentation


Published on

A presentation for the Vancouver Island Java User's Group showcasing how Groovy and the Griffon application framework can ease the pain of coding Swing applications.

Published in: Technology, Education
1 Comment
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • developers on Griffon are contributors to Groovy and have provided handy AST transformations
  • What makes it “hard” to program Swing? VERBOSITY, boilerplate
  • What things does Groovy do to help? Builder pattern is great at building tree structures Helpful abstractions one line initialization, no need to call get/set
  • What does Griffon add to the mix to make it even easier? no need to remember which builder you are calling; conflicts can be resolved using namespaces standardization/delegation of methods: size(), getAt(), putAt(), iterator()
  • After this slide, demo CSSBuilder and some of the Swingpad samples Swingpad can be used to prototype UI elements in isolation, Mockfor and Stubfor can be used to mock dependencies
  • After this slide, show the files in IDE and explain they’re nothing more than properties files consumed by ConfigSlurper
  • show L&F change? build a new app from scratch, change from label to button, run, change L&F and rerun
  • Getting your application built and published is important - you do want people to use these things after all Point out that demos are all .app files
  • No framework would be complete without testing support Show FEST test after this slide
  • Polyglot programming made easy
  • Wrappers for SwingUtilities methods Demo Binding example
  • SwingWorker DSL Demo EDT example and Animation example
  • Here’s how you work with it at the lowest level. Demo loading up the application in a console
  • Just out of interest, the demo application created to go along with this talk comes in pretty lean. Lifecycle and Integration Tests are defaults And all of these LOC measures include comments, to be fixed in a release soon
  • Griffon Presentation

    1. 1. Griffon <ul><li>“Griffon is a Grails like application framework for developing desktop applications in Groovy.” </li></ul>
    2. 2. What is Griffon? <ul><li>framework for developing Swing apps </li></ul><ul><li>Groovy based, Grails inspired </li></ul><ul><li>extensible by plugins </li></ul><ul><li>MVC </li></ul><ul><li>convention over configuration </li></ul><ul><li>aims to make build Swing apps easy! </li></ul>
    3. 3. State of Swing <ul><li>very verbose to get it right </li></ul>public void actionPerformed(ActionEvent e) {      (new Thread(new Runnable() {          public void run() {              final String result = longRunningOperation();              SwingUtilities.invokeLater(new Runnable() {                  public void run() {                      label.setText(result);                  }              });          }      }).start(); } final JLabel label = ... ; class MeaningOfLifeFinder extends SwingWorker<String, Object> { @Override public String doInBackground() { return findTheMeaningOfLife(); } @Override protected void done() { try { label.setText(get()); } catch (Exception ignore) { } } } (new MeaningOfLifeFinder()).execute(); <ul><li>SwingWorker helps with the pattern </li></ul>
    4. 4. Groovy helps a lot <ul><li>SwingBuilder DSL for fluent syntax </li></ul><ul><li>shortened forms and simplified configuration </li></ul><ul><ul><li>Java: JPanel panel = new JPanel(); new BoxLayout(panel, BoxLayout.X_AXIS) </li></ul></ul><ul><ul><li>Groovy: panel { boxLayout() } </li></ul></ul><ul><li>map coercion VS constructors </li></ul><ul><li>huge reduction in boilerplate </li></ul><ul><li>simple Binding </li></ul>
    5. 5. Griffon helps even more <ul><li>CompositeBuilder: combines numerous builders into one common dsl </li></ul><ul><li>IGriffonApplication: provides a common infrastructure </li></ul><ul><li>meta-enhancement: additional methods added to Swing components at run-time </li></ul><ul><li>makes publishing and launching easy </li></ul>
    6. 6. Builders <ul><li>SwingXBuilder - Swing component extensions </li></ul><ul><li>FxBuilder - JavaFX script support </li></ul><ul><li>JideBuilder - Swing component extensions </li></ul><ul><li>SwingXtrasBuilder - aggregate of 3 smaller Swing component extensions(I2fprod, BalloonTip, xswingx) </li></ul><ul><li>CSSBuilder - Swing Clarity: adds cssClass property to all Swing nodes </li></ul><ul><li>TridentBuilder - animation library </li></ul><ul><li>GfxBuilder - Java 2D(without pulling your hair out) </li></ul>
    7. 7. App Configuration <ul><li>Your A, B, C’s </li></ul><ul><ul><li>Application.groovy- title, root MVC group to initialize on startup, all MVC groups registered in the app </li></ul></ul><ul><ul><li>Builder.groovy - CompositeBuilder configuration </li></ul></ul><ul><ul><li>Config.groovy - logging, dev/test/prod environments, additional build script or lifecycle event configuration </li></ul></ul>
    8. 8. App Lifecycle <ul><li>Initialize - before any Swing code is realized; used for L&F and setup </li></ul><ul><li>Startup - after startup MVC groups are initialized </li></ul><ul><li>Ready - all events sent to EDT queue have been processed </li></ul><ul><li>Shutdown - opportunity to free resources before exit </li></ul><ul><li>Stop - Applet specific </li></ul>
    9. 9. Distribution and Installation <ul><li>stand-alone, webstart and applet support </li></ul><ul><li>create launchers for Windows(.exe), Linux(shell script), Mac(.app) and as executable jar </li></ul><ul><li>create installers using IzPack, RPM and DMG </li></ul><ul><li>‘big jar’ support for those lucky people in the US who can use the Java Store </li></ul><ul><li>can create all installers and launchers in one step </li></ul>
    10. 10. Testing and Analysis <ul><li>FEST - framework for Swing integration testing; equivalent of Selenium for Web testing </li></ul><ul><li>EasyB - scenario based testing </li></ul><ul><li>Cobertura - code coverage metrics </li></ul><ul><li>JDepend - static analysis </li></ul>
    11. 11. Language support <ul><li>Scala - plugin available </li></ul><ul><li>Clojure - plugin available </li></ul><ul><li>Java - if you REALLY want :) </li></ul>
    12. 12. The EDT in Groovy <ul><li>doOutside{ </li></ul><ul><li>//long running operations in a new thread </li></ul><ul><li>edt { </li></ul><ul><ul><li>//jump back to the EDT if needed </li></ul></ul><ul><li>} </li></ul><ul><li>doLater{ </li></ul><ul><ul><li>//update the UI when we’re done </li></ul></ul><ul><li>} </li></ul><ul><li>} </li></ul>
    13. 13. EDT With SwingWorker in Griffon in Griffon <ul><li>jxwithWorker {onInit { </li></ul><ul><li>//setup } work { </li></ul><ul><ul><li>//do long running work and publish intermediate results </li></ul></ul><ul><li>publish(...) } </li></ul><ul><ul><li>onUpdate { </li></ul></ul><ul><ul><li>//respond to intermediate results } onDone { </li></ul></ul><ul><li>//update UI with final results }} </li></ul><ul><li>//update UI with final results }} </li></ul><ul><ul><li>//update UI with final results }} </li></ul></ul><ul><li>//update UI with final results }} </li></ul><ul><ul><li>//update UI with final results }} </li></ul></ul><ul><li>//update UI with final results }} </li></ul>
    14. 14. How to get Griffon? <ul><li>download the izpack installer </li></ul><ul><li>macports </li></ul><ul><li>install from source - set $GRIFFON_HOME and put $GRIFFON_HOME/bin in your path, there’s an ant target to install </li></ul><ul><li>tonite’s demo was 0.2-SNAPSHOT built from source </li></ul>
    15. 15. How to use Griffon? <ul><li>On the command line </li></ul><ul><ul><li>create/run/test Applications </li></ul></ul><ul><ul><li>create MVC groups or their individual components </li></ul></ul><ul><ul><li>create tests </li></ul></ul><ul><ul><li>install/uninstall plugins </li></ul></ul><ul><ul><li>create your own plugins </li></ul></ul><ul><li>run a shell/console with your Application on the classpath </li></ul><ul><li>... </li></ul>
    16. 16. Tool support <ul><li>Netbeans - Geertjan Wielenga crafted an alpha version plugin for Java One this year </li></ul><ul><li>Intellij - Maia (version 9, in EAP now) parallels existing Grails support </li></ul><ul><li>Eclipse - Groovy plugin, no specific support for Griffon; yet </li></ul><ul><li>Griffon in Action has instructions for each of these IDE’s without plugins, based on ant </li></ul>
    17. 17. IntelliJ Maia Closeup Project view showing libraries/plugins Griffon MVC plugin view
    18. 18. What’s to come? <ul><li>Spring plugin </li></ul><ul><li>Maven </li></ul><ul><li>Gradle </li></ul><ul><li>Grails plugin ports </li></ul><ul><li>Griffon In Action from Manning Books </li></ul>
    19. 19. How much code does it take? +----------------------+-------+-------+ | Name | Files | LOC | +----------------------+-------+-------+ | Controllers | 4 | 112 | | Models | 4 | 26 | | Views | 4 | 122 | | Lifecycle | 5 | 76 | | Integration Tests | 1 | 4 | +----------------------+-------+-------+ | Totals | 18 | 340 | +----------------------+-------+-------+
    20. 20. Questions <ul><li>??? </li></ul>