Binding on Nebula DateChooserCombo

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Binding on Nebula DateChooserCombo

Postby nelsonfernando » Mon Jul 14, 2008 5:53 am

Hi I´m a newb in SWT and need some help using the Nebula components with the designer binding system .

I´m trying to bind a DateChooserCombo with a POJO , I´m using POLICE_UPDATE in model and target strategies.
I bound the value and text variables of the DateChooserCombo to Strings in a POJO.

When the view starts up the binding works ( the objects look for the values in the POJO ) . But when a alter the values in the DateChooserCombo the POJO isn´t updated .

What am I missing for the binding to work properly ?
Is there a better component for chossing a date than DateChooserCombo (outside Nebula components) that is easier to bind using the designer ?
nelsonfernando
 
Posts: 4
Joined: Mon Jul 14, 2008 5:37 am

Re: Binding on Nebula DateChooserCombo

Postby Eric Clayberg » Mon Jul 14, 2008 6:07 am

nelsonfernando wrote:What am I missing for the binding to work properly ?

You did not provide a test case, so I don't know.

I have never used a Nebula widget in a data binding example, so I don't know what the issues might be.

If you are looking for advice on how to use the Nebula widgets or how to best use data binding in your app, the eclipse.technology.nebula and eclipse.platform newsgroups would be a better source of information.

This forum is for issues directly related to the SWT Designer tooling.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Binding on Nebula DateChooserCombo

Postby pascal leclercq » Tue Jul 15, 2008 6:12 am

Hello fernando,

You can create an Observable Value for the DateChooserCombo with this code :
Code: Select all
package com.proxiad.sandbox;

import java.util.Date;

import org.eclipse.core.databinding.observable.Diffs;
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.nebula.widgets.datechooser.DateChooserCombo;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;

public class DateChooserComboObservableValue extends AbstractObservableValue
      implements IObservableValue {
   
   /**
    * The Control being observed here.
    */
   protected final DateChooserCombo dateChooserCombo;
   
   /**
    * Flag to prevent infinite recursion in {@link #doSetValue(Object)}.
    */
   protected boolean updating = false;
   
   /**
    * The "old" selection before a selection event is fired.
    */
   protected Date currentSelection;

   /**
    * Observe the selection property of the provided CDateTime control.
    *
    * @param dateChooserCombo the control to observe
    */
   public DateChooserComboObservableValue(DateChooserCombo dateChooserCombo) {
      super(SWTObservables.getRealm(dateChooserCombo.getDisplay()));
      this.dateChooserCombo = dateChooserCombo;
      currentSelection = dateChooserCombo.getValue();

      dateChooserCombo.addDisposeListener(disposeListener);
   }


   private DisposeListener disposeListener = new DisposeListener() {
      public void widgetDisposed(DisposeEvent e) {
         DateChooserComboObservableValue.this.dispose();
      }
   };
   
   
   /* (non-Javadoc)
    * @see org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue#getValueType()
    */
   
   public Object getValueType() {
      return Date.class;
   }

   /* (non-Javadoc)
    * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doGetValue()
    */

   protected Object doGetValue() {
      return dateChooserCombo.getValue();
   }


   protected void doSetValue(Object value) {
      Date oldValue;
      Date newValue;
      try {
         updating = true;
         oldValue = dateChooserCombo.getValue();
         newValue = (Date) value;
         dateChooserCombo.setValue(newValue);
         currentSelection = newValue;
         fireValueChange(Diffs.createValueDiff(oldValue, newValue));
      } finally {
         updating = false;
      }
   }
}
pascal leclercq
 
Posts: 2
Joined: Tue Jul 15, 2008 5:49 am

Re: Binding on Nebula DateChooserCombo

Postby nelsonfernando » Tue Jul 15, 2008 7:25 am

Thanks !
nelsonfernando
 
Posts: 4
Joined: Mon Jul 14, 2008 5:37 am

Re: Binding on Nebula DateChooserCombo

Postby Eric Clayberg » Tue Jul 15, 2008 7:26 pm

pascal leclercq wrote:You can create an Observable Value for the DateChooserCombo with this code

You should contribute that code to Eclipse.org!
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests