private long normalize(long date) {
   if (date == 0) return 0;
   Calendar c = Calendar.getInstance();
   c.setTimeInMillis(date);
   DateTimeUtil.resetHours(c);
   return c.getTimeInMillis();
 }
 public void modifyText(ModifyEvent e) {
   String s = text.getText();
   long date;
   if (s.length() == 0) {
     date = 0;
     setValid(allowEmpty);
     if (!allowEmpty) return;
   } else {
     date = DateTimeUtil.getDateFromString(s);
     if (date == 0 || date < min || date > max) {
       setValid(false);
       return;
     } else setValid(true);
   }
   if (DateControl.this.date != date) {
     DateControl.this.date = date;
     dateChanged.fire(date);
   }
 }
 public void fire(Object event) {
   FlatPopupMenu dlg = new FlatPopupMenu(button, null, true, false, false, false);
   DateTime ctrl = new DateTime(dlg.getControl(), SWT.CALENDAR | SWT.LONG);
   long date = DateTimeUtil.getDateFromString(text.getText());
   if (date != 0) {
     Calendar c = Calendar.getInstance();
     c.setTimeInMillis(date);
     ctrl.setYear(c.get(Calendar.YEAR));
     ctrl.setMonth(c.get(Calendar.MONTH));
     ctrl.setDay(c.get(Calendar.DAY_OF_MONTH));
   }
   ctrl.addSelectionListener(
       new SelectionListenerWithData<DateTime>(ctrl) {
         public void widgetSelected(SelectionEvent e) {
           Calendar c = Calendar.getInstance();
           c.set(Calendar.YEAR, data().getYear());
           c.set(Calendar.MONTH, data().getMonth());
           c.set(Calendar.DAY_OF_MONTH, data().getDay());
           text.setText(DateTimeUtil.getDateString(c.getTimeInMillis()));
         }
       });
   dlg.show(button, FlatPopupMenu.Orientation.BOTTOM, true);
 }
 private void setDateText(long date) {
   if (date == 0) text.setText("");
   else text.setText(DateTimeUtil.getDateString(date));
 }