123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- /*
- @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.LocaleNotLoadedException;
- import com.vaadin.terminal.gwt.client.UIDL;
- import com.vaadin.terminal.gwt.client.VConsole;
-
- public class AbstractDateFieldConnector extends AbstractComponentConnector {
-
- @Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- // Ensure correct implementation and let layout manage caption
- super.updateFromUIDL(uidl, client);
- if (!isRealUpdate(uidl)) {
- return;
- }
-
- // Save details
- getWidget().client = client;
- getWidget().paintableId = uidl.getId();
- getWidget().immediate = getState().isImmediate();
-
- getWidget().readonly = getState().isReadOnly();
- getWidget().enabled = !getState().isDisabled();
-
- if (uidl.hasAttribute("locale")) {
- final String locale = uidl.getStringAttribute("locale");
- try {
- getWidget().dts.setLocale(locale);
- getWidget().currentLocale = locale;
- } catch (final LocaleNotLoadedException e) {
- getWidget().currentLocale = getWidget().dts.getLocale();
- VConsole.error("Tried to use an unloaded locale \"" + locale
- + "\". Using default locale ("
- + getWidget().currentLocale + ").");
- VConsole.error(e);
- }
- }
-
- // We show week numbers only if the week starts with Monday, as ISO 8601
- // specifies
- getWidget().showISOWeekNumbers = uidl
- .getBooleanAttribute(VDateField.WEEK_NUMBERS)
- && getWidget().dts.getFirstDayOfWeek() == 1;
-
- int newResolution;
- if (uidl.hasVariable("sec")) {
- newResolution = VDateField.RESOLUTION_SEC;
- } else if (uidl.hasVariable("min")) {
- newResolution = VDateField.RESOLUTION_MIN;
- } else if (uidl.hasVariable("hour")) {
- newResolution = VDateField.RESOLUTION_HOUR;
- } else if (uidl.hasVariable("day")) {
- newResolution = VDateField.RESOLUTION_DAY;
- } else if (uidl.hasVariable("month")) {
- newResolution = VDateField.RESOLUTION_MONTH;
- } else {
- newResolution = VDateField.RESOLUTION_YEAR;
- }
-
- getWidget().currentResolution = newResolution;
-
- // Add stylename that indicates current resolution
- getWidget()
- .addStyleName(
- VDateField.CLASSNAME
- + "-"
- + VDateField
- .resolutionToString(getWidget().currentResolution));
-
- final int year = uidl.getIntVariable("year");
- final int month = (getWidget().currentResolution >= VDateField.RESOLUTION_MONTH) ? uidl
- .getIntVariable("month") : -1;
- final int day = (getWidget().currentResolution >= VDateField.RESOLUTION_DAY) ? uidl
- .getIntVariable("day") : -1;
- final int hour = (getWidget().currentResolution >= VDateField.RESOLUTION_HOUR) ? uidl
- .getIntVariable("hour") : 0;
- final int min = (getWidget().currentResolution >= VDateField.RESOLUTION_MIN) ? uidl
- .getIntVariable("min") : 0;
- final int sec = (getWidget().currentResolution >= VDateField.RESOLUTION_SEC) ? uidl
- .getIntVariable("sec") : 0;
-
- // Construct new date for this datefield (only if not null)
- if (year > -1) {
- getWidget().setCurrentDate(
- new Date((long) getWidget().getTime(year, month, day, hour,
- min, sec, 0)));
- } else {
- getWidget().setCurrentDate(null);
- }
- }
-
- @Override
- protected Widget createWidget() {
- return GWT.create(VDateField.class);
- }
-
- @Override
- public VDateField getWidget() {
- return (VDateField) super.getWidget();
- }
- }
|