Part 1. Getting started
Our goal in part 1 is to get you up to speed on what Griffon offers to the desktop application development experience by diving directly into
code. Part 1 is all about hitting the ground running.
We’ll introduce you to Griffon by guiding you through building your first Griffon application: a simple multitabbed file viewer.
You’ll experience most of the tasks required to design, build, package, and deploy an application; and we’ll take a quick
look at the building blocks of the framework, its conventions, and the application’s life cycle.
Taking inspiration from mythology, a Griffon (or Griffin) is a mystical beast that’s half eagle, half lion. In antiquity,
the lion was considered the king of beasts, while the eagle held the same title for birds. Thus an amalgam of both creatures
results in the king of all creatures. The Griffon framework is an amalgam between the web world (thanks to its Grails heritage)
and the desktop world. Griffons were thought to guard treasures and riches; in our case, Griffon is the key to a productive
experience when writing desktop applications.
Let’s begin our journey by looking the Griffon directly in the eye.
Chapter 1. Welcome to the Griffon revolution
This chapter covers - What Griffon is all about
- Installing Griffon
- Building your first Griffon application
- Understanding how Griffon simplifies desktop development
Welcome to a revolution in how desktop applications are designed, developed, and maintained. You may be wondering, a revolution against what exactly? Let’s begin with how you pick the application’s source layout, or how you organize build time versus runtime dependencies. What about keeping the code clean? How do you deal with multithreading concerns? Can you extend an application’s capabilities with plugins? These are but a few of the most common obstacles that must be sorted out in order to get an application out the door. Many hurdles and obstacles lurk in your path, waiting their turn to make you slip that important deadline or drive you to frustration.
Griffon is a revolutionary solution that can make your job easier while bringing back the fun of being programmer. Griffon is a Model-View-Controller (MVC) based, convention-over-configuration, Groovy-powered desktop application development framework. Using Griffon to build your desktop applications will result in organized code and less of it. But why would you build a desktop application in the first place? There are times when being close to the metal pays off really well: for example, how would you access a local device like a scanner or a printer from a web page? Via some other domain-specific device, perhaps? This is a valid use case scenario in both financial and health industries. We believe that once you use Griffon, you’ll enjoy it as much as we do.
This chapter will get you started building Griffon applications. It lays out the core concepts and underlying designs behind the framework. You’ll start by getting your development environment set up and building your first Griffon application. You’ll build on your first application and create a simple tab-based editor with a menu and actions to open and save files. We’ll review some of the challenges with Java-based desktop development and see how Griffon approaches it. Along the way, we’ll discuss some of the core Griffon constructs, components, and philosophy.
Are you ready to become truly productive building applications for the desktop? Let’s begin!
1.1. Introducing Griffon
Griffon’s goal is to bring the simplicity and productivity of modern web application frameworks like Grails and Rails to desktop development. Griffon leverages years of experience and lessons learned by Grails, Groovy, Rails, Ruby, Java Desktop, and Java developers and their communities. Griffon has adopted many of those languages’ and frameworks’ best practices, including Model-View-Controller, convention-over-configuration, a modern dynamic language (Groovy), domain-specific languages (DSLs), and the builder pattern.
Web application development as we knew it suddenly changed in 2004, when a framework named Ruby on Rails (RoR; http://rubyonrails.org) was released in the wild. It showed that a dynamic language like Ruby could make you highly productive when teamed with a well-thought-out set of conventions. Add the convention-over-configuration paradigm and the viral reception from disheartened Java developers longing for something better than JEE, and RoR suddenly stepped into the spotlight.
A year later, another web framework appeared: its name was Grails, and Groovy was its game. It followed RoR’s ideals, but its founders decided to base the framework on well-known Java technologies such as the Spring framework, Hibernate, SiteMesh, and Quartz. Grails included a default database and a full stack to develop JEE applications without the hassle that comes with a regular JEE application.
Grails grew in popularity and a community was created around it, to the point that it’s now the most successful and biggest project at the Codehaus (www.codehaus.org), an organization that hosts open source projects; that’s where Grails was born and Griffon is hosted.
Grails is a convention-over-configuration, MVC-based, Groovy-powered web application development framework. Does that definition sound familiar? Just exchange desktop for web, and you get Griffon.
Both frameworks share a lot of traits, and it’s no surprise that Griffon’s MVC design and plugin facility were based on those provided by Grails, or that the command-line tools and scripts found in one framework can also be found in the other. The decision to use Grails as the foundation of Griffon empowers developers to switch between web and desktop development: the knowledge gathered in one environment can easily be translated to the other.
Note
If you’re in a hurry to understand how to use plugins, take a quick peek at chapter 11.
Let’s get started by setting up the development environment and building your first simple Griffon application.
1.1.1. Setting up your development environment
In order to get started with Griffon, you’ll need the following three items in your toolbox: a working JDK installation, a binary distribution of the Griffon framework, and your favorite text editor or IDE.
First, make sure you have the JDK installed. The version should be 1.6 or later: to check, type javac -version from your command prompt.
Next, download the latest IzPack-based Griffon distribution from http://griffon.codehaus.org/download. The file link looks like this one:
griffon-0.9.5-installer.jar
Note that the version number may differ. The important thing is that you pick the IzPack link. IzPack provides a cross-platform installer that should take care of installing the software and configuring the environment variables for you. It will even unpack the source distribution of the framework, where you can find sample applications that are useful for learning cool tricks. You can run the installer by locating the file and double-clicking it. Alternatively, you can run the following command in a console prompt:
java –jar griffon-0.9.5-installer.jar
If for some reason the installer doesn’t work for you, or if you’d rather configure everything by yourself, download the latest Griffon binary distribution from the same page in either zip or tar.gz format. Uncompress the downloaded file into a folder of your choosing (preferably one whose name doesn’t contain whitespace characters). A standard Griffon distribution contains all the files and tools you need ...