SWT Data Bindings

Supported for Eclipse 3.3 and above only

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

SWT uses simple bindings between targets and models.

Target & Model Types

Two types of targets and models are supported:

Properties

When any Target or 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.

         

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.

  

New SWT Bindings

New bindings are created by selecting a Target, a Target Property, a Source, a Source Property and clicking the Bind button. 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.

    

When binding to a selection object, the entire object may be bound to using the Selection as object radio button or one of its fields may be bound to using the Part of selection radio button. When Part of selection is chosen, the type of the selection should be specified in the Class field. A property specific to the specified class may then be specified.

If the Strategy Properties section is expanded for either the Target or Model, validators (AfterConvert, AfterGet and BeforeSet) and converters can be specified.

If necessary, the resulting binding object can be assigned to a field. This can be useful when you need to bind to the validationStatus of the binding itself.

  

Existing SWT Bindings

At the top of the page, existing Bound Properties are listed. The Target and Model are shown as well as the Target Strategy and the Model Strategy.

Clicking the Edit button or Edit menu opens the Edit Binding dialog where the update strategies may be modified.

    

The Delete button or Delete menu is used to delete the selected bound property while the Delete All button or Delete All menu is used to delete all of the bound properties.

The Move Up and Move Down buttons and menus are used to change the order of the bindings while the 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.

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.