From edc3b08defa815d9f65a9589c7a252ad99ea40fa Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Thu, 28 Dec 2017 13:49:39 +0200 Subject: Allow setting custom styles to DateField calendar date cells (#10305) Fixes #10304 --- .../com/vaadin/client/ui/VAbstractCalendarPanel.java | 17 +++++++++++++++++ .../ui/datefield/AbstractInlineDateFieldConnector.java | 3 +++ .../client/ui/datefield/TextualDateConnector.java | 12 ++++++++++++ 3 files changed, 32 insertions(+) (limited to 'client') diff --git a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java index f009f483e0..fbfde9a3f1 100644 --- a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java +++ b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java @@ -17,7 +17,9 @@ package com.vaadin.client.ui; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.function.Predicate; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -44,6 +46,7 @@ import com.google.gwt.event.dom.client.MouseOutEvent; import com.google.gwt.event.dom.client.MouseOutHandler; import com.google.gwt.event.dom.client.MouseUpEvent; import com.google.gwt.event.dom.client.MouseUpHandler; +import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.Button; @@ -191,6 +194,9 @@ public abstract class VAbstractCalendarPanel> onSubmit(); }; + private Map dateStyles = new HashMap(); + private DateTimeFormat df = DateTimeFormat.getFormat("yyyy-MM-dd"); + public VAbstractCalendarPanel() { getElement().setId(DOM.createUniqueId()); setStyleName(VDateField.CLASSNAME + "-calendarpanel"); @@ -446,6 +452,13 @@ public abstract class VAbstractCalendarPanel> } } + public void setDateStyles(Map dateStyles) { + this.dateStyles.clear(); + if (dateStyles != null) { + this.dateStyles.putAll(dateStyles); + } + } + private void clearCalendarBody(boolean remove) { if (!remove) { // Leave the cells in place but clear their contents @@ -833,6 +846,10 @@ public abstract class VAbstractCalendarPanel> if (curr.getMonth() != displayedMonth.getMonth()) { day.addStyleDependentName(CN_OFFMONTH); } + String dayDateString = df.format(dayDate); + if (dateStyles.containsKey(dayDateString)) { + day.addStyleName(dateStyles.get(dayDateString)); + } days.setWidget(weekOfMonth, firstWeekdayColumn + dayOfWeek, day); diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/AbstractInlineDateFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/AbstractInlineDateFieldConnector.java index 54294b54ae..2492272111 100644 --- a/client/src/main/java/com/vaadin/client/ui/datefield/AbstractInlineDateFieldConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/datefield/AbstractInlineDateFieldConnector.java @@ -46,6 +46,7 @@ public abstract class AbstractInlineDateFieldConnector widget = getWidget(); if (isResolutionMonthOrHigher()) { @@ -90,6 +91,7 @@ public abstract class AbstractInlineDateFieldConnector getWidget() { return (VAbstractDateFieldCalendar) super.getWidget(); } diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java index c7cfdef71d..0702211ccb 100644 --- a/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java @@ -23,6 +23,7 @@ import com.google.gwt.event.logical.shared.CloseHandler; import com.google.gwt.user.client.ui.PopupPanel; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.UIDL; +import com.vaadin.client.annotations.OnStateChange; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.VAbstractCalendarPanel; import com.vaadin.client.ui.VAbstractCalendarPanel.FocusChangeListener; @@ -125,6 +126,7 @@ public abstract class TextualDateConnector widget = getWidget(); + widget.calendar.setDateStyles(getState().dateStyles); + // Update text field if locale already set + if (widget.getCurrentLocale() != null) { + widget.buildDate(); + } + } + } -- cgit v1.2.3