|
|
Re: CDateTime Databinding [message #1692347 is a reply to message #550116] |
Wed, 15 April 2015 08:54 |
Henno Vermeulen Messages: 126 Registered: July 2009 |
Senior Member |
|
|
In case someone reads this old post, this issue was reported here and has been fixed.
I have a use case where I also wish to update the model through UI to model binding when programmatically calling CDateTime.setSelection(). I'm not sure if it's by design, but this doesn't fire a change on the CDateTimeObservableValue. I solved this issue by using my own CDateTimeDateProperty:
import java.util.Date;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetValueProperty;
import org.eclipse.nebula.jface.cdatetime.CDateTimeObservableValue;
import org.eclipse.nebula.widgets.cdatetime.CDateTime;
import org.eclipse.swt.SWT;
/**
* Represents the <code>date</code> property of the
* {@link CDateTime} widget. It can be used for data binding. You can obtain the
* {@link IObservableValue} of the <code>date</code> property with this code:
*
* <pre>
* IObservableValue dateObservable = new CDateTimeDateProperty()
* .observe(dateTimeWidget);
* </pre>
*
* <p>
* Note that there does exist a {@link CDateTimeObservableValue} but it did not work for
* me, even after the original <a
* href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=395083">bug</a> I
* experienced was fixed. (See code comment for details.)
*
* @author Henno Vermeulen
*/
public class CDateTimeDateProperty extends WidgetValueProperty {
public CDateTimeDateProperty() {
/*
* Note that
*
* 1. SWT.Modify on it's own seems to work ok but CDateTime does not
* fire SWT.Modify when typing in a single-digit month.
*
* 2. SWT.Selection seems to work ok and gives the same behavior as the
* "official" CDateTimeObservableValue. But is not sufficient because
* CDateTime does not fire a change when setSelection(Date) is
* programmatically called. (We require this for the date selection
* buttons in PeriodSelector.)
*
* Adding both events solves the month issue mentioned in 1 because an
* SWT.Selection change is fired on focus lost.
*/
super(new int[] { SWT.Selection, SWT.Modify });
}
@Override
protected Object doGetValue(Object source) {
Date value = ((CDateTime) source).getSelection();
return value;
}
@Override
protected void doSetValue(Object source, Object value) {
((CDateTime) source).setSelection((Date) value);
}
@Override
public Object getValueType() {
return Date.class;
}
}
[Updated on: Wed, 15 April 2015 08:56] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04573 seconds