summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2014-09-21 12:36:21 +0300
committerSauli Tähkäpää <sauli@vaadin.com>2014-11-10 13:23:49 +0200
commit43da5f5c83f20e0444d1505151d6c5222241ed50 (patch)
treea21ee4ccdf910f247820a673f4574ede89679adb
parent63302d572257f2200355c44098e8df9f9c17842e (diff)
downloadvaadin-framework-43da5f5c83f20e0444d1505151d6c5222241ed50.tar.gz
vaadin-framework-43da5f5c83f20e0444d1505151d6c5222241ed50.zip
Allow move any event in month calendar view (#12413).
Change-Id: I63491488356a32a233a4ba9a7434a9f4a1f5b9d1
-rw-r--r--client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java68
-rw-r--r--uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEvent.java109
-rw-r--r--uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEventTest.java81
3 files changed, 241 insertions, 17 deletions
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 8e83dc4e36..db8452af9a 100644
--- a/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java
+++ b/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java
@@ -74,8 +74,15 @@ public class SimpleDayCell extends FocusableFlowPanel implements
private int startY = -1;
private int startYrelative;
private int startXrelative;
- private Date startDateFrom;
- private Date startDateTo;
+ // "from" date of date which is source of Dnd
+ private Date dndSourceDateFrom;
+ // "to" date of date which is source of Dnd
+ private Date dndSourceDateTo;
+ // "from" time of date which is source of Dnd
+ private Date dndSourceStartDateTime;
+ // "to" time of date which is source of Dnd
+ private Date dndSourceEndDateTime;
+
private int prevDayDiff = 0;
private int prevWeekDiff = 0;
private HandlerRegistration moveRegistration;
@@ -392,8 +399,7 @@ public class SimpleDayCell extends FocusableFlowPanel implements
prevDayDiff = 0;
prevWeekDiff = 0;
- if (!mel.isTimeSpecificEvent()
- && (xDiff < -3 || xDiff > 3 || yDiff < -3 || yDiff > 3)) {
+ if (xDiff < -3 || xDiff > 3 || yDiff < -3 || yDiff > 3) {
eventMoved(moveEvent);
} else if (calendar.getEventClickListener() != null) {
@@ -528,20 +534,47 @@ public class SimpleDayCell extends FocusableFlowPanel implements
Date from = e.getStart();
Date to = e.getEnd();
- long duration = to.getTime() - from.getTime();
long daysMs = dayDiff * DateConstants.DAYINMILLIS;
long weeksMs = weekDiff * DateConstants.WEEKINMILLIS;
- from.setTime(startDateFrom.getTime() + weeksMs + daysMs);
- to.setTime((from.getTime() + duration));
+
+ setDates(e, from, to, weeksMs + daysMs, false);
e.setStart(from);
e.setEnd(to);
- e.setStartTime(new Date(from.getTime()));
- e.setEndTime(new Date(to.getTime()));
+ if (w.isTimeSpecificEvent()) {
+ Date start = new Date();
+ Date end = new Date();
+ setDates(e, start, end, weeksMs + daysMs, true);
+ e.setStartTime(start);
+ e.setEndTime(end);
+ } else {
+ e.setStartTime(new Date(from.getTime()));
+ e.setEndTime(new Date(to.getTime()));
+ }
updateDragPosition(w, dayDiff, weekDiff);
}
+ private void setDates(CalendarEvent e, Date start, Date end, long shift,
+ boolean isDateTime) {
+ Date currentStart;
+ Date currentEnd;
+ if (isDateTime) {
+ currentStart = e.getStartTime();
+ currentEnd = e.getEndTime();
+ } else {
+ currentStart = e.getStart();
+ currentEnd = e.getEnd();
+ }
+ long duration = currentEnd.getTime() - currentStart.getTime();
+ if (isDateTime) {
+ start.setTime(dndSourceStartDateTime.getTime() + shift);
+ } else {
+ start.setTime(dndSourceDateFrom.getTime() + shift);
+ }
+ end.setTime((start.getTime() + duration));
+ }
+
private void eventMoved(CalendarEvent e) {
calendar.updateEventToMonthGrid(e);
if (calendar.getEventMovedListener() != null) {
@@ -551,10 +584,6 @@ public class SimpleDayCell extends FocusableFlowPanel implements
public void startCalendarEventDrag(MouseDownEvent event,
final MonthEventLabel w) {
- if (w.isTimeSpecificEvent()) {
- return;
- }
-
moveRegistration = addMouseMoveHandler(this);
startX = event.getClientX();
startY = event.getClientY();
@@ -564,8 +593,11 @@ public class SimpleDayCell extends FocusableFlowPanel implements
% getWidth();
CalendarEvent e = getEventByWidget(w);
- startDateFrom = (Date) e.getStart().clone();
- startDateTo = (Date) e.getEnd().clone();
+ dndSourceDateFrom = (Date) e.getStart().clone();
+ dndSourceDateTo = (Date) e.getEnd().clone();
+
+ dndSourceStartDateTime = (Date) e.getStartTime().clone();
+ dndSourceEndDateTime = (Date) e.getEndTime().clone();
Event.setCapture(getElement());
keyDownHandler = addKeyDownHandler(new KeyDownHandler() {
@@ -591,8 +623,10 @@ public class SimpleDayCell extends FocusableFlowPanel implements
moveEvent = getEventByWidget(w);
}
- moveEvent.setStart(startDateFrom);
- moveEvent.setEnd(startDateTo);
+ moveEvent.setStart(dndSourceDateFrom);
+ moveEvent.setEnd(dndSourceDateTo);
+ moveEvent.setStartTime(dndSourceStartDateTime);
+ moveEvent.setEndTime(dndSourceEndDateTime);
calendar.updateEventToMonthGrid(moveEvent);
// reset drag-related properties
diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEvent.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEvent.java
new file mode 100644
index 0000000000..b36b4d200e
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEvent.java
@@ -0,0 +1,109 @@
+/*
+ * 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.calendar;
+
+import java.util.Date;
+import java.util.List;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Calendar;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.components.calendar.event.BasicEvent;
+import com.vaadin.ui.components.calendar.event.BasicEventProvider;
+import com.vaadin.ui.components.calendar.event.CalendarEvent;
+import com.vaadin.ui.components.calendar.event.CalendarEventProvider.EventSetChangeEvent;
+import com.vaadin.ui.components.calendar.event.CalendarEventProvider.EventSetChangeListener;
+
+/**
+ * Test UI for DnD regular (not all day event) in month view.
+ *
+ * @author Vaadin Ltd
+ */
+public class CalendarMonthViewDndEvent extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final Calendar calendar = new Calendar("Test calendar");
+ final java.util.Calendar cal = getAdjustedCalendar();
+
+ Date from = cal.getTime();
+
+ Date start = new Date(from.getTime() - 24 * 3600000);
+ calendar.setStartDate(start);
+
+ cal.add(java.util.Calendar.HOUR, 1);
+ Date to = cal.getTime();
+
+ cal.add(java.util.Calendar.MONTH, 1);
+ calendar.setEndDate(cal.getTime());
+
+ final BasicEvent basicEvent = new BasicEvent("event", "description",
+ from, to);
+
+ HorizontalLayout info = new HorizontalLayout();
+ info.setSpacing(true);
+ info.setMargin(true);
+ addComponent(info);
+ final Label startLbl = new Label(String.valueOf(from.getTime()));
+ startLbl.addStyleName("start");
+ info.addComponent(startLbl);
+
+ final Label endLbl = new Label(String.valueOf(to.getTime()));
+ endLbl.addStyleName("end");
+ info.addComponent(endLbl);
+
+ BasicEventProvider provider = new BasicEventProvider();
+ provider.addEvent(basicEvent);
+ calendar.setEventProvider(provider);
+ provider.addEventSetChangeListener(new EventSetChangeListener() {
+
+ @Override
+ public void eventSetChange(EventSetChangeEvent event) {
+ List<CalendarEvent> events = event.getProvider().getEvents(
+ new Date(0), new Date(Long.MAX_VALUE));
+ CalendarEvent calEvent = events.get(0);
+ Date startEvent = calEvent.getStart();
+ Date endEvent = calEvent.getEnd();
+
+ startLbl.setValue(String.valueOf(startEvent.getTime()));
+ endLbl.setValue(String.valueOf(endEvent.getTime()));
+ }
+ });
+
+ addComponent(calendar);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Allow DnD any events in Calendar Month view";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 12413;
+ }
+
+ private java.util.Calendar getAdjustedCalendar() {
+ final java.util.Calendar cal = java.util.Calendar.getInstance();
+
+ cal.set(java.util.Calendar.SECOND, 0);
+ cal.set(java.util.Calendar.MILLISECOND, 0);
+ return cal;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEventTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEventTest.java
new file mode 100644
index 0000000000..2efcd1f88d
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEventTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.calendar;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.DndActionsTest;
+
+/**
+ * Test to check how DnD works for regular (not all day event) in calendar month
+ * view.
+ *
+ * @author Vaadin Ltd
+ */
+public class CalendarMonthViewDndEventTest extends DndActionsTest {
+
+ @Test
+ public void dragAndDropEventToNextDay() {
+ openTestURL();
+
+ WebElement event = getDriver().findElement(
+ By.className("v-calendar-event"));
+ int x = event.getLocation().getX();
+ int width = event.getSize().getWidth();
+
+ WebElement cell = getDriver().findElement(
+ By.className("v-calendar-month-day"));
+
+ int cellY = cell.getLocation().getY();
+ int cellHeight = cell.getSize().getHeight();
+
+ long origStart = getTime("start");
+ long origEnd = getTime("end");
+
+ dragAndDrop(event, event.getSize().getWidth() + 5, 0);
+
+ event = getDriver().findElement(By.className("v-calendar-event"));
+ int newX = event.getLocation().getX();
+ int newY = event.getLocation().getY();
+
+ Assert.assertTrue(
+ "Moved event has wrong Y position (not the same row)",
+ newY >= cellY && newY < cellY + cellHeight);
+ Assert.assertTrue(
+ "Moved event has wrong X position (not after original event)",
+ newX >= x + width - 1);
+
+ long start = getTime("start");
+ long end = getTime("end");
+
+ int day = 24 * 3600000;
+ Assert.assertEquals(
+ "Start date of moved event is not next day, same time",
+ origStart + day, start);
+ Assert.assertEquals(
+ "End date of moved event is not next day, same time", origEnd
+ + day, end);
+ }
+
+ private long getTime(String style) {
+ WebElement start = getDriver().findElement(By.className(style));
+ return Long.parseLong(start.getText());
+ }
+
+}