From: John Ahlroos Date: Fri, 9 Aug 2013 07:59:11 +0000 (+0300) Subject: Delay sending DateField popup value to server until popup is closed #6252 X-Git-Tag: 7.1.4~42 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c7a48ae008d0c2a168635b863fe2e44d708c4b02;p=vaadin-framework.git Delay sending DateField popup value to server until popup is closed #6252 Change-Id: Ib6f4681ea38fe7a6cac8a44bc4ab4b23151844dd --- diff --git a/client/src/com/vaadin/client/ui/VPopupCalendar.java b/client/src/com/vaadin/client/ui/VPopupCalendar.java index e431da127d..57a0222118 100644 --- a/client/src/com/vaadin/client/ui/VPopupCalendar.java +++ b/client/src/com/vaadin/client/ui/VPopupCalendar.java @@ -217,9 +217,6 @@ public class VPopupCalendar extends VTextualDate implements Field, } } } - if (isImmediate()) { - getClient().sendPendingVariableChanges(); - } } } diff --git a/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java b/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java index 7257af4a08..627478ebe5 100644 --- a/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java +++ b/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java @@ -18,6 +18,9 @@ package com.vaadin.client.ui.datefield; import java.util.Date; +import com.google.gwt.event.logical.shared.CloseEvent; +import com.google.gwt.event.logical.shared.CloseHandler; +import com.google.gwt.user.client.ui.PopupPanel; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.DateTimeService; import com.vaadin.client.UIDL; @@ -33,6 +36,35 @@ import com.vaadin.ui.DateField; @Connect(DateField.class) public class PopupDateFieldConnector extends TextualDateConnector { + /* + * (non-Javadoc) + * + * @see com.vaadin.client.ui.AbstractConnector#init() + */ + @Override + protected void init() { + getWidget().popup.addCloseHandler(new CloseHandler() { + + @Override + public void onClose(CloseEvent event) { + /* + * FIXME This is a hack so we do not have to rewrite half of the + * datefield so values are not sent while selecting a date + * (#6252). + * + * The datefield will now only set the date UIDL variables while + * the user is selecting year/month/date/time and not send them + * directly. Only when the user closes the popup (by clicking on + * a day/enter/clicking outside of popup) then the new value is + * communicated to the server. + */ + if (getWidget().isImmediate()) { + getConnection().sendPendingVariableChanges(); + } + } + }); + } + /* * (non-Javadoc) * diff --git a/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldValueChangeEvents.html b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldValueChangeEvents.html new file mode 100644 index 0000000000..18f0ce0da2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldValueChangeEvents.html @@ -0,0 +1,107 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.datefield.PopupDateFieldValueChangeEvents?restartApplication
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[0]/VPopupCalendar[0]#popupButton12,11
mouseClick//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[2]/td/table/tbody/tr[4]/td[3]/span18,12
assertTextvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]/domChild[0]Value changes: 1
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[0]/VPopupCalendar[0]#popupButton12,11
select//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[3]/td/div/selectlabel=01
select//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[3]/td/div/select[2]label=02
select//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[3]/td/div/select[3]label=03
pressSpecialKey//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[3]/td/div/select[3]enter
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[0]/VLabel[0]410,9
assertTextvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]/domChild[0]Value changes: 2
selectvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[1]/VNativeSelect[0]/domChild[0]label=MONTH
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[0]/VPopupCalendar[0]#popupButton14,9
mouseClickxpath=(//button[@type='button'])[4]3,13
mouseClickxpath=(//button[@type='button'])[5]9,6
mouseClickxpath=(//button[@type='button'])[4]7,8
pressSpecialKeyxpath=(//button[@type='button'])[4]enter
assertTextvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]/domChild[0]Value changes: 3
+ + diff --git a/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldValueChangeEvents.java b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldValueChangeEvents.java new file mode 100644 index 0000000000..b875d86428 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldValueChangeEvents.java @@ -0,0 +1,112 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +/** + * + */ +package com.vaadin.tests.components.datefield; + +import java.util.Arrays; +import java.util.Calendar; + +import com.vaadin.data.Property; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.datefield.Resolution; +import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.DateField; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.NativeSelect; + +/** + * + * @since + * @author Vaadin Ltd + */ +public class PopupDateFieldValueChangeEvents extends AbstractTestUI { + + private int count = 0; + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server. + * VaadinRequest) + */ + @Override + protected void setup(VaadinRequest request) { + + HorizontalLayout hl = new HorizontalLayout(); + addComponent(hl); + + Calendar calendar = Calendar.getInstance(); + calendar.set(2010, 1, 1, 18, 19, 20); + + final DateField df = new DateField(null, calendar.getTime()); + df.setResolution(Resolution.SECOND); + df.setImmediate(true); + hl.addComponent(df); + + NativeSelect resolution = new NativeSelect(null, + Arrays.asList(Resolution.values())); + resolution.setImmediate(true); + resolution.setValue(df.getResolution()); + hl.addComponent(resolution); + resolution.addValueChangeListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + df.setResolution((Resolution) event.getProperty().getValue()); + } + }); + + final Label log = new Label("", ContentMode.PREFORMATTED); + addComponent(log); + + df.addValueChangeListener(new Property.ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + log.setValue("Value changes: " + (++count)); + + } + }); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription() + */ + @Override + protected String getTestDescription() { + return "DateField Time resolution fields should only send events when focus is removed"; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber() + */ + @Override + protected Integer getTicketNumber() { + return 6252; + } + +}