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