// event clicks should be allowed even when read-only
monthEventMouseDown = true;
- if (w instanceof MonthEventLabel) {
+ if (calendar.isEventMoveAllowed()) {
startCalendarEventDrag(event, (MonthEventLabel) w);
}
} else if (!calendar.isReadOnly()) {
--- /dev/null
+package com.vaadin.tests.components.calendar;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Calendar;
+import com.vaadin.ui.components.calendar.CalendarComponentEvents;
+import com.vaadin.ui.components.calendar.event.BasicEvent;
+
+public class NullEventMoveHandler extends AbstractTestUI {
+ @Override
+ protected void setup(VaadinRequest request) {
+ Calendar calendar = getCalendar();
+
+ calendar.setHandler((CalendarComponentEvents.EventMoveHandler) null);
+
+ addComponent(calendar);
+ }
+
+ private Calendar getCalendar() {
+ Calendar calendar = new Calendar();
+ calendar.setLocale(Locale.US);
+
+ try {
+ calendar.setStartDate(new SimpleDateFormat("yyyy-MM-dd")
+ .parse("2014-06-01"));
+ calendar.setEndDate(new SimpleDateFormat("yyyy-MM-dd")
+ .parse("2014-06-30"));
+
+ BasicEvent event = new BasicEvent("foo", "bar",
+ new SimpleDateFormat("yyyy-MM-dd").parse("2014-06-01"));
+
+ calendar.addEvent(event);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return calendar;
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 15174;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Events should not be movable when EventMoveHandler is null.";
+ }
+}
--- /dev/null
+package com.vaadin.tests.components.calendar;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.DndActionsTest;
+
+public class NullEventMoveHandlerTest extends DndActionsTest {
+
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+ openTestURL();
+ }
+
+ @Test
+ public void eventIsNotMovableInMonthView() {
+ assertEventCannotBeMoved();
+ }
+
+ @Test
+ public void eventIsNotMovableInWeekView() {
+ openWeekView();
+ assertEventCannotBeMoved();
+ }
+
+ private void assertEventCannotBeMoved() {
+ int originalPosition = getEventXPosition();
+
+ moveEventToNextDay();
+
+ assertThat("Event position changed.", getEventXPosition(),
+ is(originalPosition));
+ }
+
+ private void openWeekView() {
+ getDriver().findElement(By.className("v-calendar-week-number")).click();
+ }
+
+ private void moveEventToNextDay() {
+ WebElement event = getEvent();
+ dragAndDrop(event, event.getSize().getWidth() + 5, 0);
+ }
+
+ private int getEventXPosition() {
+ return getEvent().getLocation().getX();
+ }
+
+ private WebElement getEvent() {
+ return getDriver().findElement(By.className("v-calendar-event"));
+ }
+}
\ No newline at end of file