Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 246014 - [DataBinding] "IObservableValue" for the nebula DateChooserCombo widget
Summary: [DataBinding] "IObservableValue" for the nebula DateChooserCombo widget
Status: CLOSED WONTFIX
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Nebula (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Eric Wuillai CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-02 16:21 EDT by Pascal Leclercq CLA
Modified: 2021-07-05 11:40 EDT (History)
8 users (show)

See Also:


Attachments
DB Observable for DateChooserCombo Nebula widget (3.51 KB, text/x-java)
2008-09-11 16:12 EDT, Pascal Leclercq CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pascal Leclercq CLA 2008-09-02 16:21:37 EDT
Build ID: UI

Steps To Reproduce:
for my needs I wrote the "IObservableValue" for the DateChooserCombo widget.

It seems to work and I want to share it with the community.


Please send me your feedbacks 

More information:
Comment 1 Benjamin Cabé CLA 2008-09-02 17:56:03 EDT
You didn't attach any patch!
Comment 2 Thomas Schindl CLA 2008-09-02 18:49:23 EDT
... and the wrong component, moving to Nebula :-)
Comment 3 Boris Bokowski CLA 2008-09-03 12:37:08 EDT
..and Tom forgot to check "Reassign bug to default assignee and QA contact, and add Default CC of selected component".
Comment 4 Emil Crumhorn CLA 2008-09-03 12:39:45 EDT
I assume this is not for CalendarCombo, so I probably shouldn't be the target of "Assigned To" :)
Comment 5 Pascal Leclercq CLA 2008-09-11 16:12:48 EDT
Created attachment 112351 [details]
DB  Observable  for DateChooserCombo Nebula widget
Comment 6 Marcelo Alcantara CLA 2009-01-21 15:17:52 EST
I tried to use this observable, but my QA team discovered that when using it, the formatting stops working when filling the date manually.

There is some workaround to this issue?

Thanks, Marcelo
Comment 7 Matthew Hall CLA 2009-01-22 18:40:31 EST
When 3.5 lands you may want to investigate implementing this using SimpleValueProperty (see bug 194734).  Properties come with their own observable implementations so you only have to implement a handful of methods and a listener class (if the widget fires events for that particular property).

public class DateChooserComboValueProperty extends SimpleValueProperty {
  private final int event;

  public DateChooserComboValueProperty(int event) {
    if (!(event == SWT.None || event == SWT.FocusOut || event == SWT.Modify))
      throw new IllegalArgumentException(
         "UpdateEventType [" + updateEventType + //$NON-NLS-1$
         "] is not supported."); //$NON-NLS-1$
    this.event = event;
  }

  public Object getValueType() {
    return Date.class;
  }

  protected Object doGetValue(Object source) {
    return ((DateChooserCombo)source).getValue();
  }

  protected void doSetValue(Object source, Object value) {
    ((DateChooserCombo)source).setValue((Date) value);
  }

  public INativePropertyListener adaptListener(ISimplePropertyListener listener) {
    if (event == SWT.None)
      return null;
    return new WidgetListener(listener);
  }

  private class WidgetListener extends Listener {
    private ISimplePropertyListener listener;

    WidgetListener(ISimplePropertyListener listener) {
      this.listener = listener;
    }

    public void handleEvent(Event e) {
      // Just parlay the event to the listener
      listener.handlePropertyChange(new SimplePropertyEvent(
          e.widget, DateChooserComboValueProperty.this, null);
    }
  }

  protected void doAddListener(Object source,
                               INativePropertyListener listener) {
    if (event != SWT.None)
      ((DateChooserCombo)source).addListener(event,
                                             (WidgetListener) listener);
  }

  protected void doRemoveListener(Object source,
                                  INativePropertyListener listener) {
    if (event != SWT.None)
      ((DateChooserCombo)source).removeListener(event,
                                                (WidgetListener) listener);
  }

  // default implementation uses current default realm
  // but with widget observables we want to use to widget's display
  // realm instead
  public IObservableValue observe(Object source) {
    Realm realm = SWTObservables.getRealm(((Widget)source).getDisplay());
    return observe(realm, source);
  }

  // ensure observable is disposed when widget is disposed
  public IObservableValue observe(Realm realm, Object source) {
    final IObservableValue observable = super.observe(realm, source);
    ((DateChooserCombo)source).addListener(SWT.Dispose,
       new Listener() {
         public void handleEvent(Event e) {
           observable.dispose();
         }
       } );
    return observable;
  }
}

Notice that you don't have to deal with realms, cache values, or fire events (or deal with updating flags).

IObservableValue dateSelection = 
    new DateChooserComboValueProperty(SWT.Modify).observe(dateCombo);

Matthew
Comment 8 Matthew Hall CLA 2009-01-22 18:42:36 EST
(In reply to comment #7)
> When 3.5 lands

That is, when 3.5M5 lands
Comment 9 Pascal Leclercq CLA 2009-02-02 15:47:04 EST
Hi,
I have no satisfactory answer to give. We noticed that sometimes,  in Java 1.4 the date parsed by the simpleDateFormat provided with the DateChooser combo has a negative timestamp.

The only workaround we found is to parse "once again" the date a different SimpleDateFormat inside the "handleEvent" method of the "updateListener" Object.
I'm not very happy of this but it work for months now.

Maybe, a better solution could be obtained using a special implementation of the "DateFormatter". But I don't have a lot of time to tests many different cases.

DefaultFormatterFactory.register(Date.class, MyOwnDateFormatter.class);


@+
Comment 10 Matthew Hall CLA 2009-03-16 17:34:49 EDT
As of 3.5M6 here is a shorter property implementation for DateChooser#selection:

public class DateChooserComboSelectionProperty extends WidgetValueProperty {
  public DateChooserComboSelectionProperty(int event) {
    super(checkEvents(event), getStaleEvents(event) );
  }

  private static int[] checkEvents(int event) {
    if (!(event == SWT.None || event == SWT.FocusOut || event == SWT.Modify))
      throw new IllegalArgumentException(
         "UpdateEventType [" + updateEventType + //$NON-NLS-1$
         "] is not supported."); //$NON-NLS-1$
    return event;
  }

  private static int[] getStaleEvents(int event) {
    if (event == SWT.FocusOut)
      return new int[] { SWT.Modify };
    return null;
  }

  public Object getValueType() {
    return Date.class;
  }

  protected Object doGetValue(Object source) {
    return ((DateChooserCombo)source).getValue();
  }

  protected void doSetValue(Object source, Object value) {
    ((DateChooserCombo)source).setValue((Date) value);
  }
}

The getStaleEvents() method ensures that SWT.FocusOut observables are stale after the selection is changed but before focus leaves the field.  This helps prevent data-bound forms from completing before the selection has been validated and copied to model, e.g. pressing the Enter key in a wizard could invoke the Finish button.
Comment 11 Eric Wuillai CLA 2010-03-15 18:31:50 EDT
I published implementations of ObservableValue for DateChooser and DateChooserCombo that seems to work for my RCP Application. Those implementations have some differences with the one provided in attachment.
Snippets are available too.

DataBinding plugins are declared as optional dependencies in the plugin. So there will be know classpath problem for applications that does not use DataBinding.
Comment 12 Matthew Hall CLA 2010-03-22 02:35:26 EDT
(In reply to comment #11)
> DataBinding plugins are declared as optional dependencies in the plugin. So
> there will be know classpath problem for applications that does not use
> DataBinding.

This is exactly how we plan to add DataBinding support for certain features in the workbench going forward.
Comment 13 Wim Jongman CLA 2013-06-21 16:17:26 EDT
CalendarCombo will be archived june 30 2013.
Please update your software to use Nebula CDateTime or SWT DateTime.
Closing as WONTFIX.