aboutsummaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorAnna Miroshnik <anna.miroshnik@arcadia.spb.ru>2014-09-24 11:33:01 +0400
committerVaadin Code Review <review@vaadin.com>2014-10-29 08:44:59 +0000
commit8d036d968a24dc1ee1690d86bdc73cbe718a8ad7 (patch)
tree8882c1b21e33774295b78fd6e3bed8e0e276dc25 /server/src
parenteeec83d56b663c030672aa596150f4a5b1948554 (diff)
downloadvaadin-framework-8d036d968a24dc1ee1690d86bdc73cbe718a8ad7.tar.gz
vaadin-framework-8d036d968a24dc1ee1690d86bdc73cbe718a8ad7.zip
Fix: Navigation to invisible days of week in VAADIN calendar (#12243)
Some changes in BasicBackwardHandler and BasicForwardHandler. Also test was added (CalendarBackwardForwardTest). Changes after review. Change-Id: Ibe0283534b784e3c18134619e1843440ca74e65c
Diffstat (limited to 'server/src')
-rw-r--r--server/src/com/vaadin/ui/components/calendar/handler/BasicBackwardHandler.java16
-rw-r--r--server/src/com/vaadin/ui/components/calendar/handler/BasicForwardHandler.java16
2 files changed, 32 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/components/calendar/handler/BasicBackwardHandler.java b/server/src/com/vaadin/ui/components/calendar/handler/BasicBackwardHandler.java
index f4d47f89d4..0e99b26856 100644
--- a/server/src/com/vaadin/ui/components/calendar/handler/BasicBackwardHandler.java
+++ b/server/src/com/vaadin/ui/components/calendar/handler/BasicBackwardHandler.java
@@ -47,6 +47,7 @@ public class BasicBackwardHandler implements BackwardHandler {
// calculate amount to move back
int durationInDays = (int) (((end.getTime()) - start.getTime()) / DateConstants.DAYINMILLIS);
durationInDays++;
+ // for week view durationInDays = -7, for day view durationInDays = -1
durationInDays = -durationInDays;
// set new start and end times
@@ -59,6 +60,21 @@ public class BasicBackwardHandler implements BackwardHandler {
javaCalendar.add(java.util.Calendar.DATE, durationInDays);
Date newEnd = javaCalendar.getTime();
+ if (start.equals(end)) { // day view
+ int firstDay = event.getComponent().getFirstVisibleDayOfWeek();
+ int lastDay = event.getComponent().getLastVisibleDayOfWeek();
+ int dayOfWeek = javaCalendar.get(Calendar.DAY_OF_WEEK);
+
+ // we suppose that 7 >= lastDay >= firstDay >= 1
+ while (!(firstDay <= dayOfWeek && dayOfWeek <= lastDay)) {
+ javaCalendar.add(java.util.Calendar.DATE, -1);
+ dayOfWeek = javaCalendar.get(Calendar.DAY_OF_WEEK);
+ }
+
+ newStart = javaCalendar.getTime();
+ newEnd = javaCalendar.getTime();
+ }
+
setDates(event, newStart, newEnd);
}
diff --git a/server/src/com/vaadin/ui/components/calendar/handler/BasicForwardHandler.java b/server/src/com/vaadin/ui/components/calendar/handler/BasicForwardHandler.java
index 96c3c097dc..45b44cb673 100644
--- a/server/src/com/vaadin/ui/components/calendar/handler/BasicForwardHandler.java
+++ b/server/src/com/vaadin/ui/components/calendar/handler/BasicForwardHandler.java
@@ -45,6 +45,7 @@ public class BasicForwardHandler implements ForwardHandler {
// calculate amount to move forward
int durationInDays = (int) (((end.getTime()) - start.getTime()) / DateConstants.DAYINMILLIS);
+ // for week view durationInDays = 7, for day view durationInDays = 1
durationInDays++;
// set new start and end times
@@ -57,6 +58,21 @@ public class BasicForwardHandler implements ForwardHandler {
javaCalendar.add(java.util.Calendar.DATE, durationInDays);
Date newEnd = javaCalendar.getTime();
+ if (start.equals(end)) { // day view
+ int firstDay = event.getComponent().getFirstVisibleDayOfWeek();
+ int lastDay = event.getComponent().getLastVisibleDayOfWeek();
+ int dayOfWeek = javaCalendar.get(Calendar.DAY_OF_WEEK);
+
+ // we suppose that 7 >= lastDay >= firstDay >= 1
+ while (!(firstDay <= dayOfWeek && dayOfWeek <= lastDay)) {
+ javaCalendar.add(java.util.Calendar.DATE, 1);
+ dayOfWeek = javaCalendar.get(Calendar.DAY_OF_WEEK);
+ }
+
+ newStart = javaCalendar.getTime();
+ newEnd = javaCalendar.getTime();
+ }
+
setDates(event, newStart, newEnd);
}