]> source.dussan.org Git - vaadin-framework.git/commitdiff
Delay sending DateField popup value to server until popup is closed #6252
authorJohn Ahlroos <john@vaadin.com>
Fri, 9 Aug 2013 07:59:11 +0000 (10:59 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 9 Aug 2013 08:31:47 +0000 (08:31 +0000)
Change-Id: Ib6f4681ea38fe7a6cac8a44bc4ab4b23151844dd

client/src/com/vaadin/client/ui/VPopupCalendar.java
client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java
uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldValueChangeEvents.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldValueChangeEvents.java [new file with mode: 0644]

index e431da127d4256fe50a2641a193ff212b05461c8..57a0222118fba7e9f87de5de54f8c49c7e30e3d6 100644 (file)
@@ -217,9 +217,6 @@ public class VPopupCalendar extends VTextualDate implements Field,
                     }
                 }
             }
-            if (isImmediate()) {
-                getClient().sendPendingVariableChanges();
-            }
         }
     }
 
index 7257af4a08bc56980310767870df0bab151da878..627478ebe5778f9c62d32a00246f6446a2eba028 100644 (file)
@@ -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<PopupPanel>() {
+
+            @Override
+            public void onClose(CloseEvent<PopupPanel> 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 (file)
index 0000000..18f0ce0
--- /dev/null
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:7171/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.datefield.PopupDateFieldValueChangeEvents?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[0]/VPopupCalendar[0]#popupButton</td>
+       <td>12,11</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[2]/td/table/tbody/tr[4]/td[3]/span</td>
+       <td>18,12</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]/domChild[0]</td>
+       <td>Value changes: 1</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[0]/VPopupCalendar[0]#popupButton</td>
+       <td>12,11</td>
+</tr>
+<tr>
+       <td>select</td>
+       <td>//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[3]/td/div/select</td>
+       <td>label=01</td>
+</tr>
+<tr>
+       <td>select</td>
+       <td>//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[3]/td/div/select[2]</td>
+       <td>label=02</td>
+</tr>
+<tr>
+       <td>select</td>
+       <td>//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[3]/td/div/select[3]</td>
+       <td>label=03</td>
+</tr>
+<tr>
+       <td>pressSpecialKey</td>
+       <td>//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[3]/td/div/select[3]</td>
+       <td>enter</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[0]/VLabel[0]</td>
+       <td>410,9</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]/domChild[0]</td>
+       <td>Value changes: 2</td>
+</tr>
+<tr>
+       <td>select</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[1]/VNativeSelect[0]/domChild[0]</td>
+       <td>label=MONTH</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[0]/VPopupCalendar[0]#popupButton</td>
+       <td>14,9</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>xpath=(//button[@type='button'])[4]</td>
+       <td>3,13</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>xpath=(//button[@type='button'])[5]</td>
+       <td>9,6</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>xpath=(//button[@type='button'])[4]</td>
+       <td>7,8</td>
+</tr>
+<tr>
+       <td>pressSpecialKey</td>
+       <td>xpath=(//button[@type='button'])[4]</td>
+       <td>enter</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldValueChangeEvents::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]/domChild[0]</td>
+       <td>Value changes: 3</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
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 (file)
index 0000000..b875d86
--- /dev/null
@@ -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;
+    }
+
+}