From: Jens Jansson Date: Mon, 30 Jan 2012 13:44:01 +0000 (+0200) Subject: Splitted VPopupCalendar to Widget and Paintable. X-Git-Tag: 7.0.0.alpha2~511^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=96c14e5d39129629d3453c17e073d178878d8dba;p=vaadin-framework.git Splitted VPopupCalendar to Widget and Paintable. --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java index 44fb9ac69c..223e13c8d7 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java @@ -21,16 +21,10 @@ import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.PopupPanel; import com.google.gwt.user.client.ui.PopupPanel.PositionCallback; -import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.DateTimeService; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VConsole; -import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusChangeListener; import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusOutListener; import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.SubmitListener; -import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.TimeChangeListener; /** * Represents a date selection component with a text field and a popup date @@ -42,19 +36,19 @@ import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.TimeChangeListener; * setCalendarPanel(VCalendarPanel panel) method. * */ -public class VPopupCalendar extends VTextualDate implements VPaintableWidget, - Field, ClickHandler, CloseHandler, SubPartAware { +public class VPopupCalendar extends VTextualDate implements Field, + ClickHandler, CloseHandler, SubPartAware { - private static final String POPUP_PRIMARY_STYLE_NAME = VDateField.CLASSNAME + protected static final String POPUP_PRIMARY_STYLE_NAME = VDateField.CLASSNAME + "-popup"; - private final Button calendarToggle; + protected final Button calendarToggle; - private VCalendarPanel calendar; + protected VCalendarPanel calendar; - private final VOverlay popup; + protected final VOverlay popup; private boolean open = false; - private boolean parsable = true; + protected boolean parsable = true; public VPopupCalendar() { super(); @@ -105,7 +99,7 @@ public class VPopupCalendar extends VTextualDate implements VPaintableWidget, } @SuppressWarnings("deprecation") - private void updateValue(Date newDate) { + protected void updateValue(Date newDate) { Date currentDate = getCurrentDate(); if (currentDate == null || newDate.getTime() != currentDate.getTime()) { setCurrentDate((Date) newDate.clone()); @@ -137,96 +131,6 @@ public class VPopupCalendar extends VTextualDate implements VPaintableWidget, } } - /* - * (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 = readonly; - boolean lastEnabledState = isEnabled(); - - parsable = uidl.getBooleanAttribute("parsable"); - - super.updateFromUIDL(uidl, client); - - String popupStyleNames = ApplicationConnection.getStyleName( - POPUP_PRIMARY_STYLE_NAME, uidl, false); - popupStyleNames += " " + VDateField.CLASSNAME + "-" - + resolutionToString(currentResolution); - popup.setStyleName(popupStyleNames); - - calendar.setDateTimeService(getDateTimeService()); - calendar.setShowISOWeekNumbers(isShowISOWeekNumbers()); - if (calendar.getResolution() != currentResolution) { - calendar.setResolution(currentResolution); - if (calendar.getDate() != null) { - calendar.setDate((Date) getCurrentDate().clone()); - // force re-render when changing resolution only - calendar.renderCalendar(); - } - } - calendarToggle.setEnabled(enabled); - - if (currentResolution <= RESOLUTION_MONTH) { - calendar.setFocusChangeListener(new FocusChangeListener() { - public void focusChanged(Date date) { - updateValue(date); - buildDate(); - Date date2 = calendar.getDate(); - date2.setYear(date.getYear()); - date2.setMonth(date.getMonth()); - } - }); - } else { - calendar.setFocusChangeListener(null); - } - - if (currentResolution > RESOLUTION_DAY) { - calendar.setTimeChangeListener(new TimeChangeListener() { - public void changed(int hour, int min, int sec, int msec) { - Date d = getDate(); - if (d == null) { - // date currently null, use the value from calendarPanel - // (~ client time at the init of the widget) - d = (Date) calendar.getDate().clone(); - } - d.setHours(hour); - d.setMinutes(min); - d.setSeconds(sec); - DateTimeService.setMilliseconds(d, msec); - - // Always update time changes to the server - updateValue(d); - - // Update text field - buildDate(); - } - }); - } - - if (readonly) { - calendarToggle.addStyleName(CLASSNAME + "-button-readonly"); - } else { - calendarToggle.removeStyleName(CLASSNAME + "-button-readonly"); - } - - if (lastReadOnlyState != readonly || lastEnabledState != 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) - updateWidth(); - } - - calendarToggle.setEnabled(true); - } - /* * (non-Javadoc) * diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendarPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendarPaintable.java new file mode 100644 index 0000000000..96e966a993 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendarPaintable.java @@ -0,0 +1,138 @@ +/* +@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(); + } +} diff --git a/src/com/vaadin/ui/DateField.java b/src/com/vaadin/ui/DateField.java index b3f54a0a78..9589414f4d 100644 --- a/src/com/vaadin/ui/DateField.java +++ b/src/com/vaadin/ui/DateField.java @@ -27,7 +27,7 @@ import com.vaadin.event.FieldEvents.FocusListener; 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; /** *

@@ -50,7 +50,7 @@ import com.vaadin.terminal.gwt.client.ui.VPopupCalendar; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(VPopupCalendar.class) +@ClientWidget(VPopupCalendarPaintable.class) public class DateField extends AbstractField implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier {