]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix NPE when clicking and move handler is not set (#8718)
authorArtur Signell <artur@vaadin.com>
Mon, 3 Aug 2015 21:16:04 +0000 (00:16 +0300)
committerpatrik <patrik@vaadin.com>
Tue, 4 Aug 2015 12:52:03 +0000 (15:52 +0300)
Change-Id: I6c4547eb716e64e60239d9d901b9b889cfcc3761

client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java
client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java
uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandler.java
uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandlerTest.java

index 1a54fe045483c4a4205d7b9909c3ca25b36a8bad..55834397d34331af69fd7060a51f049256042fc6 100644 (file)
@@ -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;
index 3bf6930933637b2ef51f29123921a40e9f590089..158241337b3f97a8445f23c2de72cb0b1666311f 100644 (file)
@@ -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;
index c2dfdb26c1f8cc7e01eb3fdd8474fdaf88625d8c..40dd43abb2598c56f6eb21a0a76ba7d469752a3a 100644 (file)
@@ -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);
     }
index c40cd9ce9794ffe91184c96b7682e348a884d7d9..156100310ce6558c78e49bfcbbe3f3d65df88026 100644 (file)
@@ -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();