From 0999abd4b3cd0628ab7f22aca765b7e06ca6eb69 Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Sun, 24 Aug 2014 11:59:51 +0300 Subject: [PATCH] Update DateCellDayEvent size on updateSizes in Connector (#13233). Change-Id: Ib3142cc62e95ce0e31bb8746eacd5ca4580c1865 --- .../client/ui/calendar/schedule/DateCell.java | 30 +++-- .../calendar/CalendarRescheduleEvent.java | 105 ++++++++++++++++++ .../calendar/CalendarRescheduleEventTest.java | 82 ++++++++++++++ .../CalendarResizeOverlappingEventsTest.java | 23 +--- .../com/vaadin/tests/tb3/DndActionsTest.java | 50 +++++++++ 5 files changed, 261 insertions(+), 29 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/calendar/CalendarRescheduleEvent.java create mode 100644 uitest/src/com/vaadin/tests/components/calendar/CalendarRescheduleEventTest.java create mode 100644 uitest/src/com/vaadin/tests/tb3/DndActionsTest.java diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java b/client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java index 9e110b6d7a..448083ba26 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java @@ -18,7 +18,6 @@ package com.vaadin.client.ui.calendar.schedule; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -203,6 +202,8 @@ public class DateCell extends FocusableComplexPanel implements width = getOffsetWidth() - Util.measureHorizontalBorder(getElement()); + // Update moveWidth for any DateCellDayEvent child + updateEventCellsWidth(); recalculateEventWidths(); } else { removeStyleDependentName("Hsized"); @@ -221,6 +222,8 @@ public class DateCell extends FocusableComplexPanel implements // recalc heights&size for events. all other height sizes come // from css startingSlotHeight = slotElements[0].getOffsetHeight(); + // Update slotHeight for each DateCellDayEvent child + updateEventCellsHeight(); recalculateEventPositions(); if (isToday()) { @@ -327,14 +330,7 @@ public class DateCell extends FocusableComplexPanel implements .setHeight(slotElementHeights[i], Unit.PX); } - Iterator it = iterator(); - while (it.hasNext()) { - Widget child = it.next(); - if (child instanceof DateCellDayEvent) { - ((DateCellDayEvent) child).setSlotHeightInPX(getSlotHeight()); - } - - } + updateEventCellsHeight(); } public int getSlotHeight() { @@ -838,4 +834,20 @@ public class DateCell extends FocusableComplexPanel implements .contextMenu(event, DateCell.this); } } + + private void updateEventCellsWidth() { + for (Widget widget : getChildren()) { + if (widget instanceof DateCellDayEvent) { + ((DateCellDayEvent) widget).setMoveWidth(width); + } + } + } + + private void updateEventCellsHeight() { + for (Widget widget : getChildren()) { + if (widget instanceof DateCellDayEvent) { + ((DateCellDayEvent) widget).setSlotHeightInPX(getSlotHeight()); + } + } + } } diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarRescheduleEvent.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarRescheduleEvent.java new file mode 100644 index 0000000000..824ad0941f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarRescheduleEvent.java @@ -0,0 +1,105 @@ +/* + * 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 to check ability to reschedule events unlimited times. + * + * @author Vaadin Ltd + */ +public class CalendarRescheduleEvent extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Calendar calendar = new Calendar("Test calendar"); + final java.util.Calendar cal = getAdjustedCalendar(1); + + Date from = cal.getTime(); + + cal.add(java.util.Calendar.HOUR, 1); + Date to = 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(); + startLbl.addStyleName("start"); + info.addComponent(startLbl); + + final Label endLbl = new Label(); + 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 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 "It should be possible to reschedule events unlimited times."; + } + + @Override + protected Integer getTicketNumber() { + return 13233; + } + + private java.util.Calendar getAdjustedCalendar(int hour) { + final java.util.Calendar cal = java.util.Calendar.getInstance(); + + cal.set(java.util.Calendar.HOUR_OF_DAY, hour); + cal.set(java.util.Calendar.MINUTE, 0); + 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/CalendarRescheduleEventTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarRescheduleEventTest.java new file mode 100644 index 0000000000..fb8cce7d53 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarRescheduleEventTest.java @@ -0,0 +1,82 @@ +/* + * 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 ability to reschedule events unlimited times. + * + * @author Vaadin Ltd + */ +public class CalendarRescheduleEventTest extends DndActionsTest { + + @Test + public void rescheduleEventSeveralTimes() { + openTestURL(); + + // Reschedule event for the first time + int y = rescheduleEvent(20); + + WebElement startElement = getDriver() + .findElement(By.className("start")); + WebElement endElement = getDriver().findElement(By.className("end")); + + long start = Long.parseLong(startElement.getText()); + long end = Long.parseLong(endElement.getText()); + + long duration = end - start; + + // Reschedule event for the second time + int yNew = rescheduleEvent(20); + + startElement = getDriver().findElement(By.className("start")); + endElement = getDriver().findElement(By.className("end")); + + long newStart = Long.parseLong(startElement.getText()); + long newEnd = Long.parseLong(endElement.getText()); + + Assert.assertTrue( + "Second rescheduling did not change the event start time", + newStart > start); + Assert.assertEquals( + "Duration of the event after second rescheduling has been changed", + duration, newEnd - newStart); + Assert.assertTrue( + "Second rescheduling did not change the event Y coordinate", + yNew > y); + } + + /* + * DnD event by Y axis + */ + private int rescheduleEvent(int yOffset) { + WebElement eventCaption = getDriver().findElement( + By.className("v-calendar-event-caption")); + + dragAndDrop(eventCaption, 0, yOffset); + + eventCaption = getDriver().findElement( + By.className("v-calendar-event-caption")); + return eventCaption.getLocation().getY(); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEventsTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEventsTest.java index f664149cce..e3e5606089 100644 --- a/uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEventsTest.java +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEventsTest.java @@ -24,15 +24,14 @@ import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; -import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.tb3.DndActionsTest; /** * * @author Vaadin Ltd */ -public class CalendarResizeOverlappingEventsTest extends MultiBrowserTest { +public class CalendarResizeOverlappingEventsTest extends DndActionsTest { private int noOverlapWidth; private int oneOverlapWidth; @@ -100,23 +99,7 @@ public class CalendarResizeOverlappingEventsTest extends MultiBrowserTest { } private void dragAndDrop(WebElement element, int yOffset) { - /* - * Selenium doesn't properly drag and drop items in IE8. It tries to - * start dragging an element from a position above the element itself. - */ - if (BrowserUtil.isIE8(getDesiredCapabilities())) { - Actions action = new Actions(getDriver()); - action.moveToElement(element); - action.moveByOffset(0, 1); - action.clickAndHold(); - action.moveByOffset(0, yOffset); - action.release(); - action.build().perform(); - } else { - Actions action = new Actions(getDriver()); - action.dragAndDropBy(element, 0, yOffset); - action.build().perform(); - } + dragAndDrop(element, 0, yOffset); } private void initParams() { diff --git a/uitest/src/com/vaadin/tests/tb3/DndActionsTest.java b/uitest/src/com/vaadin/tests/tb3/DndActionsTest.java new file mode 100644 index 0000000000..e755a00a0d --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/DndActionsTest.java @@ -0,0 +1,50 @@ +/* + * 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.tb3; + +import org.junit.Ignore; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +/** + * Base class for TestBench 3+ tests that use DnD. This class contains utility + * methods for DnD operations. + * + * @author Vaadin Ltd + */ +@Ignore +public abstract class DndActionsTest extends MultiBrowserTest { + + public void dragAndDrop(WebElement element, int xOffset, int yOffset) { + /* + * Selenium doesn't properly drag and drop items in IE8. It tries to + * start dragging an element from a position above the element itself. + */ + if (BrowserUtil.isIE8(getDesiredCapabilities())) { + Actions action = new Actions(getDriver()); + action.moveToElement(element); + action.moveByOffset(0, 1); + action.clickAndHold(); + action.moveByOffset(xOffset, yOffset); + action.release(); + action.build().perform(); + } else { + Actions action = new Actions(getDriver()); + action.dragAndDropBy(element, xOffset, yOffset); + action.build().perform(); + } + } +} -- 2.39.5