How to use Databinding to provide content and labels for editable viewers with calculated values? [message #21864] |
Fri, 17 July 2009 04:26  |
Eclipse User |
|
|
|
Originally posted by: TheRealHawk.Freenet.de
I know that I can do something like that:
IObservableMap[] labelMape = BeansObservables.observeMaps(
cp.getKnownElements(), new String[] { "name", "address", "phone" } );
viewer.setLabelProvider(new ObservableMapLabelProvider(labelMaps));
This works if I only want to display some properties of a list of beans.
But what should I do if I want to display calculated values in the viewer or
use an EditingSupport in the columns?
Markus
|
|
|
|
|
|
Re: How to use Databinding to provide content and labels for editable viewers with calculated values [message #22044 is a reply to message #21956] |
Fri, 17 July 2009 13:27  |
Eclipse User |
|
|
|
Markus,
See answers below
Markus Koch wrote:
> Just an example: I have a list of persons with property name, surname,
> dateOfBirth
>
> If I only want to display the properties in a TableViewer I can use the
> ObservableMapLabelProvider.
> But what if:
> 1. I want to also display calculated values - e.g. age?
> For this I don't can use the ObservableMapLabelProvider - I need an
> ObservableValueLabelProvider for each TableViewerColumn, so that I also can
> display CalculatedValues in the viewer.
We do have ObservableMapCellLabelProvider if this is what you're
thinking about, but it won't help you with calculated values. And since
we don't yet have ComputedMap yet then that won't work either. Probably
the simplest route is to implement a SimpleValueProperty that converts a
birth date to an age:
public class DateAgeProperty extends SimpleValueProperty {
public INativePropertyListener adaptListener( ISimplePropertyListener
listener ) {
return null;
}
protected Object doGetValue( Object source ) {
Date date = (Date) source;
// convert date to age and return
}
protected void doSetValue( Object source, Object value ) {
throw new UnsupportedOperationException();
}
public Object getValueType() {
return Integer.class;
}
}
Then chain the dateOfBirth and age properties together:
IObservableMap ages = BeanProperties
.value("dateOfBirth")
.value(new DateAgeProperty())
.observeDetail(contentProvider.getKnownElements());
> 2. I want to edit some properties?
> For this I also have to create my own TableViewerColumn with an
> ObservableValueEditingSupport.
>
> Now my question is: Is there a eclipse-default-way like
> ObservableValueLabelProvider or ObservableValueEditingSupport?
I don't follow you here. Could you elaborate?
Matthew
|
|
|
Powered by
FUDForum. Page generated in 0.05012 seconds