diff options
author | Patrik Lindström <patrik@vaadin.com> | 2013-07-29 15:09:35 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-07-30 11:33:18 +0000 |
commit | 7cb49d10de85b038b3f7068bf87b6c10315d3c21 (patch) | |
tree | 9e56c438da2c55076726418c812d8a10422d8ada /client | |
parent | 3a373efe27780f3ffd1f0e01fb6dabdb65af590c (diff) | |
download | vaadin-framework-7cb49d10de85b038b3f7068bf87b6c10315d3c21.tar.gz vaadin-framework-7cb49d10de85b038b3f7068bf87b6c10315d3c21.zip |
Fix invisible calendar actions menu #12181
Change-Id: I4cdf3d1e584f1537f0f216ddd6f65c1ec4a2ee6b
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/Action.java | 12 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/calendar/CalendarConnector.java | 107 |
2 files changed, 90 insertions, 29 deletions
diff --git a/client/src/com/vaadin/client/ui/Action.java b/client/src/com/vaadin/client/ui/Action.java index ffc3c4c7d4..e1b85dcb82 100644 --- a/client/src/com/vaadin/client/ui/Action.java +++ b/client/src/com/vaadin/client/ui/Action.java @@ -67,4 +67,16 @@ public abstract class Action implements Command { public void setIconUrl(String url) { iconUrl = url; } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "Action [owner=" + owner + ", iconUrl=" + iconUrl + ", caption=" + + caption + "]"; + } + } diff --git a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java index 5a83579d46..49cd2386ac 100644 --- a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java +++ b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java @@ -17,6 +17,7 @@ package com.vaadin.client.ui.calendar; import java.text.ParseException; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -267,6 +268,18 @@ public class CalendarConnector extends AbstractComponentConnector implements return CalendarConnector.this.getActionsBetween( start, end); + + } else if (widget instanceof MonthEventLabel) { + MonthEventLabel mel = (MonthEventLabel) widget; + CalendarEvent event = mel.getCalendarEvent(); + Action[] actions = CalendarConnector.this + .getActionsBetween(event.getStartTime(), + event.getEndTime()); + for (Action action : actions) { + ((VCalendarAction) action).setEvent(event); + } + return actions; + } else if (widget instanceof DateCell) { /* * Week and Day view @@ -284,22 +297,15 @@ public class CalendarConnector extends AbstractComponentConnector implements */ DateCellDayEvent dayEvent = (DateCellDayEvent) widget; CalendarEvent event = dayEvent.getCalendarEvent(); + Action[] actions = CalendarConnector.this .getActionsBetween(event.getStartTime(), event.getEndTime()); + for (Action action : actions) { ((VCalendarAction) action).setEvent(event); } - return actions; - } else if (widget instanceof MonthEventLabel) { - MonthEventLabel mel = (MonthEventLabel) widget; - CalendarEvent event = mel.getCalendarEvent(); - Action[] actions = CalendarConnector.this - .getActionsBetween(event.getStartTime(), - event.getEndTime()); - for (Action action : actions) { - ((VCalendarAction) action).setEvent(event); - } + return actions; } return null; @@ -456,27 +462,55 @@ public class CalendarConnector extends AbstractComponentConnector implements private Action[] getActionsBetween(Date start, Date end) { List<Action> actions = new ArrayList<Action>(); + List<String> ids = new ArrayList<String>(); + for (int i = 0; i < actionKeys.size(); i++) { - final String actionKey = actionKeys.get(i); - Date actionStartDate; - Date actionEndDate; - try { - actionStartDate = getActionStartDate(actionKey); - actionEndDate = getActionEndDate(actionKey); - } catch (ParseException pe) { - VConsole.error("Failed to parse action date"); - continue; - } + String actionKey = actionKeys.get(i); + String id = getActionID(actionKey); + if (!ids.contains(id)) { + + Date actionStartDate; + Date actionEndDate; + try { + actionStartDate = getActionStartDate(actionKey); + actionEndDate = getActionEndDate(actionKey); + } catch (ParseException pe) { + VConsole.error("Failed to parse action date"); + continue; + } - boolean startIsValid = start.compareTo(actionStartDate) >= 0; - boolean endIsValid = end.compareTo(actionEndDate) <= 0; - if (startIsValid && endIsValid) { - VCalendarAction a = new VCalendarAction(this, rpc, actionKey); - a.setCaption(getActionCaption(actionKey)); - a.setIconUrl(getActionIcon(actionKey)); - a.setActionStartDate(start); - a.setActionEndDate(end); - actions.add(a); + // Case 0: action inside event timeframe + // Action should start AFTER or AT THE SAME TIME as the event, + // and + // Action should end BEFORE or AT THE SAME TIME as the event + boolean test0 = actionStartDate.compareTo(start) >= 0 + && actionEndDate.compareTo(end) <= 0; + + // Case 1: action intersects start of timeframe + // Action end time must be between start and end of event + boolean test1 = actionEndDate.compareTo(start) > 0 + && actionEndDate.compareTo(end) <= 0; + + // Case 2: action intersects end of timeframe + // Action start time must be between start and end of event + boolean test2 = actionStartDate.compareTo(start) >= 0 + && actionStartDate.compareTo(end) < 0; + + // Case 3: event inside action timeframe + // Action should start AND END before the event is complete + boolean test3 = start.compareTo(actionStartDate) >= 0 + && end.compareTo(actionEndDate) <= 0; + + if (test0 || test1 || test2 || test3) { + VCalendarAction a = new VCalendarAction(this, rpc, + actionKey); + a.setCaption(getActionCaption(actionKey)); + a.setIconUrl(getActionIcon(actionKey)); + a.setActionStartDate(start); + a.setActionEndDate(end); + actions.add(a); + ids.add(id); + } } } @@ -496,6 +530,7 @@ public class CalendarConnector extends AbstractComponentConnector implements for (CalendarState.Action action : actions) { String id = action.actionKey + "-" + action.startDate + "-" + action.endDate; + actionMap.put(id + "_k", action.actionKey); actionMap.put(id + "_c", action.caption); actionMap.put(id + "_s", action.startDate); actionMap.put(id + "_e", action.endDate); @@ -507,6 +542,20 @@ public class CalendarConnector extends AbstractComponentConnector implements actionMap.remove(id + "_i"); } } + + Collections.sort(actionKeys); + } + + /** + * Get the original action ID that was passed in from the shared state + * + * @since 7.1.2 + * @param actionKey + * the unique action key + * @return + */ + public String getActionID(String actionKey) { + return actionMap.get(actionKey + "_k"); } /** |