|
Data binding DOM, POJO, Swing, SWT with JFace Databinding
|
|
|
|
|
Tuesday, 27 May 2008
|
Principle DataBinding The DataBinding (association of data) is a mechanism to connect a UI controls at their source data. A classic case of DataBinding east of wanting a binder control Textbox (Text SWT, Swing JTextField) has a property of a JavaBean. Either the JavaBean Person: public class Person ( private String name = "Please fill the name"; public String getName (return this.name;) public void setName (String name) (this.name = name;) ) Either the control Textbox Swing: JTextField text = new JTextField (); The ideee basic Databinding east of the binder property name of an instance of Person with the property Text of JTextField. When the JTextField appears, it contains "Please fill the name" because it calls getName of the body of person who is initialized with this value. When the user typed in the JTextField, setName setter is called to update the name of JavaBean property. This modus operandi can thus synchronize with the UI JavaBean, without being obliged to code synchronization. This is done by an engine DataBinding. Implementation Engine DataBinding I had to do a study on the implementation of the project for Databinding TK-UI that can be described in XML (XHTML, XUL, XForms ...) interfaces and travel to SWT, Swing. In the case of TK-IU, one must manage multiple type DataBinding: DataBinding IU and DOM, in other words synchronize the values of IU with the attributes of DOM
DataBinding between 2 IU, in other words a Textbox synchronize with another. DataBinding between DOM and JavaBean / Subject to Scriptable binder with an expression of binding (as XAML), an object JavaBean / Javascript with the DOM. DataBinding IU and DOM For grammar HTML: id="MyTextBox" <input type="text" value="Initial value" /> We have to attribute value is binde with the property Text of JTextField. The HTML DOM charge remains synchronized with the IU (Swing or SWT). This in turn helps to be able to recover the value of JTextField through the HTML DOM loaded, like this: Element input = document.getElementById ( "MyTextBox"); String value = input.getAttribute ( "value"); DataBinding between 2 IU In TK-UI, it is possible to describe the binding with an expression of binding (as XAML). For example, the following HTML: id="MyTextbox1" /> <input type="text" id="MyTextbox2" <input type="text" value="{Binding ElementName=MyTextbox1" Path=value />) Allows for the second Textbox binder with the first. When the first is modified by the user (or the DOM), the second textbox synchronizes with the first textbox. DataBinding between DOM and JavaBean / Object Scriptable This feature is not yet developed, but we can do this: <script> Person function () ( this.name =''; ) var myPerson = new Person (); </ script> <input type="text" value={Binding Source=myPerson Path=name} /> Used to the Textbox binder with the name fields of the object myPerson Javascript. JFace Databinding There are several implementation engine DataBinding in Java such as JGoodies or thereof. The problem is that these engines binding manages a type of binding. JGoodies permet de binder of JavaBean with controls Swing. But binder with a DOM SWT remains very complicated to implement. So I was looking for an engine of binding generic and I fell on JFace DataBinding which as its name does not indicate engine is a generic binding independent SWT. The team proposes a JFace engine binding generic and have implemented the binding for SWT and JavaBean, in other words: org.eclipse.core.databinding_ *. jar is the jar containing the engine generic DataBinding. org.eclipse.jface.databinding_ *. jar is the jar that contains the implementation of binding for SWT org.eclipse.core.databinding.beans_ *. jar is the jar that contains the implementation of binding to JavaBean What is it DOM, Swing and Javascript (Rhino). I also found the project UFace which is a generic API IU and then go to any renderer (SWT, Swing, GWT ...). UFace uses JFace DataBinding to manage the binding. I UFace helps to implement JFace Databinding to manage the binding with DOM, Swing and Javascript (Rhino). You can find projects on UFace: org.ufacekit.core.databinding.dom is the Eclipse project which contains the implementation of binding to XML DOM org.ufacekit.ui.swing.databinding is the Eclipse project which contains the implementation of binding to Swing org.ufacekit.core.databinding.scripting is the Eclipse project which contains the implementation of binding to Javascript (Rhino) This is great with JFace DataBinding is that once we have implemented a type of DataBinding, you can use it with another type. For example, the DOM DataBinding implemented can be used for binder with SWT DOM, DOM with Swing, DOM with objects JavaScripts. If you want more information on TK-IU or JFace Databinding, n'hesites not leave a message or contact me.
|