Create Data Binding Wizard

Supported for Eclipse 3.3 and above only

The tool provides two ways to quickly create new Data Bindings: the Data Bindings menu and the bindings property in the property pane.

Data Binding Menu

The Data Bindings menu provides the ability to quickly create a data binding for a widget. If the widget does not have any data bindings, the menu immediately cascades out to show the available properties of the widget that can be bound to a model property. If the widget has existing data bindings, those are shown at the top of the cascaded menu and a list of widget properties is shown in a submenu. Clicking on an unbound property will open the Create Data Binding wizard.
 

 

Bindings Property

The bindings property in the property pane opens up to show a list of all bindable properties of the widget. Clicking the button next to an unbound property will open the Create Data Binding wizard.

 

Choose Model

The first page of the Create Data Binding wizard is used to select the model and property to bind the selected target property to. Two types of targets and models are supported: Beans and Widgets. The filter field above the list can be used to filter the list of items. The clear button can be used to clear the filter and restore the full list.

  • Beans: any field of the current compilation unit may be selected.
  • Widgets: any widget in the current compilation unit may be selected.

When any Model object is selected, its properties (bean fields or predefined SWT widget properties) are shown in the associated Properties list. A drop down filter menu is available to filter the Property list by type. Supported filters are String, Boolean, Numbers, Color and Font. A second filter is also available that only shows the properties that match the source property in type.

         

If the model object is another binding object, it is possible to bind to the validation status. If the object is already an IObservableValue (like a WritableValue), it can be bound to directly.

  

Once the model property has been selected, click the Finish button to create a new data binding using default options. If you wish to customize the properties of the data binding, click the Next button to go to the second page of the wizard.

Properties

The second page of the Create Data Binding wizard is used to customize the properties of the data binding itself. When creating a binding, the update strategy from target to model and model to target may be specified as well as any strategy-specific properties (validators and converters). 

 

When the Target or Model is a Text widget and the text property is selected, the triggering event may be specified as SWT.Modify, SWT.FocusOut or SWT.NONE.

Predefined update value strategies - POLICY_UPDATE, POLICY_NEVER, POLICY_ON_REQUEST and POLICY_CONVERT - may be selected or a custom strategy class may chosen.

    

Source

Clicking the Finish button will generate the necessary data binding code 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. Any needed observables are created first followed by the creation of the Data Binding Context. The data bindings are then created using the new context.

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.