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;
width = getOffsetWidth()
- Util.measureHorizontalBorder(getElement());
+ // Update moveWidth for any DateCellDayEvent child
+ updateEventCellsWidth();
recalculateEventWidths();
} else {
removeStyleDependentName("Hsized");
// 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()) {
.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() {
.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());
+ }
+ }
+ }
}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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();
+ }
+
+}
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;
}
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() {
--- /dev/null
+/*
+ * 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();
+ }
+ }
+}