Skip to main content
Jump to: navigation, search

JFace Data Binding/TrackedGetter

< JFace Data Binding
Revision as of 15:03, 6 December 2007 by Boris (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Every getter on an observable object must make a call to ObservableTracker.getterCalled(). Why?

This enables abstractions like ComputedValue or ComputedList: All you have to write is a piece of code that computes a value, or a list. As long as this code only accesses other observables, the framework will manager listeners for you automatically.

For example, assume that your UI has text fields for the first name and the last name of a person, but you want to display a formatted version of the full name elsewhere in the UI. This is what you can write (see Snippet008 for a complete example):

final IObservableValue firstName = SWTObservables.observeText(firstNameField, SWT.Modify);
final IObservableValue lastName = SWTObservables.observeText(lastNameField, SWT.Modify);
IObservableValue formattedName = new ComputedValue() {
  protected Object calculate() {
    return lastName.getValue() + firstName.getValue();

Note that without having to register any listeners from client code, the 'formattedName' observable will always change whenever one of the observables referenced in its calculate() method changes. We didn't even have to pass a list of observables to the framework - just by calling lastName.getValue(), or firstName.getValue(), it will figure out that it has to listen for changes to lastName and firstName for you.

The data binding framework has internal classes that work similar to ComputedValue and ComputedList, but instead of producing a value or a list, they update widgets. For example, look for ControlUpdater, TableUpdater. These classes are not API yet because we haven't received enough feedback from early adopters yet. If you would like to see this as API, please push for it by filing enhancement requests in bugzilla.

Related Work

This idea is not new. It has been around for (at least) 10 years. Here are some pointers to related work.

Back to the top