Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 205565

Summary: Custom property source (date editor)
Product: [Modeling] EMF Reporter: Krzysztof Daniel <krzysztof.daniel>
Component: CoreAssignee: Ed Merks <Ed.Merks>
Status: CLOSED DUPLICATE QA Contact:
Severity: enhancement    
Priority: P3 CC: ronbermejo
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
URL: http://eclipser-blog.blogspot.com/2007/10/custom-property-source-for-emf.html
Whiteboard:
Attachments:
Description Flags
A patch that incorporates the design ideas...
none
Proposal
none
Proposal 2 none

Description Krzysztof Daniel CLA 2007-10-05 07:54:35 EDT
Ed, as you said, I am putting bugzilla entry with code and link.



public CellEditor createPropertyEditor(Composite composite) {
   CellEditor result = super.createPropertyEditor(composite);
   if(result == null) return result;
   EClassifier eType =         ((EStructuralFeature)itemPropertyDescriptor.getFeature(object)).getEType();
   if (eType instanceof EDataType) {
      EDataType eDataType = (EDataType) eType;
      if(eDataType.getInstanceClass() == Date.class){
         result = new ExtendedDialogCellEditor(composite, getEditLabelProvider()){
             protected Object openDialogBox(Control cellEditorWindow) {
                final DateTime dateTime[] = new DateTime[1];
                final Date[] date = new Date[1];
                Dialog d = new Dialog(cellEditorWindow.getShell()){
                   protected Control createDialogArea(Composite parent) {
                      Composite dialogArea = (Composite) super.createDialogArea(parent);
                      dateTime[0] = new DateTime(dialogArea, SWT.CALENDAR);
                      dateTime[0].addSelectionListener(new SelectionAdapter(){
                          public void widgetSelected(SelectionEvent e) {
                              Date dateValue = new Date();
                              dateValue.setYear(dateTime[0].getYear());
                              dateValue.setMonth(dateTime[0].getMonth());
                              dateValue.setDate(dateTime[0].getDay());
                              date[0] = dateValue;
                              super.widgetSelected(e);
                           }
                      });
                      return dialogArea;
                   }
                };
               d.setBlockOnOpen(true);
               d.open();
               if(d.getReturnCode() == Dialog.OK){
                  return date[0];
               }
               return null;
            }
         };
      }
   }
   return result;
}
Comment 1 Nick Boldt CLA 2007-10-05 10:45:28 EDT
Move out of doc so Ed will see it.
Comment 2 Ed Merks CLA 2007-10-06 09:50:10 EDT
Created attachment 79847 [details]
A patch that incorporates the design ideas...

Unfortunately a java.util.Date also includes a time, not just a calendar date and CALENDAR doesn't let you set that.  The TIME and DATE dialogs are very crude and don't even appear to be formatted quite right, i.e., the text in the widget is too close to the bottom of the display field.  So I'm not sure we can use this directly.  It will require more thought.
Comment 3 Krzysztof Daniel CLA 2007-10-22 05:23:51 EDT
Created attachment 80864 [details]
Proposal

Ed, and maybe somthing like that?
If this is to raw maybe it could be a good idea to add labels and position time belowe the date?
Comment 4 Ed Merks CLA 2007-10-23 05:53:04 EDT
Yes, that seems nicer.  One could even imagine launching a calendar control to set the date part of it.  XML Schema dateTime even allows arbitrary precision fractional seconds...
Comment 5 Krzysztof Daniel CLA 2007-11-19 08:16:03 EST
Created attachment 83229 [details]
Proposal 2

And what about this layout?
Comment 6 Krzysztof Daniel CLA 2008-01-09 04:11:41 EST
Ed, could you review this layout?
Comment 7 Ed Merks CLA 2008-01-09 07:11:33 EST
Christopher,

That's very nice!  It's prefect for java.util.Date.

To fully support XMLGregorianCalendar you'd somehow need to deal with fractional time and with timezones:

http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/datatype/XMLGregorianCalendar.html#getFractionalSecond()
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/datatype/XMLGregorianCalendar.html#getTimezone()

And of course there's a whole whack of similar XML Schema types like gYear.  Dealing with date, dateTime, and time are the most important ones...

It would be nice to have some type of registration mechanism for cell editors as described in https://bugs.eclipse.org/bugs/show_bug.cgi?id=205432...
Comment 8 Ed Merks CLA 2018-02-09 06:39:17 EST
In https://bugs.eclipse.org/bugs/show_bug.cgi?id=438123 I've implemented very flexible support that uses Nebula's CDateTime widget.

*** This bug has been marked as a duplicate of bug 438123 ***