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
Nested ClassesModifier and TypeClassDescription(package private) static classConvenience 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
ConstructorsModifierConstructorDescriptionCreate a new date picker.protectedDatePicker(MonthSelector monthAndYearSelector, CalendarView view, CalendarModel model) Creates a new date picker. -
Method Summary
Modifier and TypeMethodDescriptionaddHighlightHandler(HighlightHandler<Date> handler) Adds aHighlightEventhandler.addShowRangeHandler(ShowRangeHandler<Date> handler) Adds aShowRangeEventhandler.addShowRangeHandlerAndFire(ShowRangeHandler<Date> handler) Adds a show range handler and immediately activate the handler on the current view.voidaddStyleToDates(String styleName, Iterable<Date> dates) Add a style name to the given dates.voidaddStyleToDates(String styleName, Date date) Add a style name to the given dates.voidaddStyleToDates(String styleName, Date date, Date... moreDates) Add a style name to the given dates.final voidaddTransientStyleToDates(String styleName, Iterable<Date> dates) Adds the given style name to the specified dates, which must be visible.voidaddTransientStyleToDates(String styleName, Date date) Adds the given style name to the specified dates, which must be visible.final voidaddTransientStyleToDates(String styleName, Date date, Date... moreDates) Adds the given style name to the specified dates, which must be visible.addValueChangeHandler(ValueChangeHandler<Date> handler) Adds aValueChangeEventhandler.asEditor()Returns aTakesValueEditorbacked by the DatePicker.(package private) final DatePicker.StandardCsscss()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 DateReturns the first shown date.final DateGets the highlighted date (the one the mouse is hovering over), if any.final DateReturns the last shown date.protected final CalendarModelgetModel()Gets theCalendarModelassociated with this date picker.protected final MonthSelectorGets theMonthSelectorassociated 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 DategetValue()Returns the selected date, or null if none is selected.protected final CalendarViewgetView()Gets theCalendarViewassociated with this date picker.intReturns the number of year to display in the years selection dropdown.booleanisDateEnabled(Date date) Is the visible date enabled?booleanisDateVisible(Date date) Is the date currently shown in the date picker?booleanIs the year and month selectable via a dropdown?booleanCan the user navigate through the years?voidonLoad()This method is called immediately after a widget becomes attached to the browser's document.protected final voidRefreshes all components of this date picker.voidremoveStyleFromDates(String styleName, Iterable<Date> dates) Removes the styleName from the given dates (even if it is transient).voidremoveStyleFromDates(String styleName, Date date) Removes the styleName from the given dates (even if it is transient).voidremoveStyleFromDates(String styleName, Date date, Date... moreDates) Removes the styleName from the given dates (even if it is transient).voidsetCurrentMonth(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) voidsetHighlightedDate(Date highlighted) Sets the highlighted date.voidsetStyleName(String styleName) Sets the date picker style name.final voidsetTransientEnabledOnDates(boolean enabled, Iterable<Date> dates) Sets a group of visible dates to be enabled or disabled.final voidsetTransientEnabledOnDates(boolean enabled, Date date) Sets a visible date to be enabled or disabled.final voidsetTransientEnabledOnDates(boolean enabled, Date date, Date... moreDates) Sets a visible date to be enabled or disabled.protected voidsetup()Sets up the date picker.final voidSets theDatePicker's value.final voidSets theDatePicker's value.voidsetVisibleYearCount(int numberOfYears) Set the number of years to display in the years selection dropdown.voidsetYearAndMonthDropdownVisible(boolean dropdownVisible) If thedropdownVisibleis 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.voidsetYearArrowsVisible(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, setWidgetMethods 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, unsinkEventsMethods 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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 aTakesValueEditorbacked by the DatePicker.- Specified by:
asEditorin interfaceIsEditor<LeafValueEditor<Date>>- Returns:
- an
Editorof 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:WidgetThis 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 thedropdownVisibleis 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:
setStyleNamein 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 theCalendarModelassociated with this date picker.- Returns:
- the model
-
getMonthSelector
Gets theMonthSelectorassociated with this date picker.- Returns:
- the month selector
-
getView
Gets theCalendarViewassociated 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