Class DatePicker
java.lang.Object
com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Composite
com.google.gwt.user.datepicker.client.DatePicker
- All Implemented Interfaces:
IsEditor<LeafValueEditor<Date>>
,HasAttachHandlers
,HasHighlightHandlers<Date>
,HasShowRangeHandlers<Date>
,HasValueChangeHandlers<Date>
,HasHandlers
,EventListener
,TakesValue<Date>
,HasValue<Date>
,HasVisibility
,IsRenderable
,IsWidget
public class DatePicker
extends Composite
implements HasHighlightHandlers<Date>, HasShowRangeHandlers<Date>, HasValue<Date>, IsEditor<LeafValueEditor<Date>>
Standard GWT date picker.
CSS Style Rules
- .gwt-DatePicker { }
- .datePickerMonthSelector { the month selector widget }
- .datePickerMonth { the month in the month selector widget }
- .datePickerYear { the year in the month selector widget }
- .datePickerPreviousButton { the previous month button }
- .datePickerNextButton { the next month button }
- .datePickerPreviousYearButton { the previous year button }
- .datePickerNextYearButton { the next year button }
- .datePickerDays { the portion of the picker that shows the days }
- .datePickerWeekdayLabel { the label over weekdays }
- .datePickerWeekendLabel { the label over weekends }
- .datePickerDay { a single day }
- .datePickerDayIsToday { today's date }
- .datePickerDayIsWeekend { a weekend day }
- .datePickerDayIsFiller { a day in another month }
- .datePickerDayIsValue { the selected day }
- .datePickerDayIsDisabled { a disabled day }
- .datePickerDayIsHighlighted { the currently highlighted day }
- .datePickerDayIsValueAndHighlighted { the highlighted day if it is also selected }
Example
public class DatePickerExample implements EntryPoint { public void onModuleLoad() { // Create a date picker DatePicker datePicker = new DatePicker(); final Label text = new Label(); // Set the value in the text box when the user selects a date datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() { public void onValueChange(ValueChangeEvent<Date> event) { Date date = event.getValue(); String dateString = DateTimeFormat.getMediumDateFormat().format(date); text.setText(dateString); } }); // Set the default value datePicker.setValue(new Date(), true); // Add the widgets to the page RootPanel.get().add(text); RootPanel.get().add(datePicker); } }
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
Convenience class to group css style names.Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
-
Field Summary
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
-
Constructor Summary
ModifierConstructorDescriptionCreate a new date picker.protected
DatePicker
(MonthSelector monthAndYearSelector, CalendarView view, CalendarModel model) Creates a new date picker. -
Method Summary
Modifier and TypeMethodDescriptionaddHighlightHandler
(HighlightHandler<Date> handler) Adds aHighlightEvent
handler.addShowRangeHandler
(ShowRangeHandler<Date> handler) Adds aShowRangeEvent
handler.addShowRangeHandlerAndFire
(ShowRangeHandler<Date> handler) Adds a show range handler and immediately activate the handler on the current view.void
addStyleToDates
(String styleName, Iterable<Date> dates) Add a style name to the given dates.void
addStyleToDates
(String styleName, Date date) Add a style name to the given dates.void
addStyleToDates
(String styleName, Date date, Date... moreDates) Add a style name to the given dates.final void
addTransientStyleToDates
(String styleName, Iterable<Date> dates) Adds the given style name to the specified dates, which must be visible.void
addTransientStyleToDates
(String styleName, Date date) Adds the given style name to the specified dates, which must be visible.final void
addTransientStyleToDates
(String styleName, Date date, Date... moreDates) Adds the given style name to the specified dates, which must be visible.addValueChangeHandler
(ValueChangeHandler<Date> handler) Adds aValueChangeEvent
handler.asEditor()
Returns aTakesValueEditor
backed by the DatePicker.(package private) final DatePicker.StandardCss
css()
Gets the css associated with this date picker for use by extended month and cell grids.Gets the current month the date picker is showing.final Date
Returns the first shown date.final Date
Gets the highlighted date (the one the mouse is hovering over), if any.final Date
Returns the last shown date.protected final CalendarModel
getModel()
Gets theCalendarModel
associated with this date picker.protected final MonthSelector
Gets theMonthSelector
associated with this date picker.getStyleOfDate
(Date date) Gets the style associated with a date (does not include styles set viaaddTransientStyleToDates(java.lang.String, java.util.Date)
).final Date
getValue()
Returns the selected date, or null if none is selected.protected final CalendarView
getView()
Gets theCalendarView
associated with this date picker.int
Returns the number of year to display in the years selection dropdown.boolean
isDateEnabled
(Date date) Is the visible date enabled?boolean
isDateVisible
(Date date) Is the date currently shown in the date picker?boolean
Is the year and month selectable via a dropdown?boolean
Can the user navigate through the years?void
onLoad()
This method is called immediately after a widget becomes attached to the browser's document.protected final void
Refreshes all components of this date picker.void
removeStyleFromDates
(String styleName, Iterable<Date> dates) Removes the styleName from the given dates (even if it is transient).void
removeStyleFromDates
(String styleName, Date date) Removes the styleName from the given dates (even if it is transient).void
removeStyleFromDates
(String styleName, Date date, Date... moreDates) Removes the styleName from the given dates (even if it is transient).void
setCurrentMonth
(Date month) Sets the date picker to show the given month, usegetFirstDate()
andgetLastDate()
to access the exact date range the date picker chose to display.(package private) void
setHighlightedDate
(Date highlighted) Sets the highlighted date.void
setStyleName
(String styleName) Sets the date picker style name.final void
setTransientEnabledOnDates
(boolean enabled, Iterable<Date> dates) Sets a group of visible dates to be enabled or disabled.final void
setTransientEnabledOnDates
(boolean enabled, Date date) Sets a visible date to be enabled or disabled.final void
setTransientEnabledOnDates
(boolean enabled, Date date, Date... moreDates) Sets a visible date to be enabled or disabled.protected void
setup()
Sets up the date picker.final void
Sets theDatePicker
's value.final void
Sets theDatePicker
's value.void
setVisibleYearCount
(int numberOfYears) Set the number of years to display in the years selection dropdown.void
setYearAndMonthDropdownVisible
(boolean dropdownVisible) If thedropdownVisible
is equal to true, the user will be able to change the current month and the current year of the date picker via two dropdown lists.void
setYearArrowsVisible
(boolean yearArrowsVisible) Set if the user can navigate through the years via a set of backward and forward buttons.Methods inherited from class com.google.gwt.user.client.ui.Composite
claimElement, getWidget, initializeClaimedElement, initWidget, isAttached, onAttach, onBrowserEvent, onDetach, render, render, resolvePotentialElement, setWidget
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isOrWasAttached, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
-
Constructor Details
-
DatePicker
public DatePicker()Create a new date picker. -
DatePicker
Creates a new date picker.- Parameters:
monthAndYearSelector
- the month selectorview
- the viewmodel
- the model
-
-
Method Details
-
addStyleToDates
Add a style name to the given dates. -
addStyleToDates
Add a style name to the given dates. -
addStyleToDates
Add a style name to the given dates. -
addTransientStyleToDates
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. -
addTransientStyleToDates
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. -
addTransientStyleToDates
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. -
asEditor
Returns aTakesValueEditor
backed by the DatePicker.- Specified by:
asEditor
in interfaceIsEditor<LeafValueEditor<Date>>
- Returns:
- an
Editor
of type E
-
getCurrentMonth
Gets the current month the date picker is showing.A datepicker may show days not in the current month. It must show all days in the current month.
- Returns:
- the current month
-
getFirstDate
Returns the first shown date.- Returns:
- the first date.
-
getHighlightedDate
Gets the highlighted date (the one the mouse is hovering over), if any.- Returns:
- the highlighted date
-
getLastDate
Returns the last shown date.- Returns:
- the last date.
-
getVisibleYearCount
public int getVisibleYearCount()Returns the number of year to display in the years selection dropdown. -
getStyleOfDate
Gets the style associated with a date (does not include styles set viaaddTransientStyleToDates(java.lang.String, java.util.Date)
).- Parameters:
date
- the date- Returns:
- the styles associated with this date
-
getValue
Returns the selected date, or null if none is selected. -
isDateEnabled
Is the visible date enabled?- Parameters:
date
- the date, which must be visible- Returns:
- is the date enabled?
-
isDateVisible
Is the date currently shown in the date picker?- Parameters:
date
-- Returns:
- is the date currently shown
-
isYearArrowsVisible
public boolean isYearArrowsVisible()Can the user navigate through the years?- Returns:
- is the year navigation is enabled
-
isYearAndMonthDropdownVisible
public boolean isYearAndMonthDropdownVisible()Is the year and month selectable via a dropdown? -
onLoad
public void onLoad()Description copied from class:Widget
This method is called immediately after a widget becomes attached to the browser's document. -
removeStyleFromDates
Removes the styleName from the given dates (even if it is transient). -
removeStyleFromDates
Removes the styleName from the given dates (even if it is transient). -
removeStyleFromDates
Removes the styleName from the given dates (even if it is transient). -
setCurrentMonth
Sets the date picker to show the given month, usegetFirstDate()
andgetLastDate()
to access the exact date range the date picker chose to display.A datepicker may show days not in the current month. It must show all days in the current month.
- Parameters:
month
- the month to show
-
setVisibleYearCount
public void setVisibleYearCount(int numberOfYears) Set the number of years to display in the years selection dropdown. The range of years will be centered on the selected date. -
setYearArrowsVisible
public void setYearArrowsVisible(boolean yearArrowsVisible) Set if the user can navigate through the years via a set of backward and forward buttons. -
setYearAndMonthDropdownVisible
public void setYearAndMonthDropdownVisible(boolean dropdownVisible) If thedropdownVisible
is equal to true, the user will be able to change the current month and the current year of the date picker via two dropdown lists. -
setStyleName
Sets the date picker style name.- Overrides:
setStyleName
in classUIObject
- Parameters:
styleName
- the new style name- See Also:
-
setTransientEnabledOnDates
Sets a visible date to be enabled or disabled. This is only set until the next time the DatePicker is refreshed. -
setTransientEnabledOnDates
Sets a visible date to be enabled or disabled. This is only set until the next time the DatePicker is refreshed. -
setTransientEnabledOnDates
Sets a group of visible dates to be enabled or disabled. This is only set until the next time the DatePicker is refreshed. -
setValue
Sets theDatePicker
's value. -
setValue
Sets theDatePicker
's value. -
getModel
Gets theCalendarModel
associated with this date picker.- Returns:
- the model
-
getMonthSelector
Gets theMonthSelector
associated with this date picker.- Returns:
- the month selector
-
getView
Gets theCalendarView
associated with this date picker.- Returns:
- the view
-
refreshAll
protected final void refreshAll()Refreshes all components of this date picker. -
setup
protected void setup()Sets up the date picker. -
css
Gets the css associated with this date picker for use by extended month and cell grids.- Returns:
- the css.
-
setHighlightedDate
Sets the highlighted date.- Parameters:
highlighted
- highlighted date