diff options
8 files changed, 338 insertions, 28 deletions
diff --git a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java index e9bbf2015c..58cc31a580 100644 --- a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java +++ b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java @@ -35,8 +35,8 @@ import com.vaadin.client.ApplicationConnection; import com.vaadin.client.Paintable; import com.vaadin.client.TooltipInfo; import com.vaadin.client.UIDL; -import com.vaadin.client.WidgetUtil; import com.vaadin.client.VConsole; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.RpcProxy; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.AbstractComponentConnector; @@ -138,7 +138,7 @@ public class CalendarConnector extends AbstractComponentConnector implements getWidget().setListener(new DateClickListener() { @Override public void dateClick(String date) { - if (!getWidget().isDisabledOrReadOnly() + if (!getWidget().isDisabled() && hasEventListener(CalendarEventId.DATECLICK)) { rpc.dateClick(date); } @@ -171,7 +171,7 @@ public class CalendarConnector extends AbstractComponentConnector implements getWidget().setListener(new WeekClickListener() { @Override public void weekClick(String event) { - if (!getWidget().isDisabledOrReadOnly() + if (!getWidget().isDisabled() && hasEventListener(CalendarEventId.WEEKCLICK)) { rpc.weekClick(event); } diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/DayToolbar.java b/client/src/com/vaadin/client/ui/calendar/schedule/DayToolbar.java index db3f47dfed..10ed5bb3f9 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/DayToolbar.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/DayToolbar.java @@ -134,7 +134,7 @@ public class DayToolbar extends HorizontalPanel implements ClickHandler { @Override public void onClick(ClickEvent event) { - if (!calendar.isDisabledOrReadOnly()) { + if (!calendar.isDisabled()) { if (event.getSource() == nextLabel) { if (calendar.getForwardListener() != null) { calendar.getForwardListener().forward(); 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 424531ee58..3bf6930933 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java @@ -439,24 +439,20 @@ public class SimpleDayCell extends FocusableFlowPanel implements if (calendar.isEventMoveAllowed()) { startCalendarEventDrag(event, (MonthEventLabel) w); } - } else if (!calendar.isReadOnly()) { - // these are not allowed when in read-only - if (w == bottomspacer) { - if (scrollable) { - setLimitedCellHeight(); - } else { - setUnlimitedCellHeight(); - } - reDraw(true); - - } else if (w == this && !scrollable) { - MonthGrid grid = getMonthGrid(); - if (grid.isEnabled() && calendar.isRangeSelectAllowed()) { - grid.setSelectionStart(this); - grid.setSelectionEnd(this); - } - } else if (w instanceof Label) { - labelMouseDown = true; + } else if (w == bottomspacer) { + if (scrollable) { + setLimitedCellHeight(); + } else { + setUnlimitedCellHeight(); + } + reDraw(true); + } else if (w instanceof Label) { + labelMouseDown = true; + } else if (w == this && !scrollable) { + MonthGrid grid = getMonthGrid(); + if (grid.isEnabled() && calendar.isRangeSelectAllowed()) { + grid.setSelectionStart(this); + grid.setSelectionEnd(this); } } diff --git a/server/src/com/vaadin/ui/Calendar.java b/server/src/com/vaadin/ui/Calendar.java index e90d80072f..48c024026e 100644 --- a/server/src/com/vaadin/ui/Calendar.java +++ b/server/src/com/vaadin/ui/Calendar.java @@ -1775,9 +1775,6 @@ public class Calendar extends AbstractComponent implements @Override public void dateClick(String date) { - if (!isClientChangeAllowed()) { - return; - } if (date != null && date.length() > 6) { try { Date d = df_date.parse(date); @@ -1789,9 +1786,6 @@ public class Calendar extends AbstractComponent implements @Override public void weekClick(String event) { - if (!isClientChangeAllowed()) { - return; - } if (event.length() > 0 && event.contains("w")) { String[] splitted = event.split("w"); if (splitted.length == 2) { diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarDisabledTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarDisabledTest.java new file mode 100644 index 0000000000..8b8122dcf9 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarDisabledTest.java @@ -0,0 +1,52 @@ +package com.vaadin.tests.components.calendar; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.tb3.newelements.CalendarElement; + +public class CalendarDisabledTest extends MultiBrowserTest { + + @Override + protected Class<?> getUIClass() { + return CalendarReadOnly.class; + } + + @Override + public void setup() throws Exception { + super.setup(); + + openTestURL("restartApplication&disabled"); + } + + private CalendarElement getCalendar() { + return $(CalendarElement.class).first(); + } + + @Test + public void weekViewCannotBeOpenedFromMonthView() { + tryOpenWeekView(); + assertCalendarInMonthView(); + } + + @Test + public void dayViewCannotBeOpenedFromMonthView() { + tryOpenDayView(); + assertCalendarInMonthView(); + } + + private void tryOpenDayView() { + getCalendar().getDayNumbers().get(0).click(); + } + + private void tryOpenWeekView() { + getCalendar().getWeekNumbers().get(0).click(); + } + + private void assertCalendarInMonthView() { + assertTrue("Calendar wasn't in month view.", getCalendar() + .hasMonthView()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnly.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnly.java new file mode 100644 index 0000000000..8e82555e87 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnly.java @@ -0,0 +1,71 @@ +package com.vaadin.tests.components.calendar; + +import java.text.ParseException; +import java.text.SimpleDateFormat; + +import com.vaadin.annotations.Theme; +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; +import com.vaadin.ui.themes.ValoTheme; + +@Theme(ValoTheme.THEME_NAME) +public class CalendarReadOnly extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Calendar calendar = new Calendar(); + + if (request.getParameter("readonly") != null) { + calendar.setReadOnly(true); + } + + if (request.getParameter("disabled") != null) { + calendar.setEnabled(false); + } + + calendar.setFirstVisibleHourOfDay(8); + calendar.setLastVisibleHourOfDay(16); + + calendar.setTimeFormat(Calendar.TimeFormat.Format24H); + calendar.setHandler((CalendarComponentEvents.EventResizeHandler) null); + + calendar.setSizeFull(); + + try { + calendar.setStartDate(new SimpleDateFormat("yyyy-MM-dd") + .parse("2013-09-01")); + calendar.setEndDate(new SimpleDateFormat("yyyy-MM-dd") + .parse("2013-09-30")); + + BasicEvent event = new BasicEvent("EVENT NAME 1", + "EVENT TOOLTIP 1", + new SimpleDateFormat("yyyy-MM-dd HH:mm") + .parse("2013-09-05 15:30"), new SimpleDateFormat( + "yyyy-MM-dd HH:mm").parse("2013-09-05 22:20")); + event.setStyleName("color1"); + + calendar.addEvent(event); + calendar.addEvent(event); + calendar.addEvent(event); + calendar.addEvent(event); + + } catch (ParseException e) { + + } + + addComponent(calendar); + } + + @Override + protected Integer getTicketNumber() { + return 16523; + } + + @Override + protected String getTestDescription() { + return "When set to readonly, you should still be able to navigate through the calendar."; + } +} diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnlyTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnlyTest.java new file mode 100644 index 0000000000..142353f314 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnlyTest.java @@ -0,0 +1,149 @@ +package com.vaadin.tests.components.calendar; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.core.IsNot.not; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.tb3.newelements.CalendarElement; + +public class CalendarReadOnlyTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + + openTestURL("restartApplication&readonly"); + } + + @Test + public void weekViewCanBeOpenedFromMonthView() { + openWeekView(); + + assertTrue("Calendar wasn't in week view.", getCalendar().hasWeekView()); + } + + @Test + public void dayViewCanBeOpenedFromMonthView() { + openDayView(); + + assertTrue("Calendar wasn't in day view.", getCalendar().hasDayView()); + } + + @Test + public void dayViewCanBeOpenedFromWeekView() { + openWeekView(); + + getCalendar().getDayHeaders().get(0).click(); + + assertTrue("Calendar wasn't in day view.", getCalendar().hasDayView()); + } + + @Test + public void weekViewCanBeBrowsedForwards() { + openWeekView(); + + String firstDayOfCurrentWeek = getVisibleFirstDay(); + getCalendar().next(); + + String firstDayOfNextWeek = getVisibleFirstDay(); + + assertThat("Week didn't change.", firstDayOfCurrentWeek, + is(not(firstDayOfNextWeek))); + } + + @Test + public void weekViewCanBeBrowsedBackwards() { + openWeekView(); + + String firstDayOfCurrentWeek = getVisibleFirstDay(); + getCalendar().back(); + + String firstDayOfPreviousWeek = getVisibleFirstDay(); + + assertThat("Week didn't change.", firstDayOfCurrentWeek, + is(not(firstDayOfPreviousWeek))); + } + + @Test + public void dayViewCanBeBrowsedForwards() { + openDayView(); + + String currentDay = getVisibleFirstDay(); + getCalendar().next(); + + String nextDay = getVisibleFirstDay(); + + assertThat("Day didn't change.", currentDay, is(not(nextDay))); + } + + @Test + public void dayViewCanBeBrowsedBackwards() { + openDayView(); + + String currentDay = getVisibleFirstDay(); + getCalendar().back(); + + String previousDay = getVisibleFirstDay(); + + assertThat("Day didn't change.", currentDay, is(not(previousDay))); + } + + @Test + public void hiddenEventsCanBeExpanded() { + WebElement dayWithEvents = getFirstDayWithEvents(); + + assertThat("Incorrect event count.", getVisibleEvents(dayWithEvents) + .size(), is(2)); + + toggleExpandEvents(dayWithEvents).click(); + assertThat("Incorrect event count.", getVisibleEvents(dayWithEvents) + .size(), is(4)); + + toggleExpandEvents(dayWithEvents).click(); + assertThat("Incorrect event count.", getVisibleEvents(dayWithEvents) + .size(), is(2)); + } + + private CalendarElement getCalendar() { + return $(CalendarElement.class).first(); + } + + private void openDayView() { + getCalendar().getDayNumbers().get(0).click(); + } + + private void openWeekView() { + getCalendar().getWeekNumbers().get(0).click(); + } + + private String getVisibleFirstDay() { + return getCalendar().getDayHeaders().get(0).getText(); + } + + private WebElement getFirstDayWithEvents() { + for (WebElement monthDay : getCalendar().getMonthDays()) { + if (getVisibleEvents(monthDay).size() > 0) { + return monthDay; + } + } + + return null; + } + + private WebElement toggleExpandEvents(WebElement dayWithEvents) { + return dayWithEvents.findElement(By + .className("v-calendar-bottom-spacer")); + } + + private List<WebElement> getVisibleEvents(WebElement dayWithEvents) { + return dayWithEvents.findElements(By.className("v-calendar-event")); + } +} diff --git a/uitest/src/com/vaadin/tests/tb3/newelements/CalendarElement.java b/uitest/src/com/vaadin/tests/tb3/newelements/CalendarElement.java new file mode 100644 index 0000000000..e5213b21b5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/newelements/CalendarElement.java @@ -0,0 +1,48 @@ +package com.vaadin.tests.tb3.newelements; + +import java.util.List; + +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ServerClass; + +@ServerClass("com.vaadin.ui.Calendar") +public class CalendarElement extends + com.vaadin.testbench.elements.CalendarElement { + public List<WebElement> getWeekNumbers() { + return findElements(By.className("v-calendar-week-number")); + } + + public boolean hasMonthView() { + return isElementPresent(By.className("v-calendar-week-numbers")); + } + + public boolean hasWeekView() { + return isElementPresent(By.className("v-calendar-header-week")); + } + + public List<WebElement> getDayNumbers() { + return findElements(By.className("v-calendar-day-number")); + } + + public List<WebElement> getMonthDays() { + return findElements(By.className("v-calendar-month-day")); + } + + public boolean hasDayView() { + return getDayHeaders().size() == 1; + } + + public List<WebElement> getDayHeaders() { + return findElements(By.className("v-calendar-header-day")); + } + + public void back() { + findElement(By.className("v-calendar-back")).click(); + } + + public void next() { + findElement(By.className("v-calendar-next")).click(); + } +} |