JavaOne 2009 BOF-5189 Griffon In Depth

download JavaOne 2009 BOF-5189 Griffon In Depth

If you can't read please download the document

description

The Griffon BOF from the 2009 JavaOne conference.

Transcript of JavaOne 2009 BOF-5189 Griffon In Depth

  • 1. Griffon in Depth BOF-5189 Danno Ferrin Intelligent Software Solutions, Inc. James Williams Code Herd, LLC Speaker logo centered below photo

2. What is Griffon? 3. What is Griffon? 4. file:///C:/Users/danno.ferrin/Pictures/Griffons/Griffon%20the%20Band.jpg What is Griffon? 5. What is Griffon? 6. What is Griffon? 7. What is Griffon? 8. What is Griffon? 9. What is Griffon? 10. What is Griffon?

    • Mythological Creature
    • Part Lion
    • Part Eagle
    • Sharp Talons
    • A Magical Beast http://www.d20srd.org/srd/monsters/griffon.htm

11. What is Griffon?

    • Mythological Creature
    • Part Lion
    • Part Eagle
    • Sharp Talons
    • A Magical Beast http://www.d20srd.org/srd/monsters/griffon.htm
    • Software Framework
    • Based on Grails
    • For Rich Internet Applications
    • Runs on the JVM
    • Written with Groovy http://griffon.codehaus.org/

12. The Rails Tenets

    • Convention Over Configuration
    • Don't Repeat Yourself
    • Fat Model/Skinny Controller
    • REST Interfaces
    • Write Good Tests
    • Automate Tasks
  • http://wiki.rubyonrails.org/getting-started/overview/tenets

13. The Rails Tenets

    • Convention Over Configuration
    • Don't Repeat Yourself
    • Fat Model/Skinny Controller
    • RIAs have a different nature from Web Apps
    • REST Interfaces
    • RIAs are not Web Pages
    • Write Good Tests
    • Automate Tasks
  • http://wiki.rubyonrails.org/getting-started/overview/tenets

14. The Rails Tenets

    • Convention Over Configuration - Yes!
    • Don't Repeat Yourself - Yes!
    • Fat Model/Skinny Controller
    • RIAs have a different nature from Web Apps
    • REST Interfaces
    • RIAs are not Web Pages
    • Write Good Tests - Yes!
    • Automate Tasks - Yes!
  • http://wiki.rubyonrails.org/getting-started/overview/tenets

15. The Griffon Tenets

    • Convention Over Configuration
    • Don't Repeat Yourself
    • Pervasive MVC
    • Its not just for Web Applications!
    • Write Good Tests
    • Automate Tasks

16. Agenda

    • Convention Over Configuration
    • File Layout
    • How an App is Packaged
    • Runtime Lifecycle
    • Don't Repeat Yourself
    • Dynamic Language Features
    • Pervasive MVC
    • MVC Groups
    • Write Good Tests
    • Testing Plugins
    • Automate Tasks
    • Scripting
    • More Plugins
    • Cool Demos

17. Convention over configuration 18. Convention Over Configuration

    • Java Desktop Application Conventions are MIA
    • Very few official examples
    • No Blueprints (Like Java EE Blueprints)
    • We have to create our own
    • Following Grails Patterns
    • Source Files Segregated by Role
  • Standardize App Lifecycle (like JSR-296)
  • Automated Packaging (App, WebStart , Applet)

19. File Layout

  • Source code in
    • griffon-app
      • models , views , controllers
    • src/main
  • Runtime Assets
    • griffon-app
      • i18n , resources
  • Runtime Jars
    • lib

20. How an App is Packaged

    • Results go into /staging
    • Changed in griffon-app/config/Config.groovy via the griffon.jars.destDirproperty
      • i.e. you could target a dir in your grails app
    • What goes in the Source Jar?
    • Compiled Groovy/Java files
      • src/main/**and griffon-app/*/**
        • Some explicit exceptions ( griffon-app/conf/Config , assets)
    • Assets in griffon-app/i18n/** and griffon-app/resources/**

21. How an App is Packaged

    • Results include:
    • The jar from source code
    • The Groovy jar and griffon-rt jar
    • Files from griffon-app/conf/webstart
      • ant search and replace is done on jnlp and html files
    • Files in /lib(but not sub-directories)
    • Pack200 variants of all result jars
    • Plugins may add and alter stuff via Eventing
    • Jars, DLLs, html, etc.

22. Runtime Lifecycle Scripts

    • Lifecycle Scripts are in griffon-app/lifecycle
    • Lifecycle Events modeled after JSR-296
    • Init called - before anything griffon setup
    • Application.groovy Loaded
    • Builder.groovy loaded - SwingBuilder and such
    • Events.groovy loaded and linked (non-lifecycle events)
    • Startup MVC Groups instantiated

23. Runtime Lifecycle Scripts Continued

    • Startup called - after initial config
    • The first app frame is made visible
    • Ready called - called after the EDT calms down
    • ... App Runs ...
    • Shutdown called - manually or automatically
    • Auto-shutdown can be disabled in Application.groovy

24. Dont Repeat Yourself 25. Dont Repeat Yourself

    • How? Use a Dynamic Language!
    • With Closures/Blocks
    • With terse property syntax myJTextArea.text = "Fires Property Change"
    • With terse eventing syntax button.actionPerformed = {println 'hi'}
    • With Rich Annotation Support @Bindable String aBoundProperty
    • Most of this impacts the View Layer
    • See JavaOne 2008 TS-5098 - Building Rich Applicaitons with Groovy's SwingBuilder

26. Pervasive MVC 27. MVC and Swing

  • The MVC Pattern is Great
    • But Swing Provides a Low Effort to Reward Ratio
  • Lower the Effort
    • Language Level Support for Data Binding
    • Framework Level Support for MVC Triads
  • Increase the Reward
    • Reusability ofTriads

28. MVC Groups Pervasive Reuse

  • How many MVC Groups here?

29. MVC Groups Pervasive Reuse

  • How many MVC Groups here?
  • Three Types
    • Greet The main Application
    • UserPane The user details
    • TimelinePane The tweets
  • Six Instances
    • One Greet (the frame)
    • Two UserPanes (on each @ tab)
    • Three TimelinePanes (one per tab)

30. MVC Groups How to use (Build time)

  • Call create-mvcscript at build time
    • Optional argument is the MVC type
      • Will prompt if arg not provided
      • Can be package qualified, but package is stripped from mvc type name.
      • com.example.Foohas mvc type of Foo
    • Adds mvcGroupentry into Application.groovy
    • Generates stub files in models / views / controllers
      • Will be in package if name had a package
        • com.example.FooModel com.example.FooContoller com.example.FooView

31. MVC Groups Portion Instances

  • Portions are Classes or Groovy Scripts
    • After instantiation and injection mvcGroupInit(Map)is called if present
      • Map has named args from createMVCGroup()call
  • Views are Groovy Scripts
    • No Mandatory Class Declarations
    • Looks Like Free-Form Code
    • Compiles to .classfiles
    • Views may be classes in 0.2.x

32. MVC Groups Injection

  • MVC Portions have values injected if available
    • Scripts have values added to binding
    • Classes data is injected into properties
    • model, view, controller, builder
  • Methods are also injected via Groovy MetaClass
    • createMVCGroup()is always injected (curried with current app as first parameter)
    • On a per-portion basis in Builder.groovy
      • edt , doLater , doOutsidefrom SwingBuilder

33. MVC Groups Creating New Groups

  • Each portion is a script or a class
    • Classes can have mvcGroupInit()method for post-injection initialization
  • Call createMVCGroup()at runtime
    • Mandatory 1st arg: mvc type name
    • Optional 2nd arg: tracking name
      • Useful when you use a group multiple times
    • Optional Named Params: passed into mvcGroupInitor in script binding
    • Returns a List of the instances of portions

34. MVC Groups createMVCGroup Flow

  • Meta Class Injections of portion classes
  • Instantiate Portions via no-args constructor
  • Inject instance values
    • Portions named controller listen to app events
  • Call mvcGroupInit or execute script
    • Scripts named view are executed in the EDT
  • Everything portion is done in a fixed order
    • Griffon 0.1 order is model controller view
    • Griffon 0.2 order is the order of declaration

35. MVC Groups Coming in 0.2

  • Ability to add arbitrary portions
    • For example, actions portion for Action objects
  • User Controlled Initialization order
    • The order you declare is the init order
    • Either calls mvcGroupInitor executes the script
  • Named args to createMVCGroup()are injected into MVCGroup portions
  • Add support for mvcGroupPostInit Safe harbor warning: these are forward looking statements.May change at any time without notice.Offer void in Connecticut and Puerto Rico or where prohibited by law. Offer applies with enrollment in triple advantage.Do not taunt happy fun ball.

36. Write Good tests 37. Built-in Testing

  • Griffon has built in support for testing
    • create-mvcscript creates a test file in test/integration
      • Uses GroovyTestCase
      • See JavaOne 2008 TS-5101 Boosting your Testing Productivity with Groovy
      • Griffon doesnt write the test for you
    • test-appscript executes the tests for you
      • Bootstraps the application for you
      • Evereything up to instantiating MVC Groups

38. Testing Plugins

  • Sometimes apps need more involved testing
    • fest
      • Fluent interface for functional swing testing
    • easyb
      • Behavioral Driven Development
    • code-coverage Cobertura
      • Line Coverage Metrics
    • jdepend
      • Code quality metrics
    • codenarc
      • Static code analysis

39. Automate Tasks 40. Scripts and Events

  • Griffon runs most of its tasks from gant scripts
    • Script file format is a Groovy Script
    • Ant library is accessible via gant
  • Griffon fires events as script steps happen
    • Event Listeners are Closures
      • event = { do stuff }
  • Users can add scripts in scripts directory
    • Events are added via an _Events.groovyscript

41. Plugins

  • Griffon supports plugins a lot like Grails
  • This is how most periphery functionality is added
    • New Widget Libraries
    • Packaging Options
    • Testing Tools
  • list-pluginsscript lists the plugins
  • install-pluginscript adds the plugins
  • Plugins are stored outside of project

42. Builder Plugins

  • Plugins for common widget sets and APIs
    • swingx-builder
    • jide-builder
    • swingxtras-builder
    • flamingo-builder
    • macwidgets-builder
    • tray-builder
  • Adds the needed Builder.groovy config
  • Adds the library jars as part of packaging

43. Other Plugins

  • Plugins can add just about any periphery functionality
    • installer
      • Adds scripts to create a izPack installer for your app
    • scala
      • Adds scala interop with Griffon and Groovy
    • splash
      • Adds a splash screen durring init
    • wizard
      • Adds a wizard API

44. Twittersphere

  • Griffon Application integrating Nasa World Wind
  • http://github.com/griffon/twittersphere/tree/master

45. Questions and Answers 46. Danno Ferrin @shemnon James Williams @ecspike