Hi @ all,
I need your help in binding a FormattedText.
From the database I get Long values. These values must be brought in the format "HH: mm".
Here is a little bit code:
The FormattedText
FormattedText worktimeText = new FormattedText(client);
worktimeText.setFormatter(new DateTimeFormatter("HH:mm"));
gd = new GridData();
gd.horizontalSpan = 2;
worktimeText.getControl().setLayoutData(gd);
GridDataFactory.swtDefaults().hint(30, SWT.DEFAULT).applyTo(worktimeText.getControl());
bindWorktimeText(worktimeText.getControl(), editor);
The Binding
private void bindWorktimeText(Text worktimeText, StandbyTypeEditor editor) {
IObservableValue worktimeWidget = WidgetProperties.text(SWT.Modify).observe(worktimeText);
IObservableValue worktimeModel = PojoProperties
.value(StandbyTypeVO.WORK_TIME_FIELD).observe(editor.getModel());
UpdateValueStrategy worktimeToTarget = new UpdateValueStrategy();
worktimeToTarget.setConverter(new IConverter() {
@Override
public Object getToType() {
return Date.class;
}
@Override
public Object getFromType() {
return Long.class;
}
@Override
public Object convert(Object fromObject) {
Date date = new Date((Long) fromObject);
return date;
}
});
editor.getBindingContext().bindValue(worktimeWidget, worktimeModel, null, worktimeToTarget);
Without the ValueStrategy-Converter the text is blank but i get an exception when i try to convert it.
org.eclipse.core.databinding.BindingException: converter does not convert to type class java.lang.String Expected: class java.sql.Date, actual: class java.lang.String
can someone help me?
Greetings
[Updated on: Thu, 22 December 2011 13:28]
Report message to a moderator