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.

VCalendar.java 47KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639
  1. /*
  2. * Copyright 2000-2018 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.v7.client.ui;
  17. import java.util.ArrayList;
  18. import java.util.Arrays;
  19. import java.util.Collection;
  20. import java.util.Comparator;
  21. import java.util.Date;
  22. import java.util.List;
  23. import com.google.gwt.dom.client.Element;
  24. import com.google.gwt.event.dom.client.ContextMenuEvent;
  25. import com.google.gwt.event.dom.client.ContextMenuHandler;
  26. import com.google.gwt.i18n.client.DateTimeFormat;
  27. import com.google.gwt.user.client.ui.Composite;
  28. import com.google.gwt.user.client.ui.DockPanel;
  29. import com.google.gwt.user.client.ui.ScrollPanel;
  30. import com.google.gwt.user.client.ui.Widget;
  31. import com.vaadin.client.ui.dd.VHasDropHandler;
  32. import com.vaadin.v7.client.ui.calendar.schedule.CalendarDay;
  33. import com.vaadin.v7.client.ui.calendar.schedule.CalendarEvent;
  34. import com.vaadin.v7.client.ui.calendar.schedule.DayToolbar;
  35. import com.vaadin.v7.client.ui.calendar.schedule.MonthGrid;
  36. import com.vaadin.v7.client.ui.calendar.schedule.SimpleDayCell;
  37. import com.vaadin.v7.client.ui.calendar.schedule.SimpleDayToolbar;
  38. import com.vaadin.v7.client.ui.calendar.schedule.SimpleWeekToolbar;
  39. import com.vaadin.v7.client.ui.calendar.schedule.WeekGrid;
  40. import com.vaadin.v7.client.ui.calendar.schedule.WeeklyLongEvents;
  41. import com.vaadin.v7.client.ui.calendar.schedule.dd.CalendarDropHandler;
  42. import com.vaadin.v7.shared.ui.calendar.CalendarState.EventSortOrder;
  43. import com.vaadin.v7.shared.ui.calendar.DateConstants;
  44. /**
  45. * Client side implementation for Calendar.
  46. *
  47. * @since 7.1
  48. * @author Vaadin Ltd.
  49. */
  50. public class VCalendar extends Composite implements VHasDropHandler {
  51. public static final String ATTR_FIRSTDAYOFWEEK = "firstDay";
  52. public static final String ATTR_LASTDAYOFWEEK = "lastDay";
  53. public static final String ATTR_FIRSTHOUROFDAY = "firstHour";
  54. public static final String ATTR_LASTHOUROFDAY = "lastHour";
  55. // private boolean hideWeekends;
  56. private String[] monthNames;
  57. private String[] dayNames;
  58. private boolean format;
  59. private final DockPanel outer = new DockPanel();
  60. private int rows;
  61. private boolean rangeSelectAllowed = true;
  62. private boolean rangeMoveAllowed = true;
  63. private boolean eventResizeAllowed = true;
  64. private boolean eventMoveAllowed = true;
  65. private final SimpleDayToolbar nameToolbar = new SimpleDayToolbar();
  66. private final DayToolbar dayToolbar = new DayToolbar(this);
  67. private final SimpleWeekToolbar weekToolbar;
  68. private WeeklyLongEvents weeklyLongEvents;
  69. private MonthGrid monthGrid;
  70. private WeekGrid weekGrid;
  71. private int intWidth = 0;
  72. private int intHeight = 0;
  73. protected final DateTimeFormat dateformat_datetime = DateTimeFormat
  74. .getFormat("yyyy-MM-dd HH:mm:ss");
  75. protected final DateTimeFormat dateformat_date = DateTimeFormat
  76. .getFormat("yyyy-MM-dd");
  77. protected final DateTimeFormat time12format_date = DateTimeFormat
  78. .getFormat("h:mm a");
  79. protected final DateTimeFormat time24format_date = DateTimeFormat
  80. .getFormat("HH:mm");
  81. private boolean readOnly = false;
  82. private boolean disabled = false;
  83. private boolean isHeightUndefined = false;
  84. private boolean isWidthUndefined = false;
  85. private int firstDay;
  86. private int lastDay;
  87. private int firstHour;
  88. private int lastHour;
  89. private EventSortOrder eventSortOrder = EventSortOrder.DURATION_DESC;
  90. private static final EventDurationComparator DEFAULT_COMPARATOR = new EventDurationComparator(
  91. false);
  92. private CalendarDropHandler dropHandler;
  93. /**
  94. * Listener interface for listening to event click events.
  95. */
  96. public interface DateClickListener {
  97. /**
  98. * Triggered when a date was clicked.
  99. *
  100. * @param date
  101. * The date and time that was clicked
  102. */
  103. void dateClick(String date);
  104. }
  105. /**
  106. * Listener interface for listening to week number click events.
  107. */
  108. public interface WeekClickListener {
  109. /**
  110. * Called when a week number was selected.
  111. *
  112. * @param event
  113. * The format of the vent string is "<year>w<week>"
  114. */
  115. void weekClick(String event);
  116. }
  117. /**
  118. * Listener interface for listening to forward events.
  119. */
  120. public interface ForwardListener {
  121. /**
  122. * Called when the calendar should move one view forward.
  123. */
  124. void forward();
  125. }
  126. /**
  127. * Listener interface for listening to backward events.
  128. */
  129. public interface BackwardListener {
  130. /**
  131. * Called when the calendar should move one view backward.
  132. */
  133. void backward();
  134. }
  135. /**
  136. * Listener interface for listening to selection events.
  137. */
  138. public interface RangeSelectListener {
  139. /**
  140. * Called when a user selected a new event by highlighting an area of
  141. * the calendar.
  142. *
  143. * FIXME Fix the value nonsense.
  144. *
  145. * @param value
  146. * The format of the value string is
  147. * "<year>:<start-minutes>:<end-minutes>" if called from the
  148. * {@link SimpleWeekToolbar} and "<yyyy-MM-dd>TO<yyyy-MM-dd>"
  149. * if called from {@link MonthGrid}
  150. */
  151. void rangeSelected(String value);
  152. }
  153. /**
  154. * Listener interface for listening to click events.
  155. */
  156. public interface EventClickListener {
  157. /**
  158. * Called when an event was clicked.
  159. *
  160. * @param event
  161. * The event that was clicked
  162. */
  163. void eventClick(CalendarEvent event);
  164. }
  165. /**
  166. * Listener interface for listening to event moved events. Occurs when a
  167. * user drags an event to a new position
  168. */
  169. public interface EventMovedListener {
  170. /**
  171. * Triggered when an event was dragged to a new position and the start
  172. * and end dates was changed.
  173. *
  174. * @param event
  175. * The event that was moved
  176. */
  177. void eventMoved(CalendarEvent event);
  178. }
  179. /**
  180. * Listener interface for when an event gets resized (its start or end date
  181. * changes).
  182. */
  183. public interface EventResizeListener {
  184. /**
  185. * Triggers when the time limits for the event was changed.
  186. *
  187. * @param event
  188. * The event that was changed. The new time limits have been
  189. * updated in the event before calling this method
  190. */
  191. void eventResized(CalendarEvent event);
  192. }
  193. /**
  194. * Listener interface for listening to scroll events.
  195. */
  196. public interface ScrollListener {
  197. /**
  198. * Triggered when the calendar is scrolled.
  199. *
  200. * @param scrollPosition
  201. * The scroll position in pixels as returned by
  202. * {@link ScrollPanel#getScrollPosition()}
  203. */
  204. void scroll(int scrollPosition);
  205. }
  206. /**
  207. * Listener interface for listening to mouse events.
  208. */
  209. public interface MouseEventListener {
  210. /**
  211. * Triggered when a user wants an context menu.
  212. *
  213. * @param event
  214. * The context menu event
  215. *
  216. * @param widget
  217. * The widget that the context menu should be added to
  218. */
  219. void contextMenu(ContextMenuEvent event, Widget widget);
  220. }
  221. private abstract static class AbstractEventComparator
  222. implements Comparator<CalendarEvent> {
  223. @Override
  224. public int compare(CalendarEvent e1, CalendarEvent e2) {
  225. if (e1.isAllDay() != e2.isAllDay()) {
  226. if (e2.isAllDay()) {
  227. return 1;
  228. }
  229. return -1;
  230. }
  231. int result = doCompare(e1, e2);
  232. if (result == 0) {
  233. return indexCompare(e1, e2);
  234. }
  235. return result;
  236. }
  237. protected int indexCompare(CalendarEvent e1, CalendarEvent e2) {
  238. return ((Integer) e2.getIndex()).compareTo(e1.getIndex());
  239. }
  240. protected abstract int doCompare(CalendarEvent o1, CalendarEvent o2);
  241. }
  242. private static class EventDurationComparator
  243. extends AbstractEventComparator {
  244. EventDurationComparator(boolean ascending) {
  245. isAscending = ascending;
  246. }
  247. @Override
  248. public int doCompare(CalendarEvent e1, CalendarEvent e2) {
  249. int result = durationCompare(e1, e2, isAscending);
  250. if (result == 0) {
  251. return StartDateComparator.startDateCompare(e1, e2,
  252. isAscending);
  253. }
  254. return result;
  255. }
  256. static int durationCompare(CalendarEvent e1, CalendarEvent e2,
  257. boolean ascending) {
  258. int result = doDurationCompare(e1, e2);
  259. return ascending ? -result : result;
  260. }
  261. private static int doDurationCompare(CalendarEvent e1,
  262. CalendarEvent e2) {
  263. Long d1 = e1.getRangeInMilliseconds();
  264. Long d2 = e2.getRangeInMilliseconds();
  265. if (!d1.equals(0L) && !d2.equals(0L)) {
  266. return d2.compareTo(d1);
  267. }
  268. if (d2.equals(0L) && d1.equals(0L)) {
  269. return 0;
  270. } else if (d2.equals(0L) && d1 >= DateConstants.DAYINMILLIS) {
  271. return -1;
  272. } else if (d2.equals(0L) && d1 < DateConstants.DAYINMILLIS) {
  273. return 1;
  274. } else if (d1.equals(0L) && d2 >= DateConstants.DAYINMILLIS) {
  275. return 1;
  276. } else if (d1.equals(0L) && d2 < DateConstants.DAYINMILLIS) {
  277. return -1;
  278. }
  279. return d2.compareTo(d1);
  280. }
  281. private boolean isAscending;
  282. }
  283. private static class StartDateComparator extends AbstractEventComparator {
  284. StartDateComparator(boolean ascending) {
  285. isAscending = ascending;
  286. }
  287. @Override
  288. public int doCompare(CalendarEvent e1, CalendarEvent e2) {
  289. int result = startDateCompare(e1, e2, isAscending);
  290. if (result == 0) {
  291. // show a longer event after a shorter event
  292. return EventDurationComparator.durationCompare(e1, e2,
  293. isAscending);
  294. }
  295. return result;
  296. }
  297. static int startDateCompare(CalendarEvent e1, CalendarEvent e2,
  298. boolean ascending) {
  299. int result = e1.getStartTime().compareTo(e2.getStartTime());
  300. return ascending ? -result : result;
  301. }
  302. private boolean isAscending;
  303. }
  304. /**
  305. * Default constructor.
  306. */
  307. public VCalendar() {
  308. weekToolbar = new SimpleWeekToolbar(this);
  309. initWidget(outer);
  310. setStylePrimaryName("v-calendar");
  311. blockSelect(getElement());
  312. }
  313. /**
  314. * Hack for IE to not select text when dragging.
  315. *
  316. * @param e
  317. * The element to apply the hack on
  318. */
  319. private native void blockSelect(Element e)
  320. /*-{
  321. e.onselectstart = function() {
  322. return false;
  323. }
  324. e.ondragstart = function() {
  325. return false;
  326. }
  327. }-*/;
  328. private void updateEventsToWeekGrid(CalendarEvent[] events) {
  329. List<CalendarEvent> allDayLong = new ArrayList<CalendarEvent>();
  330. List<CalendarEvent> belowDayLong = new ArrayList<CalendarEvent>();
  331. for (CalendarEvent e : events) {
  332. if (e.isAllDay()) {
  333. // Event is set on one "allDay" event or more than one.
  334. allDayLong.add(e);
  335. } else {
  336. // Event is set only on one day.
  337. belowDayLong.add(e);
  338. }
  339. }
  340. weeklyLongEvents.addEvents(allDayLong);
  341. for (CalendarEvent e : belowDayLong) {
  342. weekGrid.addEvent(e);
  343. }
  344. }
  345. /**
  346. * Adds events to the month grid.
  347. *
  348. * @param events
  349. * The events to add
  350. * @param drawImmediately
  351. * Should the grid be rendered immediately. (currently not in
  352. * use)
  353. *
  354. */
  355. public void updateEventsToMonthGrid(Collection<CalendarEvent> events,
  356. boolean drawImmediately) {
  357. for (CalendarEvent e : sortEvents(events)) {
  358. // FIXME Why is drawImmediately not used ?????
  359. addEventToMonthGrid(e, false);
  360. }
  361. }
  362. private void addEventToMonthGrid(CalendarEvent e,
  363. boolean renderImmediately) {
  364. Date when = e.getStart();
  365. Date to = e.getEnd();
  366. boolean eventAdded = false;
  367. boolean inProgress = false; // Event adding has started
  368. boolean eventMoving = false;
  369. List<SimpleDayCell> dayCells = new ArrayList<SimpleDayCell>();
  370. List<SimpleDayCell> timeCells = new ArrayList<SimpleDayCell>();
  371. for (int row = 0; row < monthGrid.getRowCount(); row++) {
  372. if (eventAdded) {
  373. break;
  374. }
  375. for (int cell = 0; cell < monthGrid.getCellCount(row); cell++) {
  376. SimpleDayCell sdc = (SimpleDayCell) monthGrid.getWidget(row,
  377. cell);
  378. if (isEventInDay(when, to, sdc.getDate())
  379. && isEventInDayWithTime(when, to, sdc.getDate(),
  380. e.getEndTime(), e.isAllDay())) {
  381. if (!eventMoving) {
  382. eventMoving = sdc.getMoveEvent() != null;
  383. }
  384. long d = e.getRangeInMilliseconds();
  385. if ((d > 0 && d <= DateConstants.DAYINMILLIS)
  386. && !e.isAllDay()) {
  387. timeCells.add(sdc);
  388. } else {
  389. dayCells.add(sdc);
  390. }
  391. inProgress = true;
  392. continue;
  393. } else if (inProgress) {
  394. eventAdded = true;
  395. inProgress = false;
  396. break;
  397. }
  398. }
  399. }
  400. updateEventSlotIndex(e, dayCells);
  401. updateEventSlotIndex(e, timeCells);
  402. for (SimpleDayCell sdc : dayCells) {
  403. sdc.addCalendarEvent(e);
  404. }
  405. for (SimpleDayCell sdc : timeCells) {
  406. sdc.addCalendarEvent(e);
  407. }
  408. if (renderImmediately) {
  409. reDrawAllMonthEvents(!eventMoving);
  410. }
  411. }
  412. /*
  413. * We must also handle the special case when the event lasts exactly for 24
  414. * hours, thus spanning two days e.g. from 1.1.2001 00:00 to 2.1.2001 00:00.
  415. * That special case still should span one day when rendered.
  416. */
  417. @SuppressWarnings("deprecation")
  418. // Date methods are not deprecated in GWT
  419. private boolean isEventInDayWithTime(Date from, Date to, Date date,
  420. Date endTime, boolean isAllDay) {
  421. return (isAllDay || !(to.getDay() == date.getDay()
  422. && from.getDay() != to.getDay() && isMidnight(endTime)));
  423. }
  424. private void updateEventSlotIndex(CalendarEvent e,
  425. List<SimpleDayCell> cells) {
  426. if (cells.isEmpty()) {
  427. return;
  428. }
  429. if (e.getSlotIndex() == -1) {
  430. // Update slot index
  431. int newSlot = -1;
  432. for (SimpleDayCell sdc : cells) {
  433. int slot = sdc.getEventCount();
  434. if (slot > newSlot) {
  435. newSlot = slot;
  436. }
  437. }
  438. newSlot++;
  439. for (int i = 0; i < newSlot; i++) {
  440. // check for empty slot
  441. if (isSlotEmpty(e, i, cells)) {
  442. newSlot = i;
  443. break;
  444. }
  445. }
  446. e.setSlotIndex(newSlot);
  447. }
  448. }
  449. private void reDrawAllMonthEvents(boolean clearCells) {
  450. for (int row = 0; row < monthGrid.getRowCount(); row++) {
  451. for (int cell = 0; cell < monthGrid.getCellCount(row); cell++) {
  452. SimpleDayCell sdc = (SimpleDayCell) monthGrid.getWidget(row,
  453. cell);
  454. sdc.reDraw(clearCells);
  455. }
  456. }
  457. }
  458. private boolean isSlotEmpty(CalendarEvent addedEvent, int slotIndex,
  459. List<SimpleDayCell> cells) {
  460. for (SimpleDayCell sdc : cells) {
  461. CalendarEvent e = sdc.getCalendarEvent(slotIndex);
  462. if (e != null && !e.equals(addedEvent)) {
  463. return false;
  464. }
  465. }
  466. return true;
  467. }
  468. /**
  469. * Remove a month event from the view.
  470. *
  471. * @param target
  472. * The event to remove
  473. *
  474. * @param repaintImmediately
  475. * Should we repaint after the event was removed?
  476. */
  477. public void removeMonthEvent(CalendarEvent target,
  478. boolean repaintImmediately) {
  479. if (target != null && target.getSlotIndex() >= 0) {
  480. // Remove event
  481. for (int row = 0; row < monthGrid.getRowCount(); row++) {
  482. for (int cell = 0; cell < monthGrid.getCellCount(row); cell++) {
  483. SimpleDayCell sdc = (SimpleDayCell) monthGrid.getWidget(row,
  484. cell);
  485. if (sdc == null) {
  486. return;
  487. }
  488. sdc.removeEvent(target, repaintImmediately);
  489. }
  490. }
  491. }
  492. }
  493. /**
  494. * Updates an event in the month grid.
  495. *
  496. * @param changedEvent
  497. * The event that has changed
  498. */
  499. public void updateEventToMonthGrid(CalendarEvent changedEvent) {
  500. removeMonthEvent(changedEvent, true);
  501. changedEvent.setSlotIndex(-1);
  502. addEventToMonthGrid(changedEvent, true);
  503. }
  504. /**
  505. * Sort the events by current sort order.
  506. *
  507. * @param events
  508. * The events to sort
  509. * @return An array where the events has been sorted
  510. */
  511. public CalendarEvent[] sortEvents(Collection<CalendarEvent> events) {
  512. if (EventSortOrder.DURATION_DESC.equals(eventSortOrder)) {
  513. return sortEventsByDuration(events);
  514. } else if (!EventSortOrder.UNSORTED.equals(eventSortOrder)) {
  515. CalendarEvent[] sorted = events
  516. .toArray(new CalendarEvent[events.size()]);
  517. switch (eventSortOrder) {
  518. case DURATION_ASC:
  519. Arrays.sort(sorted, new EventDurationComparator(true));
  520. break;
  521. case START_DATE_ASC:
  522. Arrays.sort(sorted, new StartDateComparator(true));
  523. break;
  524. case START_DATE_DESC:
  525. Arrays.sort(sorted, new StartDateComparator(false));
  526. break;
  527. }
  528. return sorted;
  529. }
  530. return events.toArray(new CalendarEvent[events.size()]);
  531. }
  532. /**
  533. * Sort the event by how long they are.
  534. *
  535. * @param events
  536. * The events to sort
  537. * @return An array where the events has been sorted
  538. * @deprecated use {@link #sortEvents(Collection)} method which shorts
  539. * events by current sort order.
  540. */
  541. @Deprecated
  542. public CalendarEvent[] sortEventsByDuration(
  543. Collection<CalendarEvent> events) {
  544. CalendarEvent[] sorted = events
  545. .toArray(new CalendarEvent[events.size()]);
  546. Arrays.sort(sorted, getEventComparator());
  547. return sorted;
  548. }
  549. /*
  550. * Check if the given event occurs at the given date.
  551. */
  552. private boolean isEventInDay(Date eventWhen, Date eventTo, Date gridDate) {
  553. if (eventWhen.compareTo(gridDate) <= 0
  554. && eventTo.compareTo(gridDate) >= 0) {
  555. return true;
  556. }
  557. return false;
  558. }
  559. /**
  560. * Re-render the week grid.
  561. *
  562. * @param daysCount
  563. * The amount of days to include in the week
  564. * @param days
  565. * The days
  566. * @param today
  567. * Todays date
  568. * @param realDayNames
  569. * The names of the dates
  570. */
  571. @SuppressWarnings("deprecation")
  572. public void updateWeekGrid(int daysCount, List<CalendarDay> days,
  573. Date today, String[] realDayNames) {
  574. weekGrid.setFirstHour(getFirstHourOfTheDay());
  575. weekGrid.setLastHour(getLastHourOfTheDay());
  576. weekGrid.getTimeBar().updateTimeBar(is24HFormat());
  577. dayToolbar.clear();
  578. dayToolbar.addBackButton();
  579. dayToolbar.setVerticalSized(isHeightUndefined);
  580. dayToolbar.setHorizontalSized(isWidthUndefined);
  581. weekGrid.clearDates();
  582. weekGrid.setDisabled(isDisabledOrReadOnly());
  583. for (CalendarDay day : days) {
  584. String date = day.getDate();
  585. String localizedDateFormat = day.getLocalizedDateFormat();
  586. Date d = dateformat_date.parse(date);
  587. int dayOfWeek = day.getDayOfWeek();
  588. if (dayOfWeek < getFirstDayNumber()
  589. || dayOfWeek > getLastDayNumber()) {
  590. continue;
  591. }
  592. boolean isToday = false;
  593. int dayOfMonth = d.getDate();
  594. if (today.getDate() == dayOfMonth && today.getYear() == d.getYear()
  595. && today.getMonth() == d.getMonth()) {
  596. isToday = true;
  597. }
  598. dayToolbar.add(realDayNames[dayOfWeek - 1], date,
  599. localizedDateFormat, isToday ? "today" : null);
  600. weeklyLongEvents.addDate(d);
  601. weekGrid.addDate(d);
  602. if (isToday) {
  603. weekGrid.setToday(d, today);
  604. }
  605. }
  606. dayToolbar.addNextButton();
  607. }
  608. /**
  609. * Updates the events in the Month view.
  610. *
  611. * @param daysCount
  612. * How many days there are
  613. * @param daysUidl
  614. *
  615. * @param today
  616. * Todays date
  617. */
  618. @SuppressWarnings("deprecation")
  619. public void updateMonthGrid(int daysCount, List<CalendarDay> days,
  620. Date today) {
  621. int columns = getLastDayNumber() - getFirstDayNumber() + 1;
  622. rows = (int) Math.ceil(daysCount / (double) 7);
  623. monthGrid = new MonthGrid(this, rows, columns);
  624. monthGrid.setEnabled(!isDisabledOrReadOnly());
  625. weekToolbar.removeAllRows();
  626. int pos = 0;
  627. boolean monthNameDrawn = true;
  628. boolean firstDayFound = false;
  629. boolean lastDayFound = false;
  630. for (CalendarDay day : days) {
  631. String date = day.getDate();
  632. Date d = dateformat_date.parse(date);
  633. int dayOfWeek = day.getDayOfWeek();
  634. int week = day.getWeek();
  635. int dayOfMonth = d.getDate();
  636. // reset at start of each month
  637. if (dayOfMonth == 1) {
  638. monthNameDrawn = false;
  639. if (firstDayFound) {
  640. lastDayFound = true;
  641. }
  642. firstDayFound = true;
  643. }
  644. if (dayOfWeek < getFirstDayNumber()
  645. || dayOfWeek > getLastDayNumber()) {
  646. continue;
  647. }
  648. int y = (pos / columns);
  649. int x = pos - (y * columns);
  650. if (x == 0 && daysCount > 7) {
  651. // Add week to weekToolbar for navigation
  652. weekToolbar.addWeek(week, day.getYearOfWeek());
  653. }
  654. final SimpleDayCell cell = new SimpleDayCell(this, y, x);
  655. cell.setMonthGrid(monthGrid);
  656. cell.setDate(d);
  657. cell.addDomHandler(new ContextMenuHandler() {
  658. @Override
  659. public void onContextMenu(ContextMenuEvent event) {
  660. if (mouseEventListener != null) {
  661. event.preventDefault();
  662. event.stopPropagation();
  663. mouseEventListener.contextMenu(event, cell);
  664. }
  665. }
  666. }, ContextMenuEvent.getType());
  667. if (!firstDayFound) {
  668. cell.addStyleDependentName("prev-month");
  669. } else if (lastDayFound) {
  670. cell.addStyleDependentName("next-month");
  671. }
  672. if (dayOfMonth >= 1 && !monthNameDrawn) {
  673. cell.setMonthNameVisible(true);
  674. monthNameDrawn = true;
  675. }
  676. if (today.getDate() == dayOfMonth && today.getYear() == d.getYear()
  677. && today.getMonth() == d.getMonth()) {
  678. cell.setToday(true);
  679. }
  680. monthGrid.setWidget(y, x, cell);
  681. pos++;
  682. }
  683. }
  684. public void setSizeForChildren(int newWidth, int newHeight) {
  685. intWidth = newWidth;
  686. intHeight = newHeight;
  687. isWidthUndefined = intWidth == -1;
  688. dayToolbar.setVerticalSized(isHeightUndefined);
  689. dayToolbar.setHorizontalSized(isWidthUndefined);
  690. recalculateWidths();
  691. recalculateHeights();
  692. }
  693. /**
  694. * Recalculates the heights of the sub-components in the calendar.
  695. */
  696. protected void recalculateHeights() {
  697. if (monthGrid != null) {
  698. if (intHeight == -1) {
  699. monthGrid.addStyleDependentName("sizedheight");
  700. } else {
  701. monthGrid.removeStyleDependentName("sizedheight");
  702. }
  703. monthGrid.updateCellSizes(intWidth - weekToolbar.getOffsetWidth(),
  704. intHeight - nameToolbar.getOffsetHeight());
  705. weekToolbar.setHeightPX((intHeight == -1) ? intHeight
  706. : intHeight - nameToolbar.getOffsetHeight());
  707. } else if (weekGrid != null) {
  708. weekGrid.setHeightPX((intHeight == -1) ? intHeight
  709. : intHeight - weeklyLongEvents.getOffsetHeight()
  710. - dayToolbar.getOffsetHeight());
  711. }
  712. }
  713. /**
  714. * Recalculates the widths of the sub-components in the calendar.
  715. */
  716. protected void recalculateWidths() {
  717. if (!isWidthUndefined) {
  718. nameToolbar.setWidthPX(intWidth);
  719. dayToolbar.setWidthPX(intWidth);
  720. if (monthGrid != null) {
  721. monthGrid.updateCellSizes(
  722. intWidth - weekToolbar.getOffsetWidth(),
  723. intHeight - nameToolbar.getOffsetHeight());
  724. } else if (weekGrid != null) {
  725. weekGrid.setWidthPX(intWidth);
  726. weeklyLongEvents.setWidthPX(weekGrid.getInternalWidth());
  727. }
  728. } else {
  729. dayToolbar.setWidthPX(intWidth);
  730. nameToolbar.setWidthPX(intWidth);
  731. if (monthGrid != null) {
  732. if (intWidth == -1) {
  733. monthGrid.addStyleDependentName("sizedwidth");
  734. } else {
  735. monthGrid.removeStyleDependentName("sizedwidth");
  736. }
  737. } else if (weekGrid != null) {
  738. weekGrid.setWidthPX(intWidth);
  739. weeklyLongEvents.setWidthPX(weekGrid.getInternalWidth());
  740. }
  741. }
  742. }
  743. /**
  744. * Get the date format used to format dates only (excludes time).
  745. *
  746. * @return
  747. */
  748. public DateTimeFormat getDateFormat() {
  749. return dateformat_date;
  750. }
  751. /**
  752. * Get the time format used to format time only (excludes date).
  753. *
  754. * @return
  755. */
  756. public DateTimeFormat getTimeFormat() {
  757. if (is24HFormat()) {
  758. return time24format_date;
  759. }
  760. return time12format_date;
  761. }
  762. /**
  763. * Get the date and time format to format the dates (includes both date and
  764. * time).
  765. *
  766. * @return
  767. */
  768. public DateTimeFormat getDateTimeFormat() {
  769. return dateformat_datetime;
  770. }
  771. /**
  772. * Is the calendar either disabled or readonly.
  773. *
  774. * @return
  775. */
  776. public boolean isDisabledOrReadOnly() {
  777. return disabled || readOnly;
  778. }
  779. /**
  780. * Is the component disabled.
  781. */
  782. public boolean isDisabled() {
  783. return disabled;
  784. }
  785. /**
  786. * Is the component disabled.
  787. *
  788. * @param disabled
  789. * True if disabled
  790. */
  791. public void setDisabled(boolean disabled) {
  792. this.disabled = disabled;
  793. }
  794. /**
  795. * Is the component read-only.
  796. */
  797. public boolean isReadOnly() {
  798. return readOnly;
  799. }
  800. /**
  801. * Is the component read-only.
  802. *
  803. * @param readOnly
  804. * True if component is readonly
  805. */
  806. public void setReadOnly(boolean readOnly) {
  807. this.readOnly = readOnly;
  808. }
  809. /**
  810. * Get the month grid component.
  811. *
  812. * @return
  813. */
  814. public MonthGrid getMonthGrid() {
  815. return monthGrid;
  816. }
  817. /**
  818. * Get he week grid component.
  819. *
  820. * @return
  821. */
  822. public WeekGrid getWeekGrid() {
  823. return weekGrid;
  824. }
  825. /**
  826. * Calculates correct size for all cells (size / amount of cells ) and
  827. * distributes any overflow over all the cells.
  828. *
  829. * @param totalSize
  830. * the total amount of size reserved for all cells
  831. * @param numberOfCells
  832. * the number of cells
  833. * @param sizeModifier
  834. * a modifier which is applied to all cells before distributing
  835. * the overflow
  836. * @return an integer array that contains the correct size for each cell
  837. */
  838. public static int[] distributeSize(int totalSize, int numberOfCells,
  839. int sizeModifier) {
  840. int[] cellSizes = new int[numberOfCells];
  841. int startingSize = totalSize / numberOfCells;
  842. int cellSizeOverFlow = totalSize % numberOfCells;
  843. for (int i = 0; i < numberOfCells; i++) {
  844. cellSizes[i] = startingSize + sizeModifier;
  845. }
  846. // distribute size overflow amongst all slots
  847. int j = 0;
  848. while (cellSizeOverFlow > 0) {
  849. cellSizes[j]++;
  850. cellSizeOverFlow--;
  851. j++;
  852. if (j >= numberOfCells) {
  853. j = 0;
  854. }
  855. }
  856. // cellSizes[numberOfCells - 1] += cellSizeOverFlow;
  857. return cellSizes;
  858. }
  859. /**
  860. * Returns the default comparator which can compare calendar events by
  861. * duration.
  862. *
  863. * @deprecated this returns just one default comparator, but there are
  864. * number of comparators that are used to sort events depending
  865. * on order.
  866. *
  867. * @return
  868. */
  869. @Deprecated
  870. public static Comparator<CalendarEvent> getEventComparator() {
  871. return DEFAULT_COMPARATOR;
  872. }
  873. /**
  874. * Is the date at midnight.
  875. *
  876. * @param date
  877. * The date to check
  878. *
  879. * @return
  880. */
  881. @SuppressWarnings("deprecation")
  882. public static boolean isMidnight(Date date) {
  883. return (date.getHours() == 0 && date.getMinutes() == 0
  884. && date.getSeconds() == 0);
  885. }
  886. /**
  887. * Are the dates equal (uses second resolution).
  888. *
  889. * @param date1
  890. * The first the to compare
  891. * @param date2
  892. * The second date to compare
  893. * @return
  894. */
  895. @SuppressWarnings("deprecation")
  896. public static boolean areDatesEqualToSecond(Date date1, Date date2) {
  897. return date1.getYear() == date2.getYear()
  898. && date1.getMonth() == date2.getMonth()
  899. && date1.getDay() == date2.getDay()
  900. && date1.getHours() == date2.getHours()
  901. && date1.getSeconds() == date2.getSeconds();
  902. }
  903. /**
  904. * Is the calendar event zero seconds long and is occurring at midnight.
  905. *
  906. * @param event
  907. * The event to check
  908. * @return
  909. */
  910. public static boolean isZeroLengthMidnightEvent(CalendarEvent event) {
  911. return areDatesEqualToSecond(event.getStartTime(), event.getEndTime())
  912. && isMidnight(event.getEndTime());
  913. }
  914. /**
  915. * Should the 24h time format be used.
  916. *
  917. * @param format
  918. * True if the 24h format should be used else the 12h format is
  919. * used
  920. */
  921. public void set24HFormat(boolean format) {
  922. this.format = format;
  923. }
  924. /**
  925. * Is the 24h time format used.
  926. */
  927. public boolean is24HFormat() {
  928. return format;
  929. }
  930. /**
  931. * Set the names of the week days.
  932. *
  933. * @param names
  934. * The names of the days (Monday, Thursday,...)
  935. */
  936. public void setDayNames(String[] names) {
  937. assert (names.length == 7);
  938. dayNames = names;
  939. }
  940. /**
  941. * Get the names of the week days.
  942. */
  943. public String[] getDayNames() {
  944. return dayNames;
  945. }
  946. /**
  947. * Set the names of the months.
  948. *
  949. * @param names
  950. * The names of the months (January, February,...)
  951. */
  952. public void setMonthNames(String[] names) {
  953. assert (names.length == 12);
  954. monthNames = names;
  955. }
  956. /**
  957. * Get the month names.
  958. */
  959. public String[] getMonthNames() {
  960. return monthNames;
  961. }
  962. /**
  963. * Set the number when a week starts.
  964. *
  965. * @param dayNumber
  966. * The number of the day
  967. */
  968. public void setFirstDayNumber(int dayNumber) {
  969. assert (dayNumber >= 1 && dayNumber <= 7);
  970. firstDay = dayNumber;
  971. }
  972. /**
  973. * Get the number when a week starts.
  974. */
  975. public int getFirstDayNumber() {
  976. return firstDay;
  977. }
  978. /**
  979. * Set the number when a week ends.
  980. *
  981. * @param dayNumber
  982. * The number of the day
  983. */
  984. public void setLastDayNumber(int dayNumber) {
  985. assert (dayNumber >= 1 && dayNumber <= 7);
  986. lastDay = dayNumber;
  987. }
  988. /**
  989. * Get the number when a week ends.
  990. */
  991. public int getLastDayNumber() {
  992. return lastDay;
  993. }
  994. /**
  995. * Set the first hour of the day.
  996. *
  997. * @param hour
  998. * The first hour of the day
  999. */
  1000. public void setFirstHourOfTheDay(int hour) {
  1001. assert (hour >= 0 && hour <= 23);
  1002. firstHour = hour;
  1003. }
  1004. /**
  1005. * Get the first hour of the day.
  1006. *
  1007. * @return The first hour of the day
  1008. */
  1009. public int getFirstHourOfTheDay() {
  1010. return firstHour;
  1011. }
  1012. /**
  1013. * Set the last hour of the day.
  1014. *
  1015. * @param hour
  1016. * The last hour of the day
  1017. */
  1018. public void setLastHourOfTheDay(int hour) {
  1019. assert (hour >= 0 && hour <= 23);
  1020. lastHour = hour;
  1021. }
  1022. /**
  1023. * Get the last hour of the day.
  1024. *
  1025. * @return The last hour of the day
  1026. */
  1027. public int getLastHourOfTheDay() {
  1028. return lastHour;
  1029. }
  1030. /**
  1031. * Re-renders the whole week view.
  1032. *
  1033. * @param scroll
  1034. * The amount of pixels to scroll the week view
  1035. * @param today
  1036. * Todays date
  1037. * @param daysInMonth
  1038. * How many days are there in the month
  1039. * @param firstDayOfWeek
  1040. * The first day of the week
  1041. * @param events
  1042. * The events to render
  1043. */
  1044. public void updateWeekView(int scroll, Date today, int daysInMonth,
  1045. int firstDayOfWeek, Collection<CalendarEvent> events,
  1046. List<CalendarDay> days) {
  1047. while (outer.getWidgetCount() > 0) {
  1048. outer.remove(0);
  1049. }
  1050. monthGrid = null;
  1051. String[] realDayNames = new String[getDayNames().length];
  1052. int j = 0;
  1053. if (firstDayOfWeek == 2) {
  1054. for (int i = 1; i < getDayNames().length; i++) {
  1055. realDayNames[j++] = getDayNames()[i];
  1056. }
  1057. realDayNames[j] = getDayNames()[0];
  1058. } else {
  1059. for (int i = 0; i < getDayNames().length; i++) {
  1060. realDayNames[j++] = getDayNames()[i];
  1061. }
  1062. }
  1063. weeklyLongEvents = new WeeklyLongEvents(this);
  1064. if (weekGrid == null) {
  1065. weekGrid = new WeekGrid(this, is24HFormat());
  1066. }
  1067. updateWeekGrid(daysInMonth, days, today, realDayNames);
  1068. updateEventsToWeekGrid(sortEvents(events));
  1069. outer.add(dayToolbar, DockPanel.NORTH);
  1070. outer.add(weeklyLongEvents, DockPanel.NORTH);
  1071. outer.add(weekGrid, DockPanel.SOUTH);
  1072. weekGrid.setVerticalScrollPosition(scroll);
  1073. }
  1074. /**
  1075. * Re-renders the whole month view.
  1076. *
  1077. * @param firstDayOfWeek
  1078. * The first day of the week
  1079. * @param today
  1080. * Todays date
  1081. * @param daysInMonth
  1082. * Amount of days in the month
  1083. * @param events
  1084. * The events to render
  1085. * @param days
  1086. * The day information
  1087. */
  1088. public void updateMonthView(int firstDayOfWeek, Date today, int daysInMonth,
  1089. Collection<CalendarEvent> events, List<CalendarDay> days) {
  1090. // Remove all week numbers from bar
  1091. while (outer.getWidgetCount() > 0) {
  1092. outer.remove(0);
  1093. }
  1094. int firstDay = getFirstDayNumber();
  1095. int lastDay = getLastDayNumber();
  1096. int daysPerWeek = lastDay - firstDay + 1;
  1097. int j = 0;
  1098. String[] dayNames = getDayNames();
  1099. String[] realDayNames = new String[daysPerWeek];
  1100. if (firstDayOfWeek == 2) {
  1101. for (int i = firstDay; i < lastDay + 1; i++) {
  1102. if (i == 7) {
  1103. realDayNames[j++] = dayNames[0];
  1104. } else {
  1105. realDayNames[j++] = dayNames[i];
  1106. }
  1107. }
  1108. } else {
  1109. for (int i = firstDay - 1; i < lastDay; i++) {
  1110. realDayNames[j++] = dayNames[i];
  1111. }
  1112. }
  1113. nameToolbar.setDayNames(realDayNames);
  1114. weeklyLongEvents = null;
  1115. weekGrid = null;
  1116. updateMonthGrid(daysInMonth, days, today);
  1117. outer.add(nameToolbar, DockPanel.NORTH);
  1118. outer.add(weekToolbar, DockPanel.WEST);
  1119. weekToolbar.updateCellHeights();
  1120. outer.add(monthGrid, DockPanel.CENTER);
  1121. updateEventsToMonthGrid(events, false);
  1122. }
  1123. private DateClickListener dateClickListener;
  1124. /**
  1125. * Sets the listener for listening to event clicks.
  1126. *
  1127. * @param listener
  1128. * The listener to use
  1129. */
  1130. public void setListener(DateClickListener listener) {
  1131. dateClickListener = listener;
  1132. }
  1133. /**
  1134. * Gets the listener for listening to event clicks.
  1135. *
  1136. * @return
  1137. */
  1138. public DateClickListener getDateClickListener() {
  1139. return dateClickListener;
  1140. }
  1141. private ForwardListener forwardListener;
  1142. /**
  1143. * Set the listener which listens to forward events from the calendar.
  1144. *
  1145. * @param listener
  1146. * The listener to use
  1147. */
  1148. public void setListener(ForwardListener listener) {
  1149. forwardListener = listener;
  1150. }
  1151. /**
  1152. * Get the listener which listens to forward events from the calendar.
  1153. *
  1154. * @return
  1155. */
  1156. public ForwardListener getForwardListener() {
  1157. return forwardListener;
  1158. }
  1159. private BackwardListener backwardListener;
  1160. /**
  1161. * Set the listener which listens to backward events from the calendar.
  1162. *
  1163. * @param listener
  1164. * The listener to use
  1165. */
  1166. public void setListener(BackwardListener listener) {
  1167. backwardListener = listener;
  1168. }
  1169. /**
  1170. * Set the listener which listens to backward events from the calendar.
  1171. *
  1172. * @return
  1173. */
  1174. public BackwardListener getBackwardListener() {
  1175. return backwardListener;
  1176. }
  1177. private WeekClickListener weekClickListener;
  1178. /**
  1179. * Set the listener that listens to user clicking on the week numbers.
  1180. *
  1181. * @param listener
  1182. * The listener to use
  1183. */
  1184. public void setListener(WeekClickListener listener) {
  1185. weekClickListener = listener;
  1186. }
  1187. /**
  1188. * Get the listener that listens to user clicking on the week numbers.
  1189. *
  1190. * @return
  1191. */
  1192. public WeekClickListener getWeekClickListener() {
  1193. return weekClickListener;
  1194. }
  1195. private RangeSelectListener rangeSelectListener;
  1196. /**
  1197. * Set the listener that listens to the user highlighting a region in the
  1198. * calendar.
  1199. *
  1200. * @param listener
  1201. * The listener to use
  1202. */
  1203. public void setListener(RangeSelectListener listener) {
  1204. rangeSelectListener = listener;
  1205. }
  1206. /**
  1207. * Get the listener that listens to the user highlighting a region in the
  1208. * calendar.
  1209. *
  1210. * @return
  1211. */
  1212. public RangeSelectListener getRangeSelectListener() {
  1213. return rangeSelectListener;
  1214. }
  1215. private EventClickListener eventClickListener;
  1216. /**
  1217. * Get the listener that listens to the user clicking on the events.
  1218. */
  1219. public EventClickListener getEventClickListener() {
  1220. return eventClickListener;
  1221. }
  1222. /**
  1223. * Set the listener that listens to the user clicking on the events.
  1224. *
  1225. * @param listener
  1226. * The listener to use
  1227. */
  1228. public void setListener(EventClickListener listener) {
  1229. eventClickListener = listener;
  1230. }
  1231. private EventMovedListener eventMovedListener;
  1232. /**
  1233. * Get the listener that listens to when event is dragged to a new location.
  1234. *
  1235. * @return
  1236. */
  1237. public EventMovedListener getEventMovedListener() {
  1238. return eventMovedListener;
  1239. }
  1240. /**
  1241. * Set the listener that listens to when event is dragged to a new location.
  1242. *
  1243. * @param eventMovedListener
  1244. * The listener to use
  1245. */
  1246. public void setListener(EventMovedListener eventMovedListener) {
  1247. this.eventMovedListener = eventMovedListener;
  1248. }
  1249. private ScrollListener scrollListener;
  1250. /**
  1251. * Get the listener that listens to when the calendar widget is scrolled.
  1252. *
  1253. * @return
  1254. */
  1255. public ScrollListener getScrollListener() {
  1256. return scrollListener;
  1257. }
  1258. /**
  1259. * Set the listener that listens to when the calendar widget is scrolled.
  1260. *
  1261. * @param scrollListener
  1262. * The listener to use
  1263. */
  1264. public void setListener(ScrollListener scrollListener) {
  1265. this.scrollListener = scrollListener;
  1266. }
  1267. private EventResizeListener eventResizeListener;
  1268. /**
  1269. * Get the listener that listens to when an events time limits are being
  1270. * adjusted.
  1271. *
  1272. * @return
  1273. */
  1274. public EventResizeListener getEventResizeListener() {
  1275. return eventResizeListener;
  1276. }
  1277. /**
  1278. * Set the listener that listens to when an events time limits are being
  1279. * adjusted.
  1280. *
  1281. * @param eventResizeListener
  1282. * The listener to use
  1283. */
  1284. public void setListener(EventResizeListener eventResizeListener) {
  1285. this.eventResizeListener = eventResizeListener;
  1286. }
  1287. private MouseEventListener mouseEventListener;
  1288. private boolean forwardNavigationEnabled = true;
  1289. private boolean backwardNavigationEnabled = true;
  1290. private boolean eventCaptionAsHtml = false;
  1291. /**
  1292. * Get the listener that listen to mouse events.
  1293. *
  1294. * @return
  1295. */
  1296. public MouseEventListener getMouseEventListener() {
  1297. return mouseEventListener;
  1298. }
  1299. /**
  1300. * Set the listener that listen to mouse events.
  1301. *
  1302. * @param mouseEventListener
  1303. * The listener to use
  1304. */
  1305. public void setListener(MouseEventListener mouseEventListener) {
  1306. this.mouseEventListener = mouseEventListener;
  1307. }
  1308. /**
  1309. * Is selecting a range allowed?
  1310. */
  1311. public boolean isRangeSelectAllowed() {
  1312. return rangeSelectAllowed;
  1313. }
  1314. /**
  1315. * Set selecting a range allowed.
  1316. *
  1317. * @param rangeSelectAllowed
  1318. * Should selecting a range be allowed
  1319. */
  1320. public void setRangeSelectAllowed(boolean rangeSelectAllowed) {
  1321. this.rangeSelectAllowed = rangeSelectAllowed;
  1322. }
  1323. /**
  1324. * Is moving a range allowed.
  1325. *
  1326. * @return
  1327. */
  1328. public boolean isRangeMoveAllowed() {
  1329. return rangeMoveAllowed;
  1330. }
  1331. /**
  1332. * Is moving a range allowed.
  1333. *
  1334. * @param rangeMoveAllowed
  1335. * Is it allowed
  1336. */
  1337. public void setRangeMoveAllowed(boolean rangeMoveAllowed) {
  1338. this.rangeMoveAllowed = rangeMoveAllowed;
  1339. }
  1340. /**
  1341. * Is resizing an event allowed.
  1342. */
  1343. public boolean isEventResizeAllowed() {
  1344. return eventResizeAllowed;
  1345. }
  1346. /**
  1347. * Is resizing an event allowed.
  1348. *
  1349. * @param eventResizeAllowed
  1350. * True if allowed false if not
  1351. */
  1352. public void setEventResizeAllowed(boolean eventResizeAllowed) {
  1353. this.eventResizeAllowed = eventResizeAllowed;
  1354. }
  1355. /**
  1356. * Is moving an event allowed.
  1357. */
  1358. public boolean isEventMoveAllowed() {
  1359. return eventMoveAllowed;
  1360. }
  1361. /**
  1362. * Is moving an event allowed.
  1363. *
  1364. * @param eventMoveAllowed
  1365. * True if moving is allowed, false if not
  1366. */
  1367. public void setEventMoveAllowed(boolean eventMoveAllowed) {
  1368. this.eventMoveAllowed = eventMoveAllowed;
  1369. }
  1370. public boolean isBackwardNavigationEnabled() {
  1371. return backwardNavigationEnabled;
  1372. }
  1373. public void setBackwardNavigationEnabled(boolean enabled) {
  1374. backwardNavigationEnabled = enabled;
  1375. }
  1376. public boolean isForwardNavigationEnabled() {
  1377. return forwardNavigationEnabled;
  1378. }
  1379. public void setForwardNavigationEnabled(boolean enabled) {
  1380. forwardNavigationEnabled = enabled;
  1381. }
  1382. /*
  1383. * (non-Javadoc)
  1384. *
  1385. * @see com.vaadin.client.ui.dd.VHasDropHandler#getDropHandler()
  1386. */
  1387. @Override
  1388. public CalendarDropHandler getDropHandler() {
  1389. return dropHandler;
  1390. }
  1391. /**
  1392. * Set the drop handler.
  1393. *
  1394. * @param dropHandler
  1395. * The drophandler to use
  1396. */
  1397. public void setDropHandler(CalendarDropHandler dropHandler) {
  1398. this.dropHandler = dropHandler;
  1399. }
  1400. /**
  1401. * Sets whether the event captions are rendered as HTML.
  1402. * <p>
  1403. * If set to true, the captions are rendered in the browser as HTML and the
  1404. * developer is responsible for ensuring no harmful HTML is used. If set to
  1405. * false, the caption is rendered in the browser as plain text.
  1406. * <p>
  1407. * The default is false, i.e. to render that caption as plain text.
  1408. *
  1409. * @param eventCaptionAsHtml
  1410. * {@code true} if the captions are rendered as HTML,
  1411. * {@code false} if rendered as plain text
  1412. */
  1413. public void setEventCaptionAsHtml(boolean eventCaptionAsHtml) {
  1414. this.eventCaptionAsHtml = eventCaptionAsHtml;
  1415. }
  1416. /**
  1417. * Checks whether event captions are rendered as HTML
  1418. * <p>
  1419. * The default is false, i.e. to render that caption as plain text.
  1420. *
  1421. * @return true if the captions are rendered as HTML, false if rendered as
  1422. * plain text
  1423. */
  1424. public boolean isEventCaptionAsHtml() {
  1425. return eventCaptionAsHtml;
  1426. }
  1427. /**
  1428. * Set sort strategy for events.
  1429. *
  1430. * @param order
  1431. * sort order
  1432. */
  1433. public void setSortOrder(EventSortOrder order) {
  1434. if (order == null) {
  1435. eventSortOrder = EventSortOrder.DURATION_DESC;
  1436. } else {
  1437. eventSortOrder = order;
  1438. }
  1439. }
  1440. /**
  1441. * Return currently active sort order.
  1442. *
  1443. * @return current sort order
  1444. */
  1445. public EventSortOrder getSortOrder() {
  1446. return eventSortOrder;
  1447. }
  1448. }