[DataBinding] master-detail binding with non-String properties [message #18440] |
Wed, 01 July 2009 04:44  |
Eclipse User |
|
|
|
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 07:04  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.03120 seconds