Community
Participate
Working Groups
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:
You didn't attach any patch!
... and the wrong component, moving to Nebula :-)
..and Tom forgot to check "Reassign bug to default assignee and QA contact, and add Default CC of selected component".
I assume this is not for CalendarCombo, so I probably shouldn't be the target of "Assigned To" :)
Created attachment 112351 [details] DB Observable for DateChooserCombo Nebula widget
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
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
(In reply to comment #7) > When 3.5 lands That is, when 3.5M5 lands
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); @+
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.
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.
(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.
CalendarCombo will be archived june 30 2013. Please update your software to use Nebula CDateTime or SWT DateTime. Closing as WONTFIX.