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
<p>The groovy-swt binding framework is inspired by the swing binding framework, but is based on the <a href="http://wiki.eclipse.org/index.php/JFace_Data_Binding">jface databinding</a>. It is not meant to be a replacement of the jface databinding, and does not include all the features of the jface databinding. Think of it as an easy shortcut covering most cases, so you may still have to revert to the jface databinding framework.</p> <h2>An Appetizer</h2> <p>Here is just a simple example from the included <a href="http://svn.groovy.codehaus.org/browse/~raw,r=16237/groovy/trunk/groovy/modules/groovy-swt/src/examples/groovy/jface/examples/databinding/Simple01withBind.groovy">examples</a>:</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> person = new Person01(firstName:'John', lastName:'Doo', gender:'Male', age:12, married:true) ..... label('Firstname:') text(text:bind(model:person, modelProperty:'firstName')) label('Age:') text(text:bind(model:person, modelProperty:'age')) label('Married:') button(style: 'CHECK', selection:bind(model:person, modelProperty:'married') ) </pre></td></tr></table> <p>This will give you automatic two-way binding: <br class="atl-forced-newline" /></p> <ul> <li>if you change the model (person) it will automatically be reflected in the GUI(the text and button widgets)</li> <li>if the user change the text widgets it will automatically be updated in the model. <br class="atl-forced-newline" /> <br class="atl-forced-newline" /></li> </ul> <h2>The bind object</h2> <p> Properties:</p> <ul> <li>model: the model object you are binding to.</li> <li>modelProperty: the model property you are binding to.</li> <li>childrenProperty:Used in TreeViewers to specify the children property of the model object.</li> <li>target: the widget you are binding to.</li> <li>targetProperty: the widget property you are binding to.</li> <li>model2target: a <a href="http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/core/databinding/UpdateValueStrategy.html">UpdateValueStrategy</a>allowing you to specify validators, converter, etc.</li> <li>target2model: a <a href="http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/core/databinding/UpdateValueStrategy.html">UpdateValueStrategy</a>allowing you to specify validators, converter, etc.</li> <li>closure: a simple way to create ComputedValues.</li> </ul> <h3>Builder styles</h3> <p>There are (at least) two ways you can write your bindings using the groovy-swt builder:</p> <p>The basic using a bind node:</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> text('', id:firstNameTextWidget) bind(target: firstNameTextWidget, targetProperty: 'text', model: person, modelProperty: 'firstName') </pre></td></tr></table> <p>or the shortcut to avoid all the 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> text(text:bind(model:person, modelProperty:'firstName')) </pre></td></tr></table> <p>If you find that the binding functionality provided in groovy-swt is not enough or doesn't fit your needs you can use create your own IObservable using the jface databinding framwork directly and then provide that as the model object, like:</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> def observable = BeansObservables.observeValue(person, "firstName") text(text:bind(model:observable) </pre></td></tr></table> <h2>Viewers</h2> <p>If you want to bind the data to jface viewers (lists, combos, tables, etc) you should bind the input attribute like:</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> def people = new WritableList(Realm.default) people.add(new Person02(name:"Wile E. Coyote", city:"Tucson")) people.add(new Person02(name:"Road Runner", city:"Lost Horse")) ..... list() { listViewer(input: bind(model:viewModel.people, modelProperty:'name')) } </pre></td></tr></table> <p><br class="atl-forced-newline" /> <br class="atl-forced-newline" /></p> <p>If you want to the viewer to reflect changes to the list it needs to be a list that send notification if the list changes, so use the jface-databinding class WritableList. Groovy-swt accepts ordinary groovy lists, but then it will be static data and the viewer will not reflect changes to the list:</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> class ViewModel { def cities = ['NY', 'LA', 'NB'] } .... combo(style:'READ_ONLY') { comboViewer(input: bind(model:viewModel, modelProperty:'cities')) } </pre></td></tr></table> <p><br class="atl-forced-newline" /> <br class="atl-forced-newline" /></p> <h4>Master-Detail</h4> <p>If you use a jface viewer as a model if will create a master-detail observable of the selected item: <br class="atl-forced-newline" /></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> list() { listViewer(id:'v1', input: bind(people, modelProperty:'name')) } // doing it manually: text(text: bind(BeansObservables.observeDetailValue(ViewerProperties.singleSelection().observe(v1), 'city', String.class))) // shortcut text(text: bind(model: v1, modelProperty:'city')) </pre></td></tr></table> <p><br class="atl-forced-newline" /> <br class="atl-forced-newline" /></p> <h2>ComputedValues</h2> <p>To make simple one-way binding (possibly with some kind of calculations) you can use a bind closure:</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> text(text:bind {viewModel.text }) </pre></td></tr></table> <p>Groovy-swt will (like the Swing builder) automatically find out which properties are used in the closure and create a ComputedValue binding for the closure with bindings to the properties used in the closure.</p> <p>Or with a more complex example:</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> text(text:bind(model:viewModel, modelProperty:'text')) // NOTE: Bind can not find the properties to bind to if they are hidden inside a GString. label(text:bind {"You have written "+viewModel.text?.size()+ " characters"}) label('Characters left: ') label(text:bind{(50-viewModel.text?.size()).toString()}) </pre></td></tr></table> <p>You can also use the model2target.converter to create a simple calculated value:</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> button('Remove', enabled: bind(model: peopleViewer, modelProperty:'name', 'model2target.converter': {t1.selectionCount>0}) </pre></td></tr></table> <h2> </h2> <h3>Threads</h3> <p><br class="atl-forced-newline" /></p> <p>TODO: Realms, updating models in the realm, </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