import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.DomEvent;
import com.google.gwt.event.dom.client.KeyCodes;
+import com.google.gwt.event.dom.client.MouseOutEvent;
+import com.google.gwt.event.dom.client.MouseOutHandler;
+import com.google.gwt.event.dom.client.MouseOverEvent;
+import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
private boolean open = false;
+ /*
+ * #14857: If calendarToggle button is clicked when calendar popup is
+ * already open we should prevent calling openCalendarPanel() in onClick,
+ * since we don't want to reopen it again right after it closes.
+ */
+ private boolean preventOpenPopupCalendar = false;
+ private boolean cursorOverCalendarToggleButton = false;
+ private boolean toggleButtonClosesWithGuarantee = false;
+
private boolean textFieldEnabled = true;
private String captionId;
calendarToggle.setText("");
calendarToggle.addClickHandler(this);
+
+ calendarToggle.addDomHandler(new MouseOverHandler() {
+ @Override
+ public void onMouseOver(MouseOverEvent event) {
+ cursorOverCalendarToggleButton = true;
+ }
+ }, MouseOverEvent.getType());
+
+ calendarToggle.addDomHandler(new MouseOutHandler() {
+ @Override
+ public void onMouseOut(MouseOutEvent event) {
+ cursorOverCalendarToggleButton = false;
+ }
+ }, MouseOutEvent.getType());
+
// -2 instead of -1 to avoid FocusWidget.onAttach to reset it
calendarToggle.getElement().setTabIndex(-2);
@Override
public void onClick(ClickEvent event) {
if (event.getSource() == calendarToggle && isEnabled()) {
- openCalendarPanel();
+ if (!preventOpenPopupCalendar) {
+ openCalendarPanel();
+ }
+ preventOpenPopupCalendar = false;
}
}
focus();
}
- // TODO resolve what the "Sigh." is all about and document it here
- // Sigh.
- Timer t = new Timer() {
- @Override
- public void run() {
- open = false;
- }
- };
- t.schedule(100);
+ open = false;
+
+ if (cursorOverCalendarToggleButton
+ && !toggleButtonClosesWithGuarantee) {
+ preventOpenPopupCalendar = true;
+ }
+
+ toggleButtonClosesWithGuarantee = false;
}
}
*/
public void closeCalendarPanel() {
if (open) {
+ toggleButtonClosesWithGuarantee = true;
popup.hide(true);
}
}
--- /dev/null
+/*
+ * Copyright 2000-2014 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 com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.DateField;
+
+public class DateFieldPopupClosing extends AbstractTestUI {
+
+ static final String DATEFIELD_ID = "datefield";
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final DateField df = new DateField();
+ df.setId(DATEFIELD_ID);
+ addComponent(df);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "DateField popup should be closed when click on popup button";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 14857;
+ }
+
+}
--- /dev/null
+package com.vaadin.tests.components.datefield;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+
+import com.vaadin.testbench.elements.DateFieldElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class DateFieldPopupClosingTest extends MultiBrowserTest {
+
+ @Test
+ public void testDateFieldPopupClosingLongClick()
+ throws InterruptedException, IOException {
+ openTestURL();
+
+ fastClickDateDatePickerButton();
+
+ assertThatPopupIsVisible();
+
+ longClickDateDatePickerButton();
+
+ assertThatPopupIsInvisible();
+ }
+
+ private void assertThatPopupIsVisible() {
+ waitUntil(ExpectedConditions.visibilityOfElementLocated(By
+ .className("v-datefield-popup")));
+ }
+
+ private void assertThatPopupIsInvisible() {
+ // ExpectedConditions.invisibilityOfElementLocated doesn't work
+ // with PhantomJS when running with a hub:
+ // https://code.google.com/p/selenium/issues/detail?id=5000
+ // so we need to make our own.
+
+ waitUntil(new ExpectedCondition<Boolean>() {
+ @Override
+ public Boolean apply(WebDriver input) {
+ try {
+ return !(findElement(By.className("v-datefield-popup"))
+ .isDisplayed());
+ } catch (Exception e) {
+ return true;
+ }
+ }
+
+ @Override
+ public String toString() {
+ // Timed out after 10 seconds waiting for ...
+ return "popup to not be visible";
+ }
+ });
+ }
+
+ private void longClickDateDatePickerButton() {
+ WebElement button = getToggleButton();
+
+ new Actions(getDriver()).clickAndHold(button).perform();
+ assertThatPopupIsInvisible();
+
+ new Actions(getDriver()).release(button).perform();
+ }
+
+ private WebElement getToggleButton() {
+ DateFieldElement dateField = $(DateFieldElement.class).first();
+
+ return dateField.findElement(By.tagName("button"));
+ }
+
+ private void fastClickDateDatePickerButton() {
+ getToggleButton().click();
+ }
+
+}
\ No newline at end of file