diff options
Diffstat (limited to 'client')
5 files changed, 77 insertions, 58 deletions
diff --git a/client/src/com/vaadin/client/ui/VCalendar.java b/client/src/com/vaadin/client/ui/VCalendar.java index c5c12f2d72..38bcc0b14f 100644 --- a/client/src/com/vaadin/client/ui/VCalendar.java +++ b/client/src/com/vaadin/client/ui/VCalendar.java @@ -39,6 +39,8 @@ import com.vaadin.client.ui.calendar.schedule.SimpleDayToolbar; 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; /** @@ -47,7 +49,7 @@ 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"; @@ -96,6 +98,8 @@ public class VCalendar extends Composite { private int firstHour; private int lastHour; + private CalendarDropHandler dropHandler; + /** * Listener interface for listening to event click events */ @@ -1443,4 +1447,24 @@ public class VCalendar extends Composite { 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; + } } diff --git a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java index be3abb39ea..5a83579d46 100644 --- a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java +++ b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java @@ -19,6 +19,7 @@ import java.text.ParseException; 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; @@ -30,6 +31,7 @@ import com.google.gwt.user.client.Element; 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; @@ -60,7 +62,8 @@ import com.vaadin.client.ui.calendar.schedule.HasTooltipKey; 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; @@ -79,16 +82,16 @@ import com.vaadin.ui.Calendar; */ @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"; + /** * */ @@ -306,13 +309,16 @@ public class CalendarConnector extends AbstractComponentConnector implements }); } + 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)); @@ -336,10 +342,19 @@ public class CalendarConnector extends AbstractComponentConnector implements 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(); @@ -355,32 +370,22 @@ public class CalendarConnector extends AbstractComponentConnector implements * 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); + } + } } /** @@ -449,27 +454,6 @@ public class CalendarConnector extends AbstractComponentConnector implements 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++) { diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarDropHandler.java b/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarDropHandler.java index aab9ca9c38..ab0c9f2e9a 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarDropHandler.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarDropHandler.java @@ -28,15 +28,16 @@ import com.vaadin.client.ui.dd.VAbstractDropHandler; */ 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; } /* diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarMonthDropHandler.java b/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarMonthDropHandler.java index 913477ee14..fd0be4881e 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarMonthDropHandler.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarMonthDropHandler.java @@ -18,6 +18,7 @@ package com.vaadin.client.ui.calendar.schedule.dd; 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; @@ -32,6 +33,10 @@ import com.vaadin.client.ui.dd.VDragEvent; */ public class CalendarMonthDropHandler extends CalendarDropHandler { + public CalendarMonthDropHandler(CalendarConnector connector) { + super(connector); + } + private Element currentTargetElement; private SimpleDayCell currentTargetDay; diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarWeekDropHandler.java b/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarWeekDropHandler.java index 0ea683dc3c..cede1827a2 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarWeekDropHandler.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarWeekDropHandler.java @@ -18,6 +18,7 @@ package com.vaadin.client.ui.calendar.schedule.dd; 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; @@ -36,6 +37,10 @@ public class CalendarWeekDropHandler extends CalendarDropHandler { private com.google.gwt.user.client.Element currentTargetElement; private DateCell currentTargetDay; + public CalendarWeekDropHandler(CalendarConnector connector) { + super(connector); + } + /* * (non-Javadoc) * |