You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CalendarConnector.java 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui.calendar;
  17. import java.text.ParseException;
  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.Date;
  21. import java.util.HashMap;
  22. import java.util.Iterator;
  23. import java.util.List;
  24. import com.google.gwt.core.shared.GWT;
  25. import com.google.gwt.dom.client.Element;
  26. import com.google.gwt.dom.client.NativeEvent;
  27. import com.google.gwt.event.dom.client.ContextMenuEvent;
  28. import com.google.gwt.i18n.client.DateTimeFormat;
  29. import com.google.gwt.user.client.DOM;
  30. import com.google.gwt.user.client.Window;
  31. import com.google.gwt.user.client.ui.Widget;
  32. import com.vaadin.client.ApplicationConnection;
  33. import com.vaadin.client.Paintable;
  34. import com.vaadin.client.TooltipInfo;
  35. import com.vaadin.client.UIDL;
  36. import com.vaadin.client.WidgetUtil;
  37. import com.vaadin.client.VConsole;
  38. import com.vaadin.client.communication.RpcProxy;
  39. import com.vaadin.client.communication.StateChangeEvent;
  40. import com.vaadin.client.ui.AbstractComponentConnector;
  41. import com.vaadin.client.ui.Action;
  42. import com.vaadin.client.ui.ActionOwner;
  43. import com.vaadin.client.ui.SimpleManagedLayout;
  44. import com.vaadin.client.ui.VCalendar;
  45. import com.vaadin.client.ui.VCalendar.BackwardListener;
  46. import com.vaadin.client.ui.VCalendar.DateClickListener;
  47. import com.vaadin.client.ui.VCalendar.EventClickListener;
  48. import com.vaadin.client.ui.VCalendar.EventMovedListener;
  49. import com.vaadin.client.ui.VCalendar.EventResizeListener;
  50. import com.vaadin.client.ui.VCalendar.ForwardListener;
  51. import com.vaadin.client.ui.VCalendar.MouseEventListener;
  52. import com.vaadin.client.ui.VCalendar.RangeSelectListener;
  53. import com.vaadin.client.ui.VCalendar.WeekClickListener;
  54. import com.vaadin.client.ui.calendar.schedule.CalendarDay;
  55. import com.vaadin.client.ui.calendar.schedule.CalendarEvent;
  56. import com.vaadin.client.ui.calendar.schedule.DateCell;
  57. import com.vaadin.client.ui.calendar.schedule.DateCell.DateCellSlot;
  58. import com.vaadin.client.ui.calendar.schedule.DateCellDayEvent;
  59. import com.vaadin.client.ui.calendar.schedule.DateUtil;
  60. import com.vaadin.client.ui.calendar.schedule.HasTooltipKey;
  61. import com.vaadin.client.ui.calendar.schedule.MonthEventLabel;
  62. import com.vaadin.client.ui.calendar.schedule.SimpleDayCell;
  63. import com.vaadin.client.ui.calendar.schedule.dd.CalendarDropHandler;
  64. import com.vaadin.client.ui.calendar.schedule.dd.CalendarMonthDropHandler;
  65. import com.vaadin.client.ui.calendar.schedule.dd.CalendarWeekDropHandler;
  66. import com.vaadin.shared.ui.Connect;
  67. import com.vaadin.shared.ui.Connect.LoadStyle;
  68. import com.vaadin.shared.ui.calendar.CalendarClientRpc;
  69. import com.vaadin.shared.ui.calendar.CalendarEventId;
  70. import com.vaadin.shared.ui.calendar.CalendarServerRpc;
  71. import com.vaadin.shared.ui.calendar.CalendarState;
  72. import com.vaadin.shared.ui.calendar.DateConstants;
  73. import com.vaadin.ui.Calendar;
  74. /**
  75. * Handles communication between Calendar on the server side and
  76. * {@link VCalendar} on the client side.
  77. *
  78. * @since 7.1
  79. * @author Vaadin Ltd.
  80. */
  81. @Connect(value = Calendar.class, loadStyle = LoadStyle.LAZY)
  82. public class CalendarConnector extends AbstractComponentConnector implements
  83. ActionOwner, SimpleManagedLayout, Paintable {
  84. private CalendarServerRpc rpc = RpcProxy.create(CalendarServerRpc.class,
  85. this);
  86. private final HashMap<String, String> actionMap = new HashMap<String, String>();
  87. private HashMap<Object, String> tooltips = new HashMap<Object, String>();
  88. private static final String DROPHANDLER_ACCEPT_CRITERIA_PAINT_TAG = "-ac";
  89. /**
  90. *
  91. */
  92. public CalendarConnector() {
  93. // Listen to events
  94. registerListeners();
  95. }
  96. @Override
  97. protected void init() {
  98. super.init();
  99. registerRpc(CalendarClientRpc.class, new CalendarClientRpc() {
  100. @Override
  101. public void scroll(int scrollPosition) {
  102. // TODO widget scroll
  103. }
  104. });
  105. getLayoutManager().registerDependency(this, getWidget().getElement());
  106. }
  107. @Override
  108. public void onUnregister() {
  109. super.onUnregister();
  110. getLayoutManager().unregisterDependency(this, getWidget().getElement());
  111. }
  112. @Override
  113. public VCalendar getWidget() {
  114. return (VCalendar) super.getWidget();
  115. }
  116. @Override
  117. public CalendarState getState() {
  118. return (CalendarState) super.getState();
  119. }
  120. /**
  121. * Registers listeners on the calendar so server can be notified of the
  122. * events
  123. */
  124. protected void registerListeners() {
  125. getWidget().setListener(new DateClickListener() {
  126. @Override
  127. public void dateClick(String date) {
  128. if (!getWidget().isDisabledOrReadOnly()
  129. && hasEventListener(CalendarEventId.DATECLICK)) {
  130. rpc.dateClick(date);
  131. }
  132. }
  133. });
  134. getWidget().setListener(new ForwardListener() {
  135. @Override
  136. public void forward() {
  137. if (hasEventListener(CalendarEventId.FORWARD)) {
  138. rpc.forward();
  139. }
  140. }
  141. });
  142. getWidget().setListener(new BackwardListener() {
  143. @Override
  144. public void backward() {
  145. if (hasEventListener(CalendarEventId.BACKWARD)) {
  146. rpc.backward();
  147. }
  148. }
  149. });
  150. getWidget().setListener(new RangeSelectListener() {
  151. @Override
  152. public void rangeSelected(String value) {
  153. if (hasEventListener(CalendarEventId.RANGESELECT)) {
  154. rpc.rangeSelect(value);
  155. }
  156. }
  157. });
  158. getWidget().setListener(new WeekClickListener() {
  159. @Override
  160. public void weekClick(String event) {
  161. if (!getWidget().isDisabledOrReadOnly()
  162. && hasEventListener(CalendarEventId.WEEKCLICK)) {
  163. rpc.weekClick(event);
  164. }
  165. }
  166. });
  167. getWidget().setListener(new EventMovedListener() {
  168. @Override
  169. public void eventMoved(CalendarEvent event) {
  170. if (hasEventListener(CalendarEventId.EVENTMOVE)) {
  171. StringBuilder sb = new StringBuilder();
  172. sb.append(DateUtil.formatClientSideDate(event.getStart()));
  173. sb.append("-");
  174. sb.append(DateUtil.formatClientSideTime(event
  175. .getStartTime()));
  176. rpc.eventMove(event.getIndex(), sb.toString());
  177. }
  178. }
  179. });
  180. getWidget().setListener(new EventResizeListener() {
  181. @Override
  182. public void eventResized(CalendarEvent event) {
  183. if (hasEventListener(CalendarEventId.EVENTRESIZE)) {
  184. StringBuilder buffer = new StringBuilder();
  185. buffer.append(DateUtil.formatClientSideDate(event
  186. .getStart()));
  187. buffer.append("-");
  188. buffer.append(DateUtil.formatClientSideTime(event
  189. .getStartTime()));
  190. String newStartDate = buffer.toString();
  191. buffer = new StringBuilder();
  192. buffer.append(DateUtil.formatClientSideDate(event.getEnd()));
  193. buffer.append("-");
  194. buffer.append(DateUtil.formatClientSideTime(event
  195. .getEndTime()));
  196. String newEndDate = buffer.toString();
  197. rpc.eventResize(event.getIndex(), newStartDate, newEndDate);
  198. }
  199. }
  200. });
  201. getWidget().setListener(new VCalendar.ScrollListener() {
  202. @Override
  203. public void scroll(int scrollPosition) {
  204. // This call is @Delayed (== non-immediate)
  205. rpc.scroll(scrollPosition);
  206. }
  207. });
  208. getWidget().setListener(new EventClickListener() {
  209. @Override
  210. public void eventClick(CalendarEvent event) {
  211. if (hasEventListener(CalendarEventId.EVENTCLICK)) {
  212. rpc.eventClick(event.getIndex());
  213. }
  214. }
  215. });
  216. getWidget().setListener(new MouseEventListener() {
  217. @Override
  218. public void contextMenu(ContextMenuEvent event, final Widget widget) {
  219. final NativeEvent ne = event.getNativeEvent();
  220. int left = ne.getClientX();
  221. int top = ne.getClientY();
  222. top += Window.getScrollTop();
  223. left += Window.getScrollLeft();
  224. getClient().getContextMenu().showAt(new ActionOwner() {
  225. @Override
  226. public String getPaintableId() {
  227. return CalendarConnector.this.getPaintableId();
  228. }
  229. @Override
  230. public ApplicationConnection getClient() {
  231. return CalendarConnector.this.getClient();
  232. }
  233. @Override
  234. @SuppressWarnings("deprecation")
  235. public Action[] getActions() {
  236. if (widget instanceof SimpleDayCell) {
  237. /*
  238. * Month view
  239. */
  240. SimpleDayCell cell = (SimpleDayCell) widget;
  241. Date start = new Date(cell.getDate().getYear(),
  242. cell.getDate().getMonth(), cell.getDate()
  243. .getDate(), 0, 0, 0);
  244. Date end = new Date(cell.getDate().getYear(), cell
  245. .getDate().getMonth(), cell.getDate()
  246. .getDate(), 23, 59, 59);
  247. return CalendarConnector.this.getActionsBetween(
  248. start, end);
  249. } else if (widget instanceof MonthEventLabel) {
  250. MonthEventLabel mel = (MonthEventLabel) widget;
  251. CalendarEvent event = mel.getCalendarEvent();
  252. Action[] actions = CalendarConnector.this
  253. .getActionsBetween(event.getStartTime(),
  254. event.getEndTime());
  255. for (Action action : actions) {
  256. ((VCalendarAction) action).setEvent(event);
  257. }
  258. return actions;
  259. } else if (widget instanceof DateCell) {
  260. /*
  261. * Week and Day view
  262. */
  263. DateCell cell = (DateCell) widget;
  264. int slotIndex = DOM.getChildIndex(
  265. cell.getElement(), (Element) ne
  266. .getEventTarget().cast());
  267. DateCellSlot slot = cell.getSlot(slotIndex);
  268. return CalendarConnector.this.getActionsBetween(
  269. slot.getFrom(), slot.getTo());
  270. } else if (widget instanceof DateCellDayEvent) {
  271. /*
  272. * Context menu on event
  273. */
  274. DateCellDayEvent dayEvent = (DateCellDayEvent) widget;
  275. CalendarEvent event = dayEvent.getCalendarEvent();
  276. Action[] actions = CalendarConnector.this
  277. .getActionsBetween(event.getStartTime(),
  278. event.getEndTime());
  279. for (Action action : actions) {
  280. ((VCalendarAction) action).setEvent(event);
  281. }
  282. return actions;
  283. }
  284. return null;
  285. }
  286. }, left, top);
  287. }
  288. });
  289. }
  290. private boolean showingMonthView() {
  291. return getState().days.size() > 7;
  292. }
  293. @Override
  294. public void onStateChanged(StateChangeEvent stateChangeEvent) {
  295. super.onStateChanged(stateChangeEvent);
  296. CalendarState state = getState();
  297. VCalendar widget = getWidget();
  298. // Enable or disable the forward and backward navigation buttons
  299. widget.setForwardNavigationEnabled(hasEventListener(CalendarEventId.FORWARD));
  300. widget.setBackwardNavigationEnabled(hasEventListener(CalendarEventId.BACKWARD));
  301. widget.set24HFormat(state.format24H);
  302. widget.setDayNames(state.dayNames);
  303. widget.setMonthNames(state.monthNames);
  304. widget.setFirstDayNumber(state.firstVisibleDayOfWeek);
  305. widget.setLastDayNumber(state.lastVisibleDayOfWeek);
  306. widget.setFirstHourOfTheDay(state.firstHourOfDay);
  307. widget.setLastHourOfTheDay(state.lastHourOfDay);
  308. widget.setReadOnly(state.readOnly);
  309. widget.setDisabled(!state.enabled);
  310. widget.setRangeSelectAllowed(hasEventListener(CalendarEventId.RANGESELECT));
  311. widget.setRangeMoveAllowed(hasEventListener(CalendarEventId.EVENTMOVE));
  312. widget.setEventMoveAllowed(hasEventListener(CalendarEventId.EVENTMOVE));
  313. widget.setEventResizeAllowed(hasEventListener(CalendarEventId.EVENTRESIZE));
  314. List<CalendarState.Day> days = state.days;
  315. List<CalendarState.Event> events = state.events;
  316. CalendarDropHandler dropHandler = getWidget().getDropHandler();
  317. if (showingMonthView()) {
  318. updateMonthView(days, events);
  319. if (dropHandler != null
  320. && !(dropHandler instanceof CalendarMonthDropHandler)) {
  321. getWidget().setDropHandler(new CalendarMonthDropHandler(this));
  322. }
  323. } else {
  324. updateWeekView(days, events);
  325. if (dropHandler != null
  326. && !(dropHandler instanceof CalendarWeekDropHandler)) {
  327. getWidget().setDropHandler(new CalendarWeekDropHandler(this));
  328. }
  329. }
  330. updateSizes();
  331. registerEventToolTips(state.events);
  332. updateActionMap(state.actions);
  333. }
  334. /*
  335. * (non-Javadoc)
  336. *
  337. * @see
  338. * com.vaadin.terminal.gwt.client.Paintable#updateFromUIDL(com.vaadin.terminal
  339. * .gwt.client.UIDL, com.vaadin.terminal.gwt.client.ApplicationConnection)
  340. */
  341. @Override
  342. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  343. Iterator<Object> childIterator = uidl.getChildIterator();
  344. while (childIterator.hasNext()) {
  345. UIDL child = (UIDL) childIterator.next();
  346. if (DROPHANDLER_ACCEPT_CRITERIA_PAINT_TAG.equals(child.getTag())) {
  347. if (getWidget().getDropHandler() == null) {
  348. getWidget().setDropHandler(
  349. showingMonthView() ? new CalendarMonthDropHandler(
  350. this) : new CalendarWeekDropHandler(this));
  351. }
  352. getWidget().getDropHandler().updateAcceptRules(child);
  353. } else {
  354. getWidget().setDropHandler(null);
  355. }
  356. }
  357. }
  358. /**
  359. * Returns the ApplicationConnection used to connect to the server side
  360. */
  361. @Override
  362. public ApplicationConnection getClient() {
  363. return getConnection();
  364. }
  365. /**
  366. * Register the description of the events as tooltips. This way, any event
  367. * displaying widget can use the event index as a key to display the
  368. * tooltip.
  369. */
  370. private void registerEventToolTips(List<CalendarState.Event> events) {
  371. for (CalendarState.Event e : events) {
  372. if (e.description != null && !"".equals(e.description)) {
  373. tooltips.put(e.index, e.description);
  374. } else {
  375. tooltips.remove(e.index);
  376. }
  377. }
  378. }
  379. @Override
  380. public TooltipInfo getTooltipInfo(com.google.gwt.dom.client.Element element) {
  381. TooltipInfo tooltipInfo = null;
  382. Widget w = WidgetUtil.findWidget(element, null);
  383. if (w instanceof HasTooltipKey) {
  384. tooltipInfo = GWT.create(TooltipInfo.class);
  385. String title = tooltips.get(((HasTooltipKey) w).getTooltipKey());
  386. tooltipInfo.setTitle(title != null ? title : "");
  387. }
  388. if (tooltipInfo == null) {
  389. tooltipInfo = super.getTooltipInfo(element);
  390. }
  391. return tooltipInfo;
  392. }
  393. @Override
  394. public boolean hasTooltip() {
  395. /*
  396. * Tooltips are not processed until updateFromUIDL, so we can't be sure
  397. * that there are no tooltips during onStateChange when this is used.
  398. */
  399. return true;
  400. }
  401. private void updateMonthView(List<CalendarState.Day> days,
  402. List<CalendarState.Event> events) {
  403. CalendarState state = getState();
  404. getWidget().updateMonthView(state.firstDayOfWeek,
  405. getWidget().getDateTimeFormat().parse(state.now), days.size(),
  406. calendarEventListOf(events, state.format24H),
  407. calendarDayListOf(days));
  408. }
  409. private void updateWeekView(List<CalendarState.Day> days,
  410. List<CalendarState.Event> events) {
  411. CalendarState state = getState();
  412. getWidget().updateWeekView(state.scroll,
  413. getWidget().getDateTimeFormat().parse(state.now), days.size(),
  414. state.firstDayOfWeek,
  415. calendarEventListOf(events, state.format24H),
  416. calendarDayListOf(days));
  417. }
  418. private Action[] getActionsBetween(Date start, Date end) {
  419. List<Action> actions = new ArrayList<Action>();
  420. List<String> ids = new ArrayList<String>();
  421. for (int i = 0; i < actionKeys.size(); i++) {
  422. String actionKey = actionKeys.get(i);
  423. String id = getActionID(actionKey);
  424. if (!ids.contains(id)) {
  425. Date actionStartDate;
  426. Date actionEndDate;
  427. try {
  428. actionStartDate = getActionStartDate(actionKey);
  429. actionEndDate = getActionEndDate(actionKey);
  430. } catch (ParseException pe) {
  431. VConsole.error("Failed to parse action date");
  432. continue;
  433. }
  434. // Case 0: action inside event timeframe
  435. // Action should start AFTER or AT THE SAME TIME as the event,
  436. // and
  437. // Action should end BEFORE or AT THE SAME TIME as the event
  438. boolean test0 = actionStartDate.compareTo(start) >= 0
  439. && actionEndDate.compareTo(end) <= 0;
  440. // Case 1: action intersects start of timeframe
  441. // Action end time must be between start and end of event
  442. boolean test1 = actionEndDate.compareTo(start) > 0
  443. && actionEndDate.compareTo(end) <= 0;
  444. // Case 2: action intersects end of timeframe
  445. // Action start time must be between start and end of event
  446. boolean test2 = actionStartDate.compareTo(start) >= 0
  447. && actionStartDate.compareTo(end) < 0;
  448. // Case 3: event inside action timeframe
  449. // Action should start AND END before the event is complete
  450. boolean test3 = start.compareTo(actionStartDate) >= 0
  451. && end.compareTo(actionEndDate) <= 0;
  452. if (test0 || test1 || test2 || test3) {
  453. VCalendarAction a = new VCalendarAction(this, rpc,
  454. actionKey);
  455. a.setCaption(getActionCaption(actionKey));
  456. a.setIconUrl(getActionIcon(actionKey));
  457. a.setActionStartDate(start);
  458. a.setActionEndDate(end);
  459. actions.add(a);
  460. ids.add(id);
  461. }
  462. }
  463. }
  464. return actions.toArray(new Action[actions.size()]);
  465. }
  466. private List<String> actionKeys = new ArrayList<String>();
  467. private void updateActionMap(List<CalendarState.Action> actions) {
  468. actionMap.clear();
  469. actionKeys.clear();
  470. if (actions == null) {
  471. return;
  472. }
  473. for (CalendarState.Action action : actions) {
  474. String id = action.actionKey + "-" + action.startDate + "-"
  475. + action.endDate;
  476. actionMap.put(id + "_k", action.actionKey);
  477. actionMap.put(id + "_c", action.caption);
  478. actionMap.put(id + "_s", action.startDate);
  479. actionMap.put(id + "_e", action.endDate);
  480. actionKeys.add(id);
  481. if (action.iconKey != null) {
  482. actionMap.put(id + "_i", getResourceUrl(action.iconKey));
  483. } else {
  484. actionMap.remove(id + "_i");
  485. }
  486. }
  487. Collections.sort(actionKeys);
  488. }
  489. /**
  490. * Get the original action ID that was passed in from the shared state
  491. *
  492. * @since 7.1.2
  493. * @param actionKey
  494. * the unique action key
  495. * @return
  496. */
  497. public String getActionID(String actionKey) {
  498. return actionMap.get(actionKey + "_k");
  499. }
  500. /**
  501. * Get the text that is displayed for a context menu item
  502. *
  503. * @param actionKey
  504. * The unique action key
  505. * @return
  506. */
  507. public String getActionCaption(String actionKey) {
  508. return actionMap.get(actionKey + "_c");
  509. }
  510. /**
  511. * Get the icon url for a context menu item
  512. *
  513. * @param actionKey
  514. * The unique action key
  515. * @return
  516. */
  517. public String getActionIcon(String actionKey) {
  518. return actionMap.get(actionKey + "_i");
  519. }
  520. /**
  521. * Get the start date for an action item
  522. *
  523. * @param actionKey
  524. * The unique action key
  525. * @return
  526. * @throws ParseException
  527. */
  528. public Date getActionStartDate(String actionKey) throws ParseException {
  529. String dateStr = actionMap.get(actionKey + "_s");
  530. DateTimeFormat formatter = DateTimeFormat
  531. .getFormat(DateConstants.ACTION_DATE_FORMAT_PATTERN);
  532. return formatter.parse(dateStr);
  533. }
  534. /**
  535. * Get the end date for an action item
  536. *
  537. * @param actionKey
  538. * The unique action key
  539. * @return
  540. * @throws ParseException
  541. */
  542. public Date getActionEndDate(String actionKey) throws ParseException {
  543. String dateStr = actionMap.get(actionKey + "_e");
  544. DateTimeFormat formatter = DateTimeFormat
  545. .getFormat(DateConstants.ACTION_DATE_FORMAT_PATTERN);
  546. return formatter.parse(dateStr);
  547. }
  548. /**
  549. * Returns ALL currently registered events. Use {@link #getActions(Date)} to
  550. * get the actions for a specific date
  551. */
  552. @Override
  553. public Action[] getActions() {
  554. List<Action> actions = new ArrayList<Action>();
  555. for (int i = 0; i < actionKeys.size(); i++) {
  556. final String actionKey = actionKeys.get(i);
  557. final VCalendarAction a = new VCalendarAction(this, rpc, actionKey);
  558. a.setCaption(getActionCaption(actionKey));
  559. a.setIconUrl(getActionIcon(actionKey));
  560. try {
  561. a.setActionStartDate(getActionStartDate(actionKey));
  562. a.setActionEndDate(getActionEndDate(actionKey));
  563. } catch (ParseException pe) {
  564. VConsole.error(pe);
  565. }
  566. actions.add(a);
  567. }
  568. return actions.toArray(new Action[actions.size()]);
  569. }
  570. /*
  571. * (non-Javadoc)
  572. *
  573. * @see com.vaadin.terminal.gwt.client.ui.ActionOwner#getPaintableId()
  574. */
  575. @Override
  576. public String getPaintableId() {
  577. return getConnectorId();
  578. }
  579. private List<CalendarEvent> calendarEventListOf(
  580. List<CalendarState.Event> events, boolean format24h) {
  581. List<CalendarEvent> list = new ArrayList<CalendarEvent>(events.size());
  582. for (CalendarState.Event event : events) {
  583. final String dateFrom = event.dateFrom;
  584. final String dateTo = event.dateTo;
  585. final String timeFrom = event.timeFrom;
  586. final String timeTo = event.timeTo;
  587. CalendarEvent calendarEvent = new CalendarEvent();
  588. calendarEvent.setAllDay(event.allDay);
  589. calendarEvent.setCaption(event.caption);
  590. calendarEvent.setDescription(event.description);
  591. calendarEvent.setStart(getWidget().getDateFormat().parse(dateFrom));
  592. calendarEvent.setEnd(getWidget().getDateFormat().parse(dateTo));
  593. calendarEvent.setFormat24h(format24h);
  594. calendarEvent.setStartTime(getWidget().getDateTimeFormat().parse(
  595. dateFrom + " " + timeFrom));
  596. calendarEvent.setEndTime(getWidget().getDateTimeFormat().parse(
  597. dateTo + " " + timeTo));
  598. calendarEvent.setStyleName(event.styleName);
  599. calendarEvent.setIndex(event.index);
  600. list.add(calendarEvent);
  601. }
  602. return list;
  603. }
  604. private List<CalendarDay> calendarDayListOf(List<CalendarState.Day> days) {
  605. List<CalendarDay> list = new ArrayList<CalendarDay>(days.size());
  606. for (CalendarState.Day day : days) {
  607. CalendarDay d = new CalendarDay(day.date, day.localizedDateFormat,
  608. day.dayOfWeek, day.week, day.yearOfWeek);
  609. list.add(d);
  610. }
  611. return list;
  612. }
  613. @Override
  614. public void layout() {
  615. updateSizes();
  616. }
  617. private void updateSizes() {
  618. int height = getLayoutManager()
  619. .getOuterHeight(getWidget().getElement());
  620. int width = getLayoutManager().getOuterWidth(getWidget().getElement());
  621. if (isUndefinedWidth()) {
  622. width = -1;
  623. }
  624. if (isUndefinedHeight()) {
  625. height = -1;
  626. }
  627. getWidget().setSizeForChildren(width, height);
  628. }
  629. }