]> source.dussan.org Git - vaadin-framework.git/commitdiff
Enable navigation on a readonly Calendar. (#16523)
authorSauli Tähkäpää <sauli@vaadin.com>
Fri, 30 Jan 2015 15:46:07 +0000 (17:46 +0200)
committerArtur Signell <artur@vaadin.com>
Thu, 19 Feb 2015 12:36:52 +0000 (14:36 +0200)
- Month view: navigate to week and day views
- Week view: navigate to day view and to next and prev weeks
- Day view: navigate to next and prev days
- Month view: hidden events can be expanded to view.

Change-Id: I19c64ae64c55b8e07be7f73be64e18e700f849b5

client/src/com/vaadin/client/ui/calendar/CalendarConnector.java
client/src/com/vaadin/client/ui/calendar/schedule/DayToolbar.java
client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java
server/src/com/vaadin/ui/Calendar.java
uitest/src/com/vaadin/tests/components/calendar/CalendarDisabledTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnly.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnlyTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/tb3/newelements/CalendarElement.java [new file with mode: 0644]

index e9bbf2015c633cfed51bbb2f84dbecd156f6df09..58cc31a5804bcd7e0753cf910687385fc9646880 100644 (file)
@@ -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);
                 }
index db3f47dfeda6bb0c88b2acb25f84d84af1e5fc1d..10ed5bb3f9928752c485418d587a0279d911f391 100644 (file)
@@ -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();
index 424531ee583aef34d83fcce61f6b75cb3214d4c6..3bf6930933637b2ef51f29123921a40e9f590089 100644 (file)
@@ -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);
             }
         }
 
index e90d80072f00dc7c6d7f33df41801631e05928ab..48c024026ebf7f37bf7216ac61bbf684bab8cc38 100644 (file)
@@ -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 (file)
index 0000000..8b8122d
--- /dev/null
@@ -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 (file)
index 0000000..8e82555
--- /dev/null
@@ -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 (file)
index 0000000..142353f
--- /dev/null
@@ -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 (file)
index 0000000..e5213b2
--- /dev/null
@@ -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();
+    }
+}