Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » CDateTime Databinding
CDateTime Databinding [message #550115] Thu, 29 July 2010 08:06 Go to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 244
Registered: July 2009
Senior Member
Hello together,

i have a question for the CDateTime databinding. Why it doesn't work? What is the mistake? Model gets alwasys the value null
CDateTime cDateTime = new CDateTime(parent, CDT.BORDER | CDT.COMPACT | CDT.DROP_DOWN | CDT.DATE_LONG | CDT.TIME_MEDIUM);
 
DataBindingContext m_bindingContext = new DataBindingContext();
         
          m_bindingContext.bindValue(new CDateTimeObservableValue(cDateTime), BeansObservables.observeValue(model, MyModel.PROP_BIRTHDAY), 
                     null, null);
 
public class MyModel {
           public static final String PROP_BIRTHDAY  = "birthday"; 
           private Date   m_birthday;
         
           public Date getBirthday(){
              return m_birthday;
           }
         
           public void setBirthday(final Date newValue){
              Date oldValue = getBirthday();
              m_birthday = newValue;
              m_propertyChangeSupport.firePropertyChange(PROP_BIRTHDAY, oldValue, newValue);
           }
Re: CDateTime Databinding [message #550116 is a reply to message #550115] Thu, 29 July 2010 08:16 Go to previous messageGo to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 244
Registered: July 2009
Senior Member
Is this a bug??
The current Listener in CDateTimeObserverable is:
	private SelectionListener listener = new SelectionListener() {
		public void widgetDefaultSelected(SelectionEvent e) {
			if (!updating) {
				Date newSelection = CDateTimeObservableValue.this.dateTime.getSelection();
				fireValueChange(Diffs.createValueDiff(currentSelection, newSelection));
				currentSelection = newSelection;
			}
		}
		public void widgetSelected(SelectionEvent e) {
			// skip
		}


But the widgetDefaultSelected method is never called, if i switch the code, it works:

	private SelectionListener listener = new SelectionListener() {
		public void widgetDefaultSelected(SelectionEvent e) {
			//Skip
		}
		public void widgetSelected(SelectionEvent e) {
			if (!updating) {
				Date newSelection = CDateTimeObservableValue.this.dateTime.getSelection();
				fireValueChange(Diffs.createValueDiff(currentSelection, newSelection));
				currentSelection = newSelection;
			}
		}
	};
Re: CDateTime Databinding [message #1692347 is a reply to message #550116] Wed, 15 April 2015 08:54 Go to previous message
Henno Vermeulen is currently offline Henno VermeulenFriend
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

Previous Topic:[GanttChart] Space between Events
Next Topic:hidden rows copied during copy/paste
Goto Forum:
  


Current Time: Wed Apr 24 18:53:55 GMT 2024

Powered by FUDForum. Page generated in 0.03146 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top