Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

The groovy-swt binding framework is inspired by the swing binding framework, but is based on the jface databinding. 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.

An Appetizer

Here is just a simple example from the included examples:

This will give you automatic two-way binding:

  • if you change the model (person) it will automatically be reflected in the GUI(the text and button widgets)
  • if the user change the text widgets it will automatically be updated in the model.

The bind object

 Properties:

  • model: the model object you are binding to.
  • modelProperty: the model property you are binding to.
  • childrenProperty:Used in TreeViewers to specify the children property of the model object.
  • target: the widget you are binding to.
  • targetProperty: the widget property you are binding to.
  • model2target: a UpdateValueStrategyallowing you to specify validators, converter, etc.
  • target2model: a UpdateValueStrategyallowing you to specify validators, converter, etc.
  • closure: a simple way to create ComputedValues.

Builder styles

There are (at least) two ways you can write your bindings using the groovy-swt builder:

The basic using a bind node:

or the shortcut to avoid all the typing:

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:

Viewers

If you want to bind the data to jface viewers (lists, combos, tables, etc) you should bind the input attribute like:



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:



Master-Detail

If you use a jface viewer as a model if will create a master-detail observable of the selected item:



ComputedValues

To make simple one-way binding (possibly with some kind of calculations) you can use a bind closure:

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.

Or with a more complex example:

You can also use the model2target.converter to create a simple calculated value:

 

Threads


TODO: Realms, updating models in the realm, 

  • No labels