Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DateCellContainer.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.schedule;
  17. import java.util.Date;
  18. import com.google.gwt.event.dom.client.MouseDownEvent;
  19. import com.google.gwt.event.dom.client.MouseDownHandler;
  20. import com.google.gwt.event.dom.client.MouseUpEvent;
  21. import com.google.gwt.event.dom.client.MouseUpHandler;
  22. import com.google.gwt.user.client.ui.FlowPanel;
  23. import com.google.gwt.user.client.ui.Widget;
  24. import com.vaadin.client.WidgetUtil;
  25. import com.vaadin.client.ui.VCalendar;
  26. /**
  27. * Internally used class by the Calendar
  28. *
  29. * since 7.1
  30. */
  31. public class DateCellContainer extends FlowPanel implements MouseDownHandler,
  32. MouseUpHandler {
  33. private Date date;
  34. private Widget clickTargetWidget;
  35. private VCalendar calendar;
  36. private static int borderWidth = -1;
  37. public DateCellContainer() {
  38. setStylePrimaryName("v-calendar-datecell");
  39. }
  40. public static int measureBorderWidth(DateCellContainer dc) {
  41. if (borderWidth == -1) {
  42. borderWidth = WidgetUtil.measureHorizontalBorder(dc.getElement());
  43. }
  44. return borderWidth;
  45. }
  46. public void setCalendar(VCalendar calendar) {
  47. this.calendar = calendar;
  48. }
  49. public void setDate(Date date) {
  50. this.date = date;
  51. }
  52. public Date getDate() {
  53. return date;
  54. }
  55. public boolean hasEvent(int slotIndex) {
  56. return hasDateCell(slotIndex)
  57. && ((WeeklyLongEventsDateCell) getChildren().get(slotIndex))
  58. .getEvent() != null;
  59. }
  60. public boolean hasDateCell(int slotIndex) {
  61. return (getChildren().size() - 1) >= slotIndex;
  62. }
  63. public WeeklyLongEventsDateCell getDateCell(int slotIndex) {
  64. if (!hasDateCell(slotIndex)) {
  65. addEmptyEventCells(slotIndex - (getChildren().size() - 1));
  66. }
  67. return (WeeklyLongEventsDateCell) getChildren().get(slotIndex);
  68. }
  69. public void addEmptyEventCells(int eventCount) {
  70. for (int i = 0; i < eventCount; i++) {
  71. addEmptyEventCell();
  72. }
  73. }
  74. public void addEmptyEventCell() {
  75. WeeklyLongEventsDateCell dateCell = new WeeklyLongEventsDateCell();
  76. dateCell.addMouseDownHandler(this);
  77. dateCell.addMouseUpHandler(this);
  78. add(dateCell);
  79. }
  80. @Override
  81. public void onMouseDown(MouseDownEvent event) {
  82. clickTargetWidget = (Widget) event.getSource();
  83. event.stopPropagation();
  84. }
  85. @Override
  86. public void onMouseUp(MouseUpEvent event) {
  87. if (event.getSource() == clickTargetWidget
  88. && clickTargetWidget instanceof WeeklyLongEventsDateCell
  89. && !calendar.isDisabledOrReadOnly()) {
  90. CalendarEvent calendarEvent = ((WeeklyLongEventsDateCell) clickTargetWidget)
  91. .getEvent();
  92. if (calendar.getEventClickListener() != null) {
  93. calendar.getEventClickListener().eventClick(calendarEvent);
  94. }
  95. }
  96. }
  97. }