WindowBuilder: advanced databinding with CDO

Now we will see how, starting from previous tutorial, we can handle the management of the data showed into the table.

Let’s get back to the Design tab and set a GridLayout, picking it up from the palette and dropping it to the main composite

now select a  Composite and drop it into the View

let both composite fill all the available room, by applying the following layout options to both of them

Now let’s give a GridLayout to the composite

and lay out a  Label with text “Name

and another, just under, with text “Surname

now let’s do the same with a couple of text fields

and add a  Save button

Our goal is to have a binding between these fields and the correspondent attributes of the selected item on the table above. To do this we need to define a variable of type  WritableValue

with which we can now perform our  binding (do the following for both fields)


Now we need to handle the viewer selection event

where we can insert the following code

import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.emf.cdo.util.CommitException;

protected CDOTransaction transaction;

        	public void selectionChanged(SelectionChangedEvent event) {
        		if (transaction!=null) {
				transaction = cdoSession.openTransaction();
				Author authorSelected = (Author) ((StructuredSelection) event.getSelection()).getFirstElement();
				Author authorTransactionalObject = (Author) transaction.getObject(authorSelected);
				author.setValue( authorTransactionalObject );

Here we will open a new CDO transaction upon every viewer selection event and do the binding with the transactional selected item.

As far as the save action, let’s do the following. Select the Save button and add a new event

and insert the following code

import org.eclipse.emf.cdo.util.CommitException;		
		public void widgetSelected(SelectionEvent e) {
        		try {
			} catch (CommitException e1) {



If now we launch the application we can verify that:

  • fields Name and Surname are automatically synchronized with the selected item in the viewer
  • clicking on the Save button will save the data, with automatic synchronization of the viewer content


Moreover, one of the coolest things about CDO is the following.
Just adding this simple line of code

we can have all clients notified when some other has changed values; just try launching more application instances …


Back to index