]> source.dussan.org Git - vaadin-framework.git/commitdiff
Update DateCellDayEvent size on updateSizes in Connector (#13233).
authorDenis Anisimov <denis@vaadin.com>
Sun, 24 Aug 2014 08:59:51 +0000 (11:59 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 29 Aug 2014 13:01:37 +0000 (13:01 +0000)
Change-Id: Ib3142cc62e95ce0e31bb8746eacd5ca4580c1865

client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java
uitest/src/com/vaadin/tests/components/calendar/CalendarRescheduleEvent.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/calendar/CalendarRescheduleEventTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEventsTest.java
uitest/src/com/vaadin/tests/tb3/DndActionsTest.java [new file with mode: 0644]

index ffa5f780719d90b67468e047de924d50112295d7..bef03707ba96c776d381b1a9225bcee75aa199e4 100644 (file)
@@ -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<Widget> it = iterator();
-        while (it.hasNext()) {
-            Widget child = it.next();
-            if (child instanceof DateCellDayEvent) {
-                ((DateCellDayEvent) child).setSlotHeightInPX(getSlotHeight());
-            }
-
-        }
+        updateEventCellsHeight();
     }
 
     public int getSlotHeight() {
@@ -829,4 +825,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 (file)
index 0000000..824ad09
--- /dev/null
@@ -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<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 "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 (file)
index 0000000..fb8cce7
--- /dev/null
@@ -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();
+    }
+
+}
index f664149ccea3b537b937bb66a2b727baf8b31315..e3e560608938e495bee215466e51694275ad751d 100644 (file)
@@ -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 (file)
index 0000000..e755a00
--- /dev/null
@@ -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();
+        }
+    }
+}