import com.vaadin.client.ui.calendar.schedule.SimpleWeekToolbar;
import com.vaadin.client.ui.calendar.schedule.WeekGrid;
import com.vaadin.client.ui.calendar.schedule.WeeklyLongEvents;
+import com.vaadin.client.ui.calendar.schedule.dd.CalendarDropHandler;
+import com.vaadin.client.ui.dd.VHasDropHandler;
import com.vaadin.shared.ui.calendar.DateConstants;
/**
* @since 7.1
* @author Vaadin Ltd.
*/
-public class VCalendar extends Composite {
+public class VCalendar extends Composite implements VHasDropHandler {
public static final String ATTR_FIRSTDAYOFWEEK = "firstDay";
public static final String ATTR_LASTDAYOFWEEK = "lastDay";
private int firstHour;
private int lastHour;
+ private CalendarDropHandler dropHandler;
+
/**
* Listener interface for listening to event click events
*/
public void setForwardNavigationEnabled(boolean enabled) {
forwardNavigationEnabled = enabled;
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.client.ui.dd.VHasDropHandler#getDropHandler()
+ */
+ @Override
+ public CalendarDropHandler getDropHandler() {
+ return dropHandler;
+ }
+
+ /**
+ * Set the drop handler
+ *
+ * @param dropHandler
+ * The drophandler to use
+ */
+ public void setDropHandler(CalendarDropHandler dropHandler) {
+ this.dropHandler = dropHandler;
+ }
}
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
+import com.vaadin.client.Paintable;
import com.vaadin.client.TooltipInfo;
import com.vaadin.client.UIDL;
import com.vaadin.client.Util;
import com.vaadin.client.ui.calendar.schedule.MonthEventLabel;
import com.vaadin.client.ui.calendar.schedule.SimpleDayCell;
import com.vaadin.client.ui.calendar.schedule.dd.CalendarDropHandler;
-import com.vaadin.client.ui.dd.VHasDropHandler;
+import com.vaadin.client.ui.calendar.schedule.dd.CalendarMonthDropHandler;
+import com.vaadin.client.ui.calendar.schedule.dd.CalendarWeekDropHandler;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.Connect.LoadStyle;
import com.vaadin.shared.ui.calendar.CalendarClientRpc;
*/
@Connect(value = Calendar.class, loadStyle = LoadStyle.LAZY)
public class CalendarConnector extends AbstractComponentConnector implements
- VHasDropHandler, ActionOwner, SimpleManagedLayout {
+ ActionOwner, SimpleManagedLayout, Paintable {
private CalendarServerRpc rpc = RpcProxy.create(CalendarServerRpc.class,
this);
- private CalendarDropHandler dropHandler;
-
private final HashMap<String, String> actionMap = new HashMap<String, String>();
private HashMap<Object, String> tooltips = new HashMap<Object, String>();
+ private static final String DROPHANDLER_ACCEPT_CRITERIA_PAINT_TAG = "-ac";
+
/**
*
*/
});
}
+ private boolean showingMonthView() {
+ return getState().days.size() > 7;
+ }
+
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
CalendarState state = getState();
VCalendar widget = getWidget();
- boolean monthView = state.days.size() > 7;
// Enable or disable the forward and backward navigation buttons
widget.setForwardNavigationEnabled(hasEventListener(CalendarEventId.FORWARD));
List<CalendarState.Day> days = state.days;
List<CalendarState.Event> events = state.events;
- if (monthView) {
+ CalendarDropHandler dropHandler = getWidget().getDropHandler();
+ if (showingMonthView()) {
updateMonthView(days, events);
+ if (dropHandler != null
+ && !(dropHandler instanceof CalendarMonthDropHandler)) {
+ getWidget().setDropHandler(new CalendarMonthDropHandler(this));
+ }
} else {
updateWeekView(days, events);
+ if (dropHandler != null
+ && !(dropHandler instanceof CalendarWeekDropHandler)) {
+ getWidget().setDropHandler(new CalendarWeekDropHandler(this));
+ }
}
updateSizes();
* com.vaadin.terminal.gwt.client.Paintable#updateFromUIDL(com.vaadin.terminal
* .gwt.client.UIDL, com.vaadin.terminal.gwt.client.ApplicationConnection)
*/
+ @Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-
- // check for DD -related access criteria
- // Iterator<Object> childIterator = uidl.getChildIterator();
- // while (childIterator.hasNext()) {
- // UIDL child = (UIDL) childIterator.next();
- //
- // // Drag&drop
- // if (ACCESSCRITERIA.equals(child.getTag())) {
- // if (monthView
- // && !(getDropHandler() instanceof CalendarMonthDropHandler)) {
- // setDropHandler(new CalendarMonthDropHandler());
- //
- // } else if (!monthView
- // && !(getDropHandler() instanceof CalendarWeekDropHandler)) {
- // setDropHandler(new CalendarWeekDropHandler());
- // }
- //
- // getDropHandler().setCalendarPaintable(this);
- // getDropHandler().updateAcceptRules(child);
- //
- // } else {
- // setDropHandler(null);
- // }
- //
- // }
+ Iterator<Object> childIterator = uidl.getChildIterator();
+ while (childIterator.hasNext()) {
+ UIDL child = (UIDL) childIterator.next();
+ if (DROPHANDLER_ACCEPT_CRITERIA_PAINT_TAG.equals(child.getTag())) {
+ if (getWidget().getDropHandler() == null) {
+ getWidget().setDropHandler(
+ showingMonthView() ? new CalendarMonthDropHandler(
+ this) : new CalendarWeekDropHandler(this));
+ }
+ getWidget().getDropHandler().updateAcceptRules(child);
+ } else {
+ getWidget().setDropHandler(null);
+ }
+ }
}
/**
calendarDayListOf(days));
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.vaadin.terminal.gwt.client.ui.dd.VHasDropHandler#getDropHandler()
- */
- @Override
- public CalendarDropHandler getDropHandler() {
- return dropHandler;
- }
-
- /**
- * Set the drop handler
- *
- * @param dropHandler
- * The drophandler to use
- */
- public void setDropHandler(CalendarDropHandler dropHandler) {
- this.dropHandler = dropHandler;
- }
-
private Action[] getActionsBetween(Date start, Date end) {
List<Action> actions = new ArrayList<Action>();
for (int i = 0; i < actionKeys.size(); i++) {
*/
public abstract class CalendarDropHandler extends VAbstractDropHandler {
- protected CalendarConnector calendarConnector;
+ protected final CalendarConnector calendarConnector;
/**
- * Set the calendar instance
+ * Constructor
*
- * @param calendarPaintable
+ * @param connector
+ * The connector of the calendar
*/
- public void setConnector(CalendarConnector calendarConnector) {
- this.calendarConnector = calendarConnector;
+ public CalendarDropHandler(CalendarConnector connector) {
+ calendarConnector = connector;
}
/*
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.vaadin.client.Util;
+import com.vaadin.client.ui.calendar.CalendarConnector;
import com.vaadin.client.ui.calendar.schedule.SimpleDayCell;
import com.vaadin.client.ui.dd.VAcceptCallback;
import com.vaadin.client.ui.dd.VDragEvent;
*/
public class CalendarMonthDropHandler extends CalendarDropHandler {
+ public CalendarMonthDropHandler(CalendarConnector connector) {
+ super(connector);
+ }
+
private Element currentTargetElement;
private SimpleDayCell currentTargetDay;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.vaadin.client.Util;
+import com.vaadin.client.ui.calendar.CalendarConnector;
import com.vaadin.client.ui.calendar.schedule.DateCell;
import com.vaadin.client.ui.calendar.schedule.DateCellDayEvent;
import com.vaadin.client.ui.dd.VAcceptCallback;
private com.google.gwt.user.client.Element currentTargetElement;
private DateCell currentTargetDay;
+ public CalendarWeekDropHandler(CalendarConnector connector) {
+ super(connector);
+ }
+
/*
* (non-Javadoc)
*
import com.vaadin.event.dd.DropTarget;
import com.vaadin.event.dd.TargetDetails;
import com.vaadin.server.KeyMapper;
+import com.vaadin.server.PaintException;
+import com.vaadin.server.PaintTarget;
import com.vaadin.shared.ui.calendar.CalendarEventId;
import com.vaadin.shared.ui.calendar.CalendarServerRpc;
import com.vaadin.shared.ui.calendar.CalendarState;
CalendarComponentEvents.RangeSelectNotifier,
CalendarComponentEvents.EventResizeNotifier,
CalendarEventProvider.EventSetChangeListener, DropTarget,
- CalendarEditableEventProvider, Action.Container {
+ CalendarEditableEventProvider, Action.Container, LegacyComponent {
/**
* Calendar can use either 12 hours clock or 24 hours clock.
}
}
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.server.VariableOwner#changeVariables(java.lang.Object,
+ * java.util.Map)
+ */
+ @Override
+ public void changeVariables(Object source, Map<String, Object> variables) {
+ /*
+ * Only defined to fulfill the LegacyComponent interface used for
+ * calendar drag & drop. No implementation required.
+ */
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.ui.LegacyComponent#paintContent(com.vaadin.server.PaintTarget)
+ */
+ @Override
+ public void paintContent(PaintTarget target) throws PaintException {
+ if (dropHandler != null) {
+ dropHandler.getAcceptCriterion().paint(target);
+ }
+ }
}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:7171/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.calendar.CalendarDragAndDrop?restartApplication</td>
+ <td></td>
+</tr>
+<!--// Test drag and drop in month view-->
+<tr>
+ <td>drag</td>
+ <td>vaadin=runcomvaadintestscomponentscalendarCalendarDragAndDrop::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[1]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[9]/domChild[0]/domChild[0]</td>
+ <td>76,7</td>
+</tr>
+<tr>
+ <td>drop</td>
+ <td>vaadin=runcomvaadintestscomponentscalendarCalendarDragAndDrop::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[0]/VCalendar[0]/domChild[0]/domChild[1]/domChild[1]/domChild[0]/domChild[1]/domChild[1]/domChild[5]/domChild[0]/domChild[2]</td>
+ <td>54,9</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentscalendarCalendarDragAndDrop::PID_SCalendar/domChild[0]/domChild[1]/domChild[1]/domChild[0]/domChild[1]/domChild[1]/domChild[5]/domChild[0]/domChild[1]</td>
+ <td>12:00 AM Event 10</td>
+</tr>
+<!--//Test drag and drop in week view-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentscalendarCalendarDragAndDrop::PID_SCalendar/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[1]/domChild[1]/domChild[0]/domChild[0]</td>
+ <td>7,85</td>
+</tr>
+<tr>
+ <td>drag</td>
+ <td>vaadin=runcomvaadintestscomponentscalendarCalendarDragAndDrop::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[1]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[11]/domChild[0]/domChild[0]</td>
+ <td>34,12</td>
+</tr>
+<tr>
+ <td>drop</td>
+ <td>vaadin=runcomvaadintestscomponentscalendarCalendarDragAndDrop::PID_SCalendar/domChild[0]/domChild[3]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[2]/domChild[0]/domChild[15]</td>
+ <td>75,9</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentscalendarCalendarDragAndDrop::PID_SCalendar/domChild[0]/domChild[3]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[2]/domChild[0]/domChild[48]/domChild[0]</td>
+ <td>7:30 AM: Event 13</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
--- /dev/null
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+/**
+ *
+ */
+package com.vaadin.tests.components.calendar;
+
+import java.util.GregorianCalendar;
+import java.util.Locale;
+
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.event.dd.DropHandler;
+import com.vaadin.event.dd.acceptcriteria.AcceptAll;
+import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Calendar;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.Table.TableDragMode;
+import com.vaadin.ui.Table.TableTransferable;
+import com.vaadin.ui.components.calendar.CalendarTargetDetails;
+import com.vaadin.ui.components.calendar.event.BasicEvent;
+
+public class CalendarDragAndDrop extends AbstractTestUI {
+
+ private Calendar calendar;
+
+ private Table table;
+
+ private class TestDropHandler implements DropHandler {
+
+ @Override
+ public void drop(DragAndDropEvent event) {
+ CalendarTargetDetails details = (CalendarTargetDetails) event
+ .getTargetDetails();
+
+ TableTransferable transferable = (TableTransferable) event
+ .getTransferable();
+
+ calendar.addEvent(new BasicEvent(transferable.getItemId()
+ .toString(), "This event was dragged here", details
+ .getDropTime()));
+
+ table.removeItem(transferable.getItemId());
+ }
+
+ @Override
+ public AcceptCriterion getAcceptCriterion() {
+ return AcceptAll.get();
+ }
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ setSizeFull();
+ getContent().setSizeFull();
+ getLayout().setSizeFull();
+
+ HorizontalLayout root = new HorizontalLayout();
+ root.setSizeFull();
+ addComponent(root);
+
+ Locale locale = new Locale("en", "US");
+ GregorianCalendar cal = new GregorianCalendar(locale);
+ cal.set(2013, 0, 1);
+
+ calendar = new Calendar();
+ calendar.setId("Calendar");
+ calendar.setLocale(locale);
+ calendar.setDropHandler(new TestDropHandler());
+ calendar.setSizeFull();
+ root.addComponent(calendar);
+
+ calendar.setStartDate(cal.getTime());
+ cal.add(java.util.Calendar.MONTH, 1);
+ calendar.setEndDate(cal.getTime());
+
+ table = new Table();
+ table.setSizeFull();
+ table.setDragMode(TableDragMode.ROW);
+ table.addGeneratedColumn("COLUMN", new Table.ColumnGenerator() {
+
+ @Override
+ public Object generateCell(Table source, Object itemId,
+ Object columnId) {
+ return itemId;
+ }
+ });
+
+ for (int eventNum = 1; eventNum < 50; eventNum++) {
+ table.addItem("Event " + eventNum);
+ }
+
+ root.addComponent(table);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 11048;
+ }
+
+}