Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<h1>Quick Start</h1> <p>The following makes it simple to start a griffon project. </p> <img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e3RvY30&locale=en_GB&version=2" data-macro-name="toc"> <h2>Create a Griffon project</h2> <p>Once you have <a class="confluence-link" href="/display/GROOVY/Installing+Griffon" data-linked-resource-id="102105093" data-linked-resource-type="page" data-linked-resource-default-alias="Installing Griffon" data-base-url="http://docs.codehaus.org">installed</a> Griffon you can use the built-in target for creating new projects:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> griffon create-app </pre></td></tr></table> <p>The target will prompt you for the name of your project and create the project structure below:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> %PROJECT_HOME% + griffon-app + conf ---> location of configuration artifacts like builder configuration + keys ---> keys for code signing + webstart ---> webstart and applet config + controllers ---> location of controller classes + i18n ---> location of message bundles for i18n + lifecycle ---> location of lifecycle scripts + models ---> location of model classes + resources ---> location of non code resources (images, etc) + views ---> location of view classes + lib + scripts ---> scripts + src + main ---> optional; location for Groovy and Java source files (of types other than those in griffon-app/*) </pre></td></tr></table> <h2>Create an Application Model</h2> <p>Make sure you are in the root directory of your project (for argument sake "DemoConsole", a simple script evaluator) by typing</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> cd DemoConsole </pre></td></tr></table> <p>The "create-app" target created a Griffon MVC Triad for you in the models, views, and controllers directory named after the application. hence you already have a model class DemoConsoleModel in the models directory.</p> <p>The application model for the quick start is simple: the script to be evaluated and the results of the evaluation.</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="title=DemoConsoleModel.groovy" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9RGVtb0NvbnNvbGVNb2RlbC5ncm9vdnl9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>import groovy.beans.Bindable class DemoConsoleModel { String scriptSource @Bindable def scriptResult @Bindable boolean enabled = true }</pre></td></tr></table> <h2>Create the Controller Logic</h2> <p>The controller for our quick start app is simple: throw the contents of the script from the model at a groovy shell.</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="title=DemoConsoleController.groovy" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9RGVtb0NvbnNvbGVDb250cm9sbGVyLmdyb292eX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>import java.awt.event.ActionEvent class DemoConsoleController { GroovyShell shell = new GroovyShell() // these will be injected by Griffon def model def view def executeScript(ActionEvent evt = null) { model.enabled = false doOutside { def result try { result = shell.evaluate(model.scriptSource) } finally { edt { model.enabled = true model.scriptResult = result } } } } }</pre></td></tr></table> <p>The Griffon framework will inject references to the other portions of the MVC triad if fields named model, view, and controller are present in the model or controller. This allows us to access the view widgets and the model data if needed</p> <p>The executeScript method will be used in the view for the button action. Hence the ActionEvent parameter, and the default value so it can be called without an action event.</p> <p>Finally, the Griffon framework can be configured to inject portions of the builders it uses. By default, the Threading classes are injected into the controller, allowing the use of the <code>edt</code>, <code>doOutside</code> and <code>doLater</code> methods from the SwingBuilder.</p> <p>Also, the threading may look a bit obsessive. But good thread management is essential to a well functioning Swing application. </p> <h2>Add Content to the View</h2> <p>The view classes contain the visual components for your application.</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="title=DemoConsoleView.groovy" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9RGVtb0NvbnNvbGVWaWV3Lmdyb292eX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>application(title:'DemoConsole', pack:true, locationByPlatform:true) { panel(border:emptyBorder(6)) { borderLayout() scrollPane(constraints:CENTER) { textArea(text:bind(target:model, targetProperty:'scriptSource'), enabled: bind {model.enabled}, columns:40, rows:10) } hbox(constraints:SOUTH) { button("Execute", actionPerformed:controller.&executeScript, enabled: bind {model.enabled}) hstrut(5) label("Result:") hstrut(5) label(text:bind {model.scriptResult}) } } }</pre></td></tr></table> <p>The view script is a fairly straightforward SwingBuilder script. Griffon will execute these groovy scripts in context of it's UberBuilder (a composite of the SwingBuilder and whatever else is thrown in).</p> <h2>Run the Application</h2> <p>To start your Griffon app run the following target</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> griffon run-app </pre></td></tr></table> <p>This will run the application as a Java application. You can also use the <code>run-webstart</code> target to run the application from a WebStart/JNLP file.</p> <p>The run-app script implies the execution of the package script. The package script creates file artifacts suitable for a Java application, a WebStart application, and an Applet, with code signed by a self-signed certificate. All from the same source tree. By default they go in the 'target' directory.</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> ls target </pre></td></tr></table> <p>Try out the applet by bringing up the applet.html file in a browser.</p> <h1>What's Next</h1> <p>This is just the first pass at the framework. The sky's the limit!</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced