From f3ae913aa05fedd33c5b706f75cf6c37310a3f84 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 4 Aug 2015 00:16:04 +0300 Subject: [PATCH] Fix NPE when clicking and move handler is not set (#8718) Change-Id: I13dfe9344d7ca516d41145e4c35fc45c620cac56 --- .../ui/calendar/schedule/DateCellDayEvent.java | 9 +++++++-- .../ui/calendar/schedule/SimpleDayCell.java | 7 +++++-- .../components/calendar/NullEventMoveHandler.java | 14 ++++++++++++-- .../calendar/NullEventMoveHandlerTest.java | 15 +++++++++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java b/client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java index 1a54fe0454..55834397d3 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java @@ -268,8 +268,13 @@ public class DateCellDayEvent extends FocusableHTML implements } int endX = event.getClientX(); int endY = event.getClientY(); - int xDiff = startX - endX; - int yDiff = startY - endY; + int xDiff = 0, yDiff = 0; + if (startX != -1 && startY != -1) { + // Drag started + xDiff = startX - endX; + yDiff = startY - endY; + } + startX = -1; startY = -1; mouseMoveStarted = false; diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java b/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java index 3bf6930933..158241337b 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java @@ -392,8 +392,11 @@ public class SimpleDayCell extends FocusableFlowPanel implements int endX = event.getClientX(); int endY = event.getClientY(); - int xDiff = startX - endX; - int yDiff = startY - endY; + int xDiff = 0, yDiff = 0; + if (startX != -1 && startY != -1) { + xDiff = startX - endX; + yDiff = startY - endY; + } startX = -1; startY = -1; prevDayDiff = 0; diff --git a/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandler.java b/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandler.java index c2dfdb26c1..40dd43abb2 100644 --- a/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandler.java +++ b/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandler.java @@ -5,17 +5,27 @@ import java.text.SimpleDateFormat; import java.util.Locale; import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.Calendar; import com.vaadin.ui.components.calendar.CalendarComponentEvents; +import com.vaadin.ui.components.calendar.CalendarComponentEvents.EventClick; +import com.vaadin.ui.components.calendar.CalendarComponentEvents.EventClickHandler; import com.vaadin.ui.components.calendar.event.BasicEvent; -public class NullEventMoveHandler extends AbstractTestUI { +public class NullEventMoveHandler extends AbstractTestUIWithLog { @Override protected void setup(VaadinRequest request) { Calendar calendar = getCalendar(); calendar.setHandler((CalendarComponentEvents.EventMoveHandler) null); + calendar.setHandler(new EventClickHandler() { + + @Override + public void eventClick(EventClick event) { + log("Clicked on " + event.getCalendarEvent().getCaption()); + + } + }); addComponent(calendar); } diff --git a/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandlerTest.java b/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandlerTest.java index c40cd9ce97..156100310c 100644 --- a/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandlerTest.java +++ b/uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandlerTest.java @@ -3,6 +3,7 @@ package com.vaadin.tests.components.calendar; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; +import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; @@ -22,12 +23,26 @@ public class NullEventMoveHandlerTest extends DndActionsTest { assertEventCannotBeMoved(); } + @Test + public void eventIsClickableWhenNotMovableInMonthView() { + getEvent().click(); + Assert.assertEquals("1. Clicked on foo", getLogRow(0)); + } + @Test public void eventIsNotMovableInWeekView() { openWeekView(); assertEventCannotBeMoved(); } + @Test + public void eventIsClickableWhenNotMovableInWeekView() { + openWeekView(); + getEvent().findElement(By.className("v-calendar-event-caption")) + .click(); + Assert.assertEquals("1. Clicked on foo", getLogRow(0)); + } + private void assertEventCannotBeMoved() { int originalPosition = getEventXPosition(); -- 2.39.5