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;
getWidget().setListener(new DateClickListener() {
@Override
public void dateClick(String date) {
- if (!getWidget().isDisabledOrReadOnly()
+ if (!getWidget().isDisabled()
&& hasEventListener(CalendarEventId.DATECLICK)) {
rpc.dateClick(date);
}
getWidget().setListener(new WeekClickListener() {
@Override
public void weekClick(String event) {
- if (!getWidget().isDisabledOrReadOnly()
+ if (!getWidget().isDisabled()
&& hasEventListener(CalendarEventId.WEEKCLICK)) {
rpc.weekClick(event);
}
@Override
public void onClick(ClickEvent event) {
- if (!calendar.isDisabledOrReadOnly()) {
+ if (!calendar.isDisabled()) {
if (event.getSource() == nextLabel) {
if (calendar.getForwardListener() != null) {
calendar.getForwardListener().forward();
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);
}
}
@Override
public void dateClick(String date) {
- if (!isClientChangeAllowed()) {
- return;
- }
if (date != null && date.length() > 6) {
try {
Date d = df_date.parse(date);
@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) {
--- /dev/null
+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());
+ }
+}
--- /dev/null
+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.";
+ }
+}
--- /dev/null
+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"));
+ }
+}
--- /dev/null
+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();
+ }
+}