Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

JFace Data Binding/Tutorial

< JFace Data Binding
Revision as of 20:06, 12 October 2007 by Unnamed Poltroon (Talk) (New page: == Data Binding Tutorial == === Terms === * Model: a Model represents the Domain Model of your Application. * Target: a Target represents the GUI side. === A first simple binding === <p>L...)

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

Data Binding Tutorial

Terms

  • Model: a Model represents the Domain Model of your Application.
  • Target: a Target represents the GUI side.

A first simple binding

Looking at the example snippets, you'll see a few SWT examples. This time, we'll create a very simple RCP view. Our createPartControl method has just one Text Element:

	public void createPartControl(Composite parent){

	name = new Text(testGroup, SWT.BORDER);
	final GridData gd_name = new GridData(SWT.FILL, SWT.CENTER, true, false);
	name.setLayoutData(gd_name);

	}

That Text name represents the Target of our binding. Let's add a simple Model:

	static class Person {
		// A property...
		String name = "HelloWorld";

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}
	}

To create your first binding, you need to instantiate a DataBindingContext. Create a method like this:

	private DataBindingContext initDataBindings() {
	DataBindingContext bindingContext = new DataBindingContext();

	return bindingContext;
	}

Next, we add a IObservableValue Object for the Target:

	private DataBindingContext initDataBindings() {
	DataBindingContext bindingContext = new DataBindingContext();

        IObservableValue nameTextObserveWidget = SWTObservables.observeText(name, SWT.FocusOut);

	return bindingContext;
	}

The observeText method takes two params

  • name: the watched Control
  • event: when the model will be updated. Choices are

Back to the top