Browse Source

Fix NPE when clicking and move handler is not set (#8718)

Change-Id: I13dfe9344d7ca516d41145e4c35fc45c620cac56
tags/7.6.0.alpha4
Artur Signell 8 years ago
parent
commit
f3ae913aa0

+ 7
- 2
client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java View File

} }
int endX = event.getClientX(); int endX = event.getClientX();
int endY = event.getClientY(); 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; startX = -1;
startY = -1; startY = -1;
mouseMoveStarted = false; mouseMoveStarted = false;

+ 5
- 2
client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java View File



int endX = event.getClientX(); int endX = event.getClientX();
int endY = event.getClientY(); 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; startX = -1;
startY = -1; startY = -1;
prevDayDiff = 0; prevDayDiff = 0;

+ 12
- 2
uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandler.java View File

import java.util.Locale; import java.util.Locale;


import com.vaadin.server.VaadinRequest; 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.Calendar;
import com.vaadin.ui.components.calendar.CalendarComponentEvents; 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; import com.vaadin.ui.components.calendar.event.BasicEvent;


public class NullEventMoveHandler extends AbstractTestUI {
public class NullEventMoveHandler extends AbstractTestUIWithLog {
@Override @Override
protected void setup(VaadinRequest request) { protected void setup(VaadinRequest request) {
Calendar calendar = getCalendar(); Calendar calendar = getCalendar();


calendar.setHandler((CalendarComponentEvents.EventMoveHandler) null); calendar.setHandler((CalendarComponentEvents.EventMoveHandler) null);
calendar.setHandler(new EventClickHandler() {

@Override
public void eventClick(EventClick event) {
log("Clicked on " + event.getCalendarEvent().getCaption());

}
});


addComponent(calendar); addComponent(calendar);
} }

+ 15
- 0
uitest/src/com/vaadin/tests/components/calendar/NullEventMoveHandlerTest.java View File

import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;


import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
assertEventCannotBeMoved(); assertEventCannotBeMoved();
} }


@Test
public void eventIsClickableWhenNotMovableInMonthView() {
getEvent().click();
Assert.assertEquals("1. Clicked on foo", getLogRow(0));
}

@Test @Test
public void eventIsNotMovableInWeekView() { public void eventIsNotMovableInWeekView() {
openWeekView(); openWeekView();
assertEventCannotBeMoved(); 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() { private void assertEventCannotBeMoved() {
int originalPosition = getEventXPosition(); int originalPosition = getEventXPosition();



Loading…
Cancel
Save