Skip to content

Commit

Permalink
Add more details on Groovy based JavaFX binding support. Relates to #148
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Feb 29, 2016
1 parent c809f63 commit 5dbdd27
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docs/griffon-guide/src/docs/asciidoc/_links.adoc
Expand Up @@ -54,6 +54,7 @@
:link_mvchandler: link:api/griffon/core/mvc/MVCHandler.html[MVCHandler, window="_blank"]
:link_threading: link:api/griffon/transform/Threading.html[@griffon.transform.Threading, window="_blank"]
:link_threadinghandler: link:api/griffon/core/threading/ThreadingHandler.html[ThreadingHandler, window="_blank"]
:link_threadingmanager: link:api/griffon/core/threading/ThreadingManager.html[ThreadingManager, window="_blank"]
:link_property_listener: link:api/griffon/transform/PropertyListener.html[@griffon.transform.PropertyListener, window="_blank"]
:link_change_listener: link:api/griffon/transform/ChangeListener.html[@griffon.transform.ChangeListener, window="_blank"]
:link_invalidation_listener: link:api/griffon/transform/InvalidationListener.html[@griffon.transform.InvalidationListener, window="_blank"]
Expand Down Expand Up @@ -103,7 +104,9 @@
:link_guiceberry: link:https://github.com/zorzella/guiceberry[GuiceBerry, window="_blank"]
:link_mockito: link:http://mockito.org/[Mockito, window="_blank"]
:link_jukito: link:https://github.com/ArcBees/Jukito[Jukito, window="_blank"]
:link_junitparams: link:https://github.com/Pragmatists/JUnitParams[JUnitParams, window="_blank"]
:link_junitparams: link:https://github.com/Pragmatists/JUnitParams[JUnitParams, window="_blank"]`
:link_javafx_beans_observable: link:http://docs.oracle.com/javase/8/javafx/api/javafx/beans/Observable.html[Observable, window="_blank"]
:link_groovyfx: link:http://groovyfx.org/[GroovyFX, window="_blank"]

:sample-swing-java: {rootdir}/samples/sample-swing-java
:sample-swing-groovy: {rootdir}/samples/sample-swing-groovy
Expand Down
48 changes: 47 additions & 1 deletion docs/griffon-guide/src/docs/asciidoc/models-binding-javafx.adoc
Expand Up @@ -2,5 +2,51 @@
[[_models_binding_javafx]]
= JavaFX Binding

TBD
JavaFX provides its own binding mechanism, based on `{link_javafx_beans_observable}` and related types, such as
`javafx.beans.property.Property` and `javafx.beans.binding.Binding`.

[[_models_binding_javafx_groovy]]
== Groovy Bindings

{link_groovyfx} brings Groovy support for JavaFX in a similar way as standard Groovy does for Swing, which was
discussed in a <<_models_binding_swing_groovy,previous section>>. However there are some slight differences.

The `griffon-javafx-groovy-{griffon-version}.jar` delivers a new AST Transformation: <<_models_fxobservable_transformation,@FXObservable>>,
which by all means and purposes is functionally equivalent to GroovyFX's `@FXBindable` annotation. However `@FXObservable`
delivers better integration with the Griffon runtime, for example hooking into `{link_threadingmanager}` instead of calling
into `Platform.runLater`.

Using the `@FXObservable` AST transformation results in shorter, more expressive code. For example, the following code

[source,groovy,linenums,options="nowrap"]
----
class MyModel {
@FXObservable String value
}
----

Is transformed into byte code as if you had written the following source code

[source,groovy,linenums,options="nowrap"]
----
import javafx.beans.property.SimpleStringProperty
import javafx.beans.property.StringProperty
class MyModel {
private StringProperty value
String getValue() { valueProperty().get() }
void setValue(String s) { valueProperty().set(s) }
StringProperty getValueProperty() { valueProperty() }
StringProperty valueProperty() {
if (value == null) {
value = new SimpleStringProperty(this, 'value')
}
value
}
}
----

This annotation serves then as a shortcut for writing observable properties and nothing more.

Expand Up @@ -6,6 +6,7 @@ Binding in Griffon is achieved by leveraging Java Beans' `java.beans.PropertyCha
and their related classes; thus binding will work with any class that fires this type of
event, regardless of its usage of `{link_observable_ast}` or not.

[[_models_binding_swing_groovy]]
== Groovy Bindings

The following options are available for writing bindings using the `bind` call when Groovy is the source language:
Expand Down Expand Up @@ -201,3 +202,8 @@ swing.edt {

A contrived way to copy text from one textfield to another. The copy is performed by listening to `ActionEvent`s
pumped by the button.

NOTE: These examples made use of the `@griffon.transform.Observable` AST transformation. This transformation is a carbon
copy of `@groovy.beans.Bindable` with one addition: the owner class will also implement the `{link_observable} interface.
Both transformations are functionally equivalent and can be used interchangeably.

0 comments on commit 5dbdd27

Please sign in to comment.