summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorAnna Miroshnik <anna.miroshnik@arcadia.spb.ru>2014-09-24 11:33:01 +0400
committerSauli Tähkäpää <sauli@vaadin.com>2014-11-10 12:59:04 +0200
commit59e024b4a4231fa3e0c21d7adbffc5237774cb01 (patch)
tree1cb16f51ccbd2007109d17c03b04e8d946034c63 /server
parentd9cbbe89d35d7b8110376b7bf9adce0a4e1e39c6 (diff)
downloadvaadin-framework-59e024b4a4231fa3e0c21d7adbffc5237774cb01.tar.gz
vaadin-framework-59e024b4a4231fa3e0c21d7adbffc5237774cb01.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')
-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);
}