Click the Bindings tab in the editor to created and edit data bindings.

image

image

JFace Viewers can bind to a content provider, label provider and input object. The content provider (an ObservableListContentProvider or ObservableSetContentProvider) is calculated automatically based on the input. The label provider (and ObservableMapLabelProvider) is created based on the observed bean and its selected properties.

Viewers

Any viewers defined in the current compilation unit are shown in the widget list. Several properties including the input can be selected in the properties list

image

Input Types

Several types of inputs are supported:

  • image Collections: any field of the current compilation unit that is a java.lang.List or java.lang.Set may be selected. The filter field above the list can be used to filter the list of collections. The image clear button can be used to clear the filter and restore the full list.
    image  

  • image Beans: any field of the current compilation unit may be selected. The filter field above the list can be used to filter the list of beans. The image clear button can be used to clear the filter and restore the full list. Beans are the primary data source for bindings (usually the model). Any property of the Bean may be observed.
    image  

  • image Selection: any object (usually a JFace viewer) with a selection property of type org.eclipse.jface.viewers.IStructuredSelection may be selected. The filter field above the list can be used to filter the list of selections. The image clear button can be used to clear the filter and restore the full list. Typically, the selection of one viewer is bound to the input of another viewer in a master-detail relationship. If the selection target provide multiple selection or checked elements, those are available as inputs as well.
    image

New JFace Bindings

New bindings are created by selecting a Viewer, an Input and clicking the image Bind button. When creating a binding, the Content Provider and Label Provider may be specified.

image  image

For TreeViewer inputs, the Input Bean Class, IObservableFactory, Tree Structure Advisor, Content Provider and Label Provider may be specified.

image

In order to simplify this, the tool can generate a number of pre-defined helper classes that implement most of the needed tree behavior.

image

Existing JFace Bindings

At the top of the page, existing Bound Viewers are listed. The Content Provider and Input are listed for each viewer.

image

Clicking the image Edit button or Edit menu opens the Edit Binding dialog where the providers may be modified.

image     image

The image Delete button or Delete menu is used to delete the selected bound viewer while the image Delete All button or Delete All menu is used to delete all of the bound viewers.

The image Move Up and image Move Down buttons and menus are used to change the order of the bindings while the image Goto Definition button and menu are used to jump to the generated code for the binding.

Source

As bindings are created or edited on the Bindings tab, the necessary data binding code is generated which may then be seen in the Source view. An initDataBindings() method is created, if it does not already exist and a call to that method is added to the end of the widget creation process.

Within the initDataBindings() method, any needed observables are created first followed by the creation of the Data Binding Context. Simple SWT data bindings are then created using the new context followed by any JFace content providers, list providers and inputs that are needed.

image

Warning
do not edit the initDataBinding() method by hand (without carefully matching the code generation pattern used by the tool) as it will be regenerated in its entirety any time the tool needs to add, remove or update a data binding.