2 * Copyright 2000-2018 Vaadin Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
16 package com.vaadin.v7.client.ui.calendar.schedule.dd;
18 import com.google.gwt.dom.client.Element;
19 import com.google.gwt.user.client.DOM;
20 import com.vaadin.client.WidgetUtil;
21 import com.vaadin.client.ui.dd.VAcceptCallback;
22 import com.vaadin.client.ui.dd.VDragEvent;
23 import com.vaadin.v7.client.ui.calendar.CalendarConnector;
24 import com.vaadin.v7.client.ui.calendar.schedule.SimpleDayCell;
27 * Handles DD when the monthly view is showing in the Calendar. In the monthly
28 * view, drops are only allowed in the the day cells. Only the day index is
29 * included in the drop details sent to the server.
34 public class CalendarMonthDropHandler extends CalendarDropHandler {
36 public CalendarMonthDropHandler(CalendarConnector connector) {
40 private Element currentTargetElement;
41 private SimpleDayCell currentTargetDay;
47 * com.vaadin.terminal.gwt.client.ui.dd.VAbstractDropHandler#dragAccepted
48 * (com.vaadin.terminal.gwt.client.ui.dd.VDragEvent)
51 protected void dragAccepted(VDragEvent drag) {
53 currentTargetElement = drag.getElementOver();
54 currentTargetDay = WidgetUtil.findWidget(currentTargetElement,
60 * Removed the emphasis CSS style name from the currently emphasized day
62 private void deEmphasis() {
63 if (currentTargetElement != null && currentTargetDay != null) {
64 currentTargetDay.removeEmphasisStyle();
65 currentTargetElement = null;
70 * Add CSS style name for the currently emphasized day
72 private void emphasis() {
73 if (currentTargetElement != null && currentTargetDay != null) {
74 currentTargetDay.addEmphasisStyle();
82 * com.vaadin.terminal.gwt.client.ui.dd.VAbstractDropHandler#dragOver(com
83 * .vaadin.terminal.gwt.client.ui.dd.VDragEvent)
86 public void dragOver(final VDragEvent drag) {
87 if (isLocationValid(drag.getElementOver())) {
88 validate(new VAcceptCallback() {
90 public void accepted(VDragEvent event) {
98 * Checks if the one can perform a drop in a element
101 * The element to check
104 private boolean isLocationValid(Element elementOver) {
105 Element monthGridElement = calendarConnector.getWidget().getMonthGrid()
108 // drops are not allowed in:
110 // - week number bart
111 return DOM.isOrHasChild(monthGridElement, elementOver);
118 * com.vaadin.terminal.gwt.client.ui.dd.VAbstractDropHandler#dragEnter(com
119 * .vaadin.terminal.gwt.client.ui.dd.VDragEvent)
122 public void dragEnter(VDragEvent drag) {
123 // NOOP, we determine drag acceptance in dragOver
130 * com.vaadin.terminal.gwt.client.ui.dd.VAbstractDropHandler#drop(com.vaadin
131 * .terminal.gwt.client.ui.dd.VDragEvent)
134 public boolean drop(VDragEvent drag) {
135 if (isLocationValid(drag.getElementOver())) {
136 updateDropDetails(drag);
138 return super.drop(drag);
147 * Updates the drop details sent to the server
152 private void updateDropDetails(VDragEvent drag) {
153 int dayIndex = calendarConnector.getWidget().getMonthGrid()
154 .getDayCellIndex(currentTargetDay);
156 drag.getDropDetails().put("dropDayIndex", dayIndex);
163 * com.vaadin.terminal.gwt.client.ui.dd.VAbstractDropHandler#dragLeave(com
164 * .vaadin.terminal.gwt.client.ui.dd.VDragEvent)
167 public void dragLeave(VDragEvent drag) {
169 super.dragLeave(drag);