import com.google.gwt.user.client.ui.Button;\r
import com.google.gwt.user.client.ui.PopupPanel;\r
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;\r
-import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
import com.vaadin.terminal.gwt.client.BrowserInfo;\r
-import com.vaadin.terminal.gwt.client.DateTimeService;\r
-import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
-import com.vaadin.terminal.gwt.client.UIDL;\r
import com.vaadin.terminal.gwt.client.VConsole;\r
-import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusChangeListener;\r
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusOutListener;\r
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.SubmitListener;\r
-import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.TimeChangeListener;\r
\r
/**\r
* Represents a date selection component with a text field and a popup date\r
* <code>setCalendarPanel(VCalendarPanel panel)</code> method.\r
* \r
*/\r
-public class VPopupCalendar extends VTextualDate implements VPaintableWidget,\r
- Field, ClickHandler, CloseHandler<PopupPanel>, SubPartAware {\r
+public class VPopupCalendar extends VTextualDate implements Field,\r
+ ClickHandler, CloseHandler<PopupPanel>, SubPartAware {\r
\r
- private static final String POPUP_PRIMARY_STYLE_NAME = VDateField.CLASSNAME\r
+ protected static final String POPUP_PRIMARY_STYLE_NAME = VDateField.CLASSNAME\r
+ "-popup";\r
\r
- private final Button calendarToggle;\r
+ protected final Button calendarToggle;\r
\r
- private VCalendarPanel calendar;\r
+ protected VCalendarPanel calendar;\r
\r
- private final VOverlay popup;\r
+ protected final VOverlay popup;\r
private boolean open = false;\r
- private boolean parsable = true;\r
+ protected boolean parsable = true;\r
\r
public VPopupCalendar() {\r
super();\r
}\r
\r
@SuppressWarnings("deprecation")\r
- private void updateValue(Date newDate) {\r
+ protected void updateValue(Date newDate) {\r
Date currentDate = getCurrentDate();\r
if (currentDate == null || newDate.getTime() != currentDate.getTime()) {\r
setCurrentDate((Date) newDate.clone());\r
}\r
}\r
\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see\r
- * com.vaadin.terminal.gwt.client.ui.VTextualDate#updateFromUIDL(com.vaadin\r
- * .terminal.gwt.client.UIDL,\r
- * com.vaadin.terminal.gwt.client.ApplicationConnection)\r
- */\r
- @Override\r
- @SuppressWarnings("deprecation")\r
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
- boolean lastReadOnlyState = readonly;\r
- boolean lastEnabledState = isEnabled();\r
-\r
- parsable = uidl.getBooleanAttribute("parsable");\r
-\r
- super.updateFromUIDL(uidl, client);\r
-\r
- String popupStyleNames = ApplicationConnection.getStyleName(\r
- POPUP_PRIMARY_STYLE_NAME, uidl, false);\r
- popupStyleNames += " " + VDateField.CLASSNAME + "-"\r
- + resolutionToString(currentResolution);\r
- popup.setStyleName(popupStyleNames);\r
-\r
- calendar.setDateTimeService(getDateTimeService());\r
- calendar.setShowISOWeekNumbers(isShowISOWeekNumbers());\r
- if (calendar.getResolution() != currentResolution) {\r
- calendar.setResolution(currentResolution);\r
- if (calendar.getDate() != null) {\r
- calendar.setDate((Date) getCurrentDate().clone());\r
- // force re-render when changing resolution only\r
- calendar.renderCalendar();\r
- }\r
- }\r
- calendarToggle.setEnabled(enabled);\r
-\r
- if (currentResolution <= RESOLUTION_MONTH) {\r
- calendar.setFocusChangeListener(new FocusChangeListener() {\r
- public void focusChanged(Date date) {\r
- updateValue(date);\r
- buildDate();\r
- Date date2 = calendar.getDate();\r
- date2.setYear(date.getYear());\r
- date2.setMonth(date.getMonth());\r
- }\r
- });\r
- } else {\r
- calendar.setFocusChangeListener(null);\r
- }\r
-\r
- if (currentResolution > RESOLUTION_DAY) {\r
- calendar.setTimeChangeListener(new TimeChangeListener() {\r
- public void changed(int hour, int min, int sec, int msec) {\r
- Date d = getDate();\r
- if (d == null) {\r
- // date currently null, use the value from calendarPanel\r
- // (~ client time at the init of the widget)\r
- d = (Date) calendar.getDate().clone();\r
- }\r
- d.setHours(hour);\r
- d.setMinutes(min);\r
- d.setSeconds(sec);\r
- DateTimeService.setMilliseconds(d, msec);\r
-\r
- // Always update time changes to the server\r
- updateValue(d);\r
-\r
- // Update text field\r
- buildDate();\r
- }\r
- });\r
- }\r
-\r
- if (readonly) {\r
- calendarToggle.addStyleName(CLASSNAME + "-button-readonly");\r
- } else {\r
- calendarToggle.removeStyleName(CLASSNAME + "-button-readonly");\r
- }\r
-\r
- if (lastReadOnlyState != readonly || lastEnabledState != isEnabled()) {\r
- // Enabled or readonly state changed. Differences in theming might\r
- // affect the width (for instance if the popup button is hidden) so\r
- // we have to recalculate the width (IF the width of the field is\r
- // fixed)\r
- updateWidth();\r
- }\r
-\r
- calendarToggle.setEnabled(true);\r
- }\r
-\r
/*\r
* (non-Javadoc)\r
* \r
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.Date;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.DateTimeService;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusChangeListener;
+import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.TimeChangeListener;
+
+public class VPopupCalendarPaintable extends VTextualDatePaintable {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.terminal.gwt.client.ui.VTextualDate#updateFromUIDL(com.vaadin
+ * .terminal.gwt.client.UIDL,
+ * com.vaadin.terminal.gwt.client.ApplicationConnection)
+ */
+ @Override
+ @SuppressWarnings("deprecation")
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ boolean lastReadOnlyState = getWidgetForPaintable().readonly;
+ boolean lastEnabledState = getWidgetForPaintable().isEnabled();
+
+ getWidgetForPaintable().parsable = uidl.getBooleanAttribute("parsable");
+
+ super.updateFromUIDL(uidl, client);
+
+ String popupStyleNames = ApplicationConnection.getStyleName(
+ VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, uidl, false);
+ popupStyleNames += " "
+ + VDateField.CLASSNAME
+ + "-"
+ + VPopupCalendar
+ .resolutionToString(getWidgetForPaintable().currentResolution);
+ getWidgetForPaintable().popup.setStyleName(popupStyleNames);
+
+ getWidgetForPaintable().calendar
+ .setDateTimeService(getWidgetForPaintable()
+ .getDateTimeService());
+ getWidgetForPaintable().calendar
+ .setShowISOWeekNumbers(getWidgetForPaintable()
+ .isShowISOWeekNumbers());
+ if (getWidgetForPaintable().calendar.getResolution() != getWidgetForPaintable().currentResolution) {
+ getWidgetForPaintable().calendar
+ .setResolution(getWidgetForPaintable().currentResolution);
+ if (getWidgetForPaintable().calendar.getDate() != null) {
+ getWidgetForPaintable().calendar
+ .setDate((Date) getWidgetForPaintable()
+ .getCurrentDate().clone());
+ // force re-render when changing resolution only
+ getWidgetForPaintable().calendar.renderCalendar();
+ }
+ }
+ getWidgetForPaintable().calendarToggle
+ .setEnabled(getWidgetForPaintable().enabled);
+
+ if (getWidgetForPaintable().currentResolution <= VPopupCalendar.RESOLUTION_MONTH) {
+ getWidgetForPaintable().calendar
+ .setFocusChangeListener(new FocusChangeListener() {
+ public void focusChanged(Date date) {
+ getWidgetForPaintable().updateValue(date);
+ getWidgetForPaintable().buildDate();
+ Date date2 = getWidgetForPaintable().calendar
+ .getDate();
+ date2.setYear(date.getYear());
+ date2.setMonth(date.getMonth());
+ }
+ });
+ } else {
+ getWidgetForPaintable().calendar.setFocusChangeListener(null);
+ }
+
+ if (getWidgetForPaintable().currentResolution > VPopupCalendar.RESOLUTION_DAY) {
+ getWidgetForPaintable().calendar
+ .setTimeChangeListener(new TimeChangeListener() {
+ public void changed(int hour, int min, int sec, int msec) {
+ Date d = getWidgetForPaintable().getDate();
+ if (d == null) {
+ // date currently null, use the value from
+ // calendarPanel
+ // (~ client time at the init of the widget)
+ d = (Date) getWidgetForPaintable().calendar
+ .getDate().clone();
+ }
+ d.setHours(hour);
+ d.setMinutes(min);
+ d.setSeconds(sec);
+ DateTimeService.setMilliseconds(d, msec);
+
+ // Always update time changes to the server
+ getWidgetForPaintable().updateValue(d);
+
+ // Update text field
+ getWidgetForPaintable().buildDate();
+ }
+ });
+ }
+
+ if (getWidgetForPaintable().readonly) {
+ getWidgetForPaintable().calendarToggle
+ .addStyleName(VPopupCalendar.CLASSNAME + "-button-readonly");
+ } else {
+ getWidgetForPaintable().calendarToggle
+ .removeStyleName(VPopupCalendar.CLASSNAME
+ + "-button-readonly");
+ }
+
+ if (lastReadOnlyState != getWidgetForPaintable().readonly
+ || lastEnabledState != getWidgetForPaintable().isEnabled()) {
+ // Enabled or readonly state changed. Differences in theming might
+ // affect the width (for instance if the popup button is hidden) so
+ // we have to recalculate the width (IF the width of the field is
+ // fixed)
+ getWidgetForPaintable().updateWidth();
+ }
+
+ getWidgetForPaintable().calendarToggle.setEnabled(true);
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VPopupCalendar.class);
+ }
+
+ @Override
+ public VPopupCalendar getWidgetForPaintable() {
+ return (VPopupCalendar) super.getWidgetForPaintable();
+ }
+}
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.ui.VDateField;
-import com.vaadin.terminal.gwt.client.ui.VPopupCalendar;
+import com.vaadin.terminal.gwt.client.ui.VPopupCalendarPaintable;
/**
* <p>
* @since 3.0
*/
@SuppressWarnings("serial")
-@ClientWidget(VPopupCalendar.class)
+@ClientWidget(VPopupCalendarPaintable.class)
public class DateField extends AbstractField<Date> implements
FieldEvents.BlurNotifier, FieldEvents.FocusNotifier {