Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [Databinding] What do you think about manage JFace Databinding with Annotation?(Explain a POC that I have started to create to manage JFace Databinding with annotation)
[Databinding] What do you think about manage JFace Databinding with Annotation? [message #730382] Wed, 28 September 2011 09:37
Angelo ZERR is currently offline Angelo ZERRFriend
Messages: 122
Registered: July 2009
Senior Member
Hi JFace Team,

I would like know your opinion about an idea that I have to manage JFace Databinding with annotation. JFace Databinding is very powerfull but :

* API can be verbose.
* It's difficult to see the binding done by regarding Java code of JFace binding.

WindowProBuilder is a great tool which generates binding, so my last arguments can be criticized. But I would like share my idea with you and know your opinion about managing JFace Databinding with annotation.

I have created a very basic POC that I have called org.eclipse.core.databinding.annotations to use JFace Databinding with annotation. My sample is very basic : bind a SWT Text with Person model.

Here my sample :

public class PersonSnippet1 {

@BindValue(targetProperty = UIProperty.Text, targetEvent = SWT.Modify, modelProperty = "name")
private Text text = null;

@Model
private Person model;
}


To interpret thoses annotation, you must called at end :

DataBindingContext dataBindingContext = new DataBindingContext(SWTObservables.getRealm(display));
BindAnnotationProcessorRegsitry.getRegistry().process(PersonSnippet1.this, dataBindingContext, null);


Here the whole code with annotation :
package fr.opensagres.eclipse.forms.samples.annotations;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.annotations.BindAnnotationProcessorRegsitry;
import org.eclipse.core.databinding.annotations.BindException;
import org.eclipse.core.databinding.annotations.BindValue;
import org.eclipse.core.databinding.annotations.Model;
import org.eclipse.core.databinding.annotations.UIProperty;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import fr.opensagres.eclipse.forms.samples.model.Person;

public class PersonSnippet1 {

	@BindValue(targetProperty = UIProperty.Text, targetEvent = SWT.Modify, modelProperty = "name")
	private Text text = null;

	@Model
	private Person model;

	public void run() {
		final Display display = new Display();
		Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
			public void run() {
				final Shell shell = new Shell(display);

				shell.setLayout(new FillLayout());

				model = new Person();
				text = new Text(shell, SWT.BORDER);

				DataBindingContext dataBindingContext = new DataBindingContext(
						SWTObservables.getRealm(display));
				
				// Process @BindValue annotation
				try {
					BindAnnotationProcessorRegsitry.getRegistry().process(
							PersonSnippet1.this, dataBindingContext, null);
				} catch (BindException e) {
					e.printStackTrace();
				}
				shell.setSize(200, 50);
				shell.open();

				// The SWT event loop
				Display display = Display.getCurrent();
				while (!shell.isDisposed()) {
					if (!display.readAndDispatch()) {
						display.sleep();
					}
				}
			}
		});

	}

	public static void main(String[] args) {
		PersonSnippet1 snippet = new PersonSnippet1();
		snippet.run();
	}
}



Here the sample without annotation with classic API JFAce Databinding:

package fr.opensagres.eclipse.forms.samples.annotations;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.PojoObservables;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import fr.opensagres.eclipse.forms.samples.model.Person;

public class PersonSnippet1_withoutAnnotation {

	private Text text = null;

	private Person model;

	public void run() {
		final Display display = new Display();
		Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
			public void run() {
				final Shell shell = new Shell(display);

				shell.setLayout(new FillLayout());

				model = new Person();
				text = new Text(shell, SWT.BORDER);

				DataBindingContext dataBindingContext = new DataBindingContext(
						SWTObservables.getRealm(display));

				IObservableValue textObserveTextObserveWidget = SWTObservables
						.observeText(text, SWT.Modify);
				IObservableValue modelNameObserveValue = PojoObservables
						.observeValue(model, "name");
				dataBindingContext.bindValue(textObserveTextObserveWidget,
						modelNameObserveValue, null, null);

				shell.setSize(200, 50);
				shell.open();

				// The SWT event loop
				Display display = Display.getCurrent();
				while (!shell.isDisposed()) {
					if (!display.readAndDispatch()) {
						display.sleep();
					}
				}
			}
		});

	}

	public static void main(String[] args) {
		PersonSnippet1_withoutAnnotation snippet = new PersonSnippet1_withoutAnnotation();
		snippet.run();
	}
}


I have a lot of idea for org.eclipse.core.databinding.annotationsto manage UpdateValueStrategy, validator, etc with annotation manage JSR-303 like this
http://www.techjava.de/topics/2011/02/validating-jface-databinding-jsr-303/

What do you think about this idea? If you like I could create a patch with my work.

Regards Angelo

[Updated on: Wed, 28 September 2011 09:53]

Report message to a moderator

Previous Topic:OwnerDrawLabelProvider ignores setting event.height
Next Topic:Adding new row using Inline Editing in a TableViewer
Goto Forum:
  


Current Time: Thu Apr 25 19:18:33 GMT 2024

Powered by FUDForum. Page generated in 0.02640 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top