JFace Data Binding |
Home |
FAQ |
Snippets |
Developing line of business applications as Eclipse Rich Client Platform applications presents a number of unique challenges.
All of these concerns are improved using JFace Data Binding.
Traditionally, database-driven line of business applications are organized into tiers:
The communication paths between these tiers are organized along the routes that data flows within and among these tiers.
Recently, Hibernate, EJB3, and Rails technologies have emergedas a means of automating the data flow between the business tier andthe database tier.
By analogy, just as Hibernate helps automate the data flowbetween the business tier and the database tier, JFace Data Bindinghelps automate the data flow betweeen the business tier and thepresentation tier. It does this via a simple update to themodel-view-controller pattern that enables us to create a set ofcompletely generic and reusable controllers between the business modelobjects and the view (or presentation) tier.
Traditional object-oriented architectures use themodel-view-controller pattern to persist changes in a user interface toa model. This architecture can be visualized as follows:
This works the following way:
There are a few problems with this pattern:
Data binding is a recognition that most of the time, Text widgetsare bound to single properties of objects, a radio group has ajava.util.List or a java.util.Set of choices and its selection is boundto a single property of an object, and so on. Since we know that thedata type in the business model tier has to match the data type in theGUI widget, we can build a generic mapping layer between POJOs and GUIssimilar to the way Hibernate is a generic mapping layer between POJOsand databases.
In general, the architecture then looks like:
The implementation is simple. The generic controller representsdata binding. It listens to changes on both the model and on the GUIview. When a change in a property occurs in the model, it isautomatically copied to the GUI. Similarly, when the user changes avalue in the GUI, the change is automatically copied back to the model.
To make this concrete, let‘s look at an example:
Suppose the model object is an Integer property of an Employeeobject called "numberOfYearsWithFirm". This property is to be bound toan SWT Text control. Then:
The controller simply listens to the model for changes in the"numberOfYearsWithFirm" property. Similarly, it listens to the SWT Textobject for changes the user makes in the UI.
If the user changes the UI or the underlying model objectchanges, that change is copied to the other side, automaticallyapplying any validation and/or data type conversion rules that arenecessary to make the whole thing work.
For example, if the user changes the SWT Text object, the newString value is validated that it can be converted to an "int", thevalue is then converted to an "int", and the new integer value is thenset in the model object.