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 24KB

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