diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2017-12-28 13:49:39 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-12-28 13:49:39 +0200 |
commit | edc3b08defa815d9f65a9589c7a252ad99ea40fa (patch) | |
tree | 3306cc2c06cf492aabc874531820a3ce3204f1de /client | |
parent | aa1371c84a5642c8b01603764291b746ff85f79d (diff) | |
download | vaadin-framework-edc3b08defa815d9f65a9589c7a252ad99ea40fa.tar.gz vaadin-framework-edc3b08defa815d9f65a9589c7a252ad99ea40fa.zip |
Allow setting custom styles to DateField calendar date cells (#10305)
Fixes #10304
Diffstat (limited to 'client')
3 files changed, 32 insertions, 0 deletions
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<R extends Enum<R>> onSubmit(); }; + private Map<String, String> dateStyles = new HashMap<String, String>(); + 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<R extends Enum<R>> } } + public void setDateStyles(Map<String, String> 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<R extends Enum<R>> 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<PANEL extends VAbstractCa * {@link #updateFromUIDL(UIDL, ApplicationConnection)} method as is and * customizing only listeners logic. */ + @SuppressWarnings("deprecation") protected void updateListeners() { VAbstractDateFieldCalendar<PANEL, R> widget = getWidget(); if (isResolutionMonthOrHigher()) { @@ -90,6 +91,7 @@ public abstract class AbstractInlineDateFieldConnector<PANEL extends VAbstractCa } else { widget.calendarPanel.setDate(null); } + widget.calendarPanel.setDateStyles(getState().dateStyles); updateListeners(); @@ -98,6 +100,7 @@ public abstract class AbstractInlineDateFieldConnector<PANEL extends VAbstractCa } @Override + @SuppressWarnings("unchecked") public VAbstractDateFieldCalendar<PANEL, R> getWidget() { return (VAbstractDateFieldCalendar<PANEL, R>) 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<PANEL extends VAbstractCalendarPanel< getWidget().setRangeStart(nullSafeDateClone(getState().rangeStart)); getWidget().setRangeEnd(nullSafeDateClone(getState().rangeEnd)); + getWidget().calendar.setDateStyles(getState().dateStyles); getWidget().calendar .setDateTimeService(getWidget().getDateTimeService()); getWidget().calendar @@ -194,4 +196,14 @@ public abstract class TextualDateConnector<PANEL extends VAbstractCalendarPanel< getWidget().getStylePrimaryName() + "-popup" + styleName, add); } + @OnStateChange("dateStyles") + void dateStylesUpdated() { + VAbstractPopupCalendar<PANEL, R> widget = getWidget(); + widget.calendar.setDateStyles(getState().dateStyles); + // Update text field if locale already set + if (widget.getCurrentLocale() != null) { + widget.buildDate(); + } + } + } |