/** * Adds the given style name to the specified dates, which must be visible. * This is only set until the next time the DatePicker is refreshed. */ public void addTransientStyleToDates(String styleName, Date date) { assert isDateVisible(date) : date + " must be visible"; getView().addStyleToDate(styleName, date); }
/** * Allows the calendar view to update the date picker's highlighted date. * * @param date the highlighted date */ protected final void setHighlightedDate(Date date) { getDatePicker().setHighlightedDate(date); } }
/** * Is the date currently shown in the date picker? * * @param date * * @return is the date currently shown */ public boolean isDateVisible(Date date) { CalendarView r = getView(); Date first = r.getFirstDate(); Date last = r.getLastDate(); return (date != null && (CalendarUtil.isSameDate(first, date) || CalendarUtil.isSameDate(last, date) || (first.before(date) && last.after(date)))); }
/** * Creates a new date picker. * * @param monthAndYearSelector the month selector * @param view the view * @param model the model */ protected DatePicker(MonthSelector monthAndYearSelector, CalendarView view, CalendarModel model) { this.model = model; this.monthAndYearSelector = monthAndYearSelector; monthAndYearSelector.setDatePicker(this); this.view = view; view.setDatePicker(this); view.setup(); monthAndYearSelector.setup(); this.setup(); setCurrentMonth(new Date()); addStyleToDates(css().dayIsToday(), new Date()); }
/** * Refreshes all components of this date picker. */ protected final void refreshAll() { highlighted = null; getModel().refresh(); getView().refresh(); getMonthSelector().refresh(); if (isAttached()) { ShowRangeEvent.fire(this, getFirstDate(), getLastDate()); } getView().setAriaSelectedCell(value); }
/** * Sets a visible date to be enabled or disabled. This is only set until the * next time the DatePicker is refreshed. */ public final void setTransientEnabledOnDates(boolean enabled, Date date) { assert isDateVisible(date) : date + " must be visible"; getView().setEnabledOnDate(enabled, date); }
/** * Removes the styleName from the given dates (even if it is transient). */ public void removeStyleFromDates(String styleName, Date date) { styler.setStyleName(date, styleName, false); if (isDateVisible(date)) { getView().removeStyleFromDate(styleName, date); } }
/** * Is the visible date enabled? * * @param date the date, which must be visible * * @return is the date enabled? */ public boolean isDateEnabled(Date date) { assert isDateVisible(date) : date + " is not visible"; return getView().isDateEnabled(date); }
/** * Returns the last shown date. * * @return the last date. */ // Final because the view should always control the value of the last date. public final Date getLastDate() { return view.getLastDate(); }
/** * Returns the first shown date. * * @return the first date. */ // Final because the view should always control the value of the first date. public final Date getFirstDate() { return view.getFirstDate(); }
/** * Sets the {@link DatePicker}'s value. * * @param newValue the new value for this date picker * @param fireEvents should events be fired. */ public final void setValue(Date newValue, boolean fireEvents) { Date oldValue = value; if (oldValue != null) { removeStyleFromDates(css().dayIsValue(), oldValue); } value = CalendarUtil.copyDate(newValue); if (value != null) { addStyleToDates(css().dayIsValue(), value); } getView().setAriaSelectedCell(newValue); if (fireEvents) { DateChangeEvent.fireIfNotEqualDates(this, oldValue, newValue); } }
/** * Refreshes all components of this date picker. */ protected final void refreshAll() { highlighted = null; getModel().refresh(); getView().refresh(); getMonthSelector().refresh(); if (isAttached()) { ShowRangeEvent.fire(this, getFirstDate(), getLastDate()); } getView().setAriaSelectedCell(value); }
/** * Creates a new date picker. * * @param monthAndYearSelector the month selector * @param view the view * @param model the model */ protected DatePicker(MonthSelector monthAndYearSelector, CalendarView view, CalendarModel model) { this.model = model; this.monthAndYearSelector = monthAndYearSelector; monthAndYearSelector.setDatePicker(this); this.view = view; view.setDatePicker(this); view.setup(); monthAndYearSelector.setup(); this.setup(); setCurrentMonth(new Date()); addStyleToDates(css().dayIsToday(), new Date()); }
/** * Sets a visible date to be enabled or disabled. This is only set until the * next time the DatePicker is refreshed. */ public final void setTransientEnabledOnDates(boolean enabled, Date date) { assert isDateVisible(date) : date + " must be visible"; getView().setEnabledOnDate(enabled, date); }
/** * Removes the styleName from the given dates (even if it is transient). */ public void removeStyleFromDates(String styleName, Date date) { styler.setStyleName(date, styleName, false); if (isDateVisible(date)) { getView().removeStyleFromDate(styleName, date); } }
/** * Is the visible date enabled? * * @param date the date, which must be visible * * @return is the date enabled? */ public boolean isDateEnabled(Date date) { assert isDateVisible(date) : date + " is not visible"; return getView().isDateEnabled(date); }
/** * Returns the last shown date. * * @return the last date. */ // Final because the view should always control the value of the last date. public final Date getLastDate() { return view.getLastDate(); }
/** * Returns the first shown date. * * @return the first date. */ // Final because the view should always control the value of the first date. public final Date getFirstDate() { return view.getFirstDate(); }
/** * Sets the {@link DatePicker}'s value. * * @param newValue the new value for this date picker * @param fireEvents should events be fired. */ public final void setValue(Date newValue, boolean fireEvents) { Date oldValue = value; if (oldValue != null) { removeStyleFromDates(css().dayIsValue(), oldValue); } value = CalendarUtil.copyDate(newValue); if (value != null) { addStyleToDates(css().dayIsValue(), value); } getView().setAriaSelectedCell(newValue); if (fireEvents) { DateChangeEvent.fireIfNotEqualDates(this, oldValue, newValue); } }
/** * Adds a show range handler and immediately activate the handler on the * current view. * * @param handler the handler * @return the handler registration */ public HandlerRegistration addShowRangeHandlerAndFire( ShowRangeHandler<Date> handler) { ShowRangeEvent<Date> event = new ShowRangeEvent<Date>( getView().getFirstDate(), getView().getLastDate()) { }; handler.onShowRange(event); return addShowRangeHandler(handler); }