|
Re: EMF DataBinding Converter [message #1032967 is a reply to message #1032602] |
Wed, 03 April 2013 17:41 |
Matthew Fitzgerald Messages: 13 Registered: July 2009 |
Junior Member |
|
|
RESOLVED
I figured out the error message and one other problem:
1. The EMF model was of primitive type float hence causing the "Model converter Class does not exist." error... which I now understand. Changing the model to EFloatObject (java.lang.Float) fixed that problem. org.eclipse.core.databinding.conversion.Converter must, of course, be used with 'tos' and 'froms' which are descendants of java.lang.Object.... it was a late night....
2. The second problem was the POLICY_CONVERT. This policy performs the conversion, but stops short of updating the value to the Label - the update is a separate request. Changing back to POLICY_UPDATE fixed this issue.
So, my converter class ends up being this:
import org.eclipse.core.databinding.conversion.Converter;
public class FloatToStringConverter extends Converter {
public FloatToStringConverter(){
super(Float.class, String.class);
}
@Override
public Object convert(Object fromObject) {
if (fromObject == null) return "";
if (fromObject.getClass() != Float.class) return "";
Float f = (Float)fromObject;
String s;
.... fancy conversion code ...
return s;
}
}
And the WindowsBuilder generated initDataBindings are:
IObservableValue observeTextLblAvgReadElapsedTimeObserveWidget = WidgetProperties.text().observe(lblAvgReadElapsedTime);
IObservableValue commsStatisticsResponseTimeMsAvgObserveValue = EMFObservables.observeValue(commsStatistics,
Literals.COMMS_STATISTICS__RESPONSE_TIME_MS_AVG);
UpdateValueStrategy strategy_4 = new UpdateValueStrategy();
strategy_4.setConverter(new FloatToStringConverter());
bindingContext.bindValue(observeTextLblAvgReadElapsedTimeObserveWidget, commsStatisticsResponseTimeMsAvgObserveValue,
new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), strategy_4);
Hope this helps anyone else with a similar issue.
|
|
|
Powered by
FUDForum. Page generated in 0.02944 seconds