Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [DataBinding] master-detail binding with non-String properties
[DataBinding] master-detail binding with non-String properties [message #18440] Wed, 01 July 2009 08:44 Go to next message
Marcin Gryszko is currently offline Marcin GryszkoFriend
Messages: 2
Registered: July 2009
Junior Member
Hi,

Master-detail binding between TableViewer selection and a Text field
doesn't work for me for non-String properties of the model class.

My TableViewer displays model objects. My model class has a long property,
id, and a String property, description. The description property value is
bound correctly to the corresponding text field, the text field for the id
property remains empty.

I adapted the master-detail snippet from JFace Data Bindin Snippets page:

IObservableValue selection =
ViewersObservables.observeSingleSelection(viewer);
IObservableValue detailObservable =
BeansObservables.observeDetailValue(selection, "id", long.class);
new DataBindingContext().bindValue(SWTObservables.observeText(na me,
SWT.None), detailObservable, new UpdateValueStrategy(false,
UpdateValueStrategy.POLICY_NEVER), null);

Is this behaviour a bug? Should I configure a converter someway? Does
single selection-detail binding work only with java.lang.String properties?

Thanks in advance you for your help,

Marcin Gryszko
Re: [DataBinding] master-detail binding with non-String properties [message #18460 is a reply to message #18440] Wed, 01 July 2009 11:04 Go to previous message
Marcin Gryszko is currently offline Marcin GryszkoFriend
Messages: 2
Registered: July 2009
Junior Member
OK, I found the solution to my problem.

It results that there is no default converter for the master-detail case.
The binding framework doesn't know a priori what property class the detail
will have (it doesn't know the class of the viewer selection). Thus no
converter is registered and my text field is filled with a null value.

I solved the problem by manually creating a converter from long to String
and passing it to the UpdateValueStrategy:

new UpdateValueStrategy().setConverter( new Converter( long.class,
String.class ) {
@Override
public Object convert(Object fromObject) {
return ((Long) fromObject).toString();
}
})

I wonder only why default converters from the
org.eclipse.core.internal.databinding.conversion are not exported from the
org.eclipse.core.databinding bundle if sometimes they must be configured
manually.
Previous Topic:[databinding] ObservableListTreeContentProvider with IObservableList in different realm
Next Topic:TreeViewer getItems
Goto Forum:
  


Current Time: Fri Apr 26 19:37:53 GMT 2024

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

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

Back to the top