Class DatePicker

  • All Implemented Interfaces:
    IsEditor<LeafValueEditor<java.util.Date>>, HasAttachHandlers, HasHighlightHandlers<java.util.Date>, HasShowRangeHandlers<java.util.Date>, HasValueChangeHandlers<java.util.Date>, HasHandlers, EventListener, TakesValue<java.util.Date>, HasValue<java.util.Date>, HasVisibility, IsRenderable, IsWidget

    public class DatePicker
    extends Composite
    implements HasHighlightHandlers<java.util.Date>, HasShowRangeHandlers<java.util.Date>, HasValue<java.util.Date>, IsEditor<LeafValueEditor<java.util.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);
      }
    }
    

    • Constructor Detail

      • DatePicker

        public DatePicker()
        Create a new date picker.
      • DatePicker

        protected DatePicker​(MonthSelector monthAndYearSelector,
                             CalendarView view,
                             CalendarModel model)
        Creates a new date picker.
        Parameters:
        monthAndYearSelector - the month selector
        view - the view
        model - the model
    • Method Detail

      • addShowRangeHandlerAndFire

        public HandlerRegistration addShowRangeHandlerAndFire​(ShowRangeHandler<java.util.Date> handler)
        Adds a show range handler and immediately activate the handler on the current view.
        Parameters:
        handler - the handler
        Returns:
        the handler registration
      • addStyleToDates

        public void addStyleToDates​(java.lang.String styleName,
                                    java.util.Date date)
        Add a style name to the given dates.
      • addStyleToDates

        public void addStyleToDates​(java.lang.String styleName,
                                    java.util.Date date,
                                    java.util.Date... moreDates)
        Add a style name to the given dates.
      • addStyleToDates

        public void addStyleToDates​(java.lang.String styleName,
                                    java.lang.Iterable<java.util.Date> dates)
        Add a style name to the given dates.
      • addTransientStyleToDates

        public void addTransientStyleToDates​(java.lang.String styleName,
                                             java.util.Date date)
        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

        public final void addTransientStyleToDates​(java.lang.String styleName,
                                                   java.util.Date date,
                                                   java.util.Date... moreDates)
        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

        public final void addTransientStyleToDates​(java.lang.String styleName,
                                                   java.lang.Iterable<java.util.Date> dates)
        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.
      • getCurrentMonth

        public java.util.Date 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

        public final java.util.Date getFirstDate()
        Returns the first shown date.
        Returns:
        the first date.
      • getHighlightedDate

        public final java.util.Date getHighlightedDate()
        Gets the highlighted date (the one the mouse is hovering over), if any.
        Returns:
        the highlighted date
      • getLastDate

        public final java.util.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.
      • getValue

        public final java.util.Date getValue()
        Returns the selected date, or null if none is selected.
        Specified by:
        getValue in interface HasValue<java.util.Date>
        Specified by:
        getValue in interface TakesValue<java.util.Date>
        Returns:
        the selected date, or null
        See Also:
        TakesValue.setValue(V)
      • isDateEnabled

        public boolean isDateEnabled​(java.util.Date date)
        Is the visible date enabled?
        Parameters:
        date - the date, which must be visible
        Returns:
        is the date enabled?
      • isDateVisible

        public boolean isDateVisible​(java.util.Date date)
        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.
        Overrides:
        onLoad in class Widget
      • removeStyleFromDates

        public void removeStyleFromDates​(java.lang.String styleName,
                                         java.util.Date date)
        Removes the styleName from the given dates (even if it is transient).
      • removeStyleFromDates

        public void removeStyleFromDates​(java.lang.String styleName,
                                         java.util.Date date,
                                         java.util.Date... moreDates)
        Removes the styleName from the given dates (even if it is transient).
      • removeStyleFromDates

        public void removeStyleFromDates​(java.lang.String styleName,
                                         java.lang.Iterable<java.util.Date> dates)
        Removes the styleName from the given dates (even if it is transient).
      • setCurrentMonth

        public void setCurrentMonth​(java.util.Date month)
        Sets the date picker to show the given month, use getFirstDate() and getLastDate() 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 the dropdownVisible 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.
      • setTransientEnabledOnDates

        public final void setTransientEnabledOnDates​(boolean enabled,
                                                     java.util.Date date)
        Sets a visible date to be enabled or disabled. This is only set until the next time the DatePicker is refreshed.
      • setTransientEnabledOnDates

        public final void setTransientEnabledOnDates​(boolean enabled,
                                                     java.util.Date date,
                                                     java.util.Date... moreDates)
        Sets a visible date to be enabled or disabled. This is only set until the next time the DatePicker is refreshed.
      • setTransientEnabledOnDates

        public final void setTransientEnabledOnDates​(boolean enabled,
                                                     java.lang.Iterable<java.util.Date> dates)
        Sets a group of visible dates to be enabled or disabled. This is only set until the next time the DatePicker is refreshed.
      • setValue

        public final void setValue​(java.util.Date newValue,
                                   boolean fireEvents)
        Sets the DatePicker's value.
        Specified by:
        setValue in interface HasValue<java.util.Date>
        Parameters:
        newValue - the new value for this date picker
        fireEvents - should events be fired.
      • getMonthSelector

        protected final MonthSelector getMonthSelector()
        Gets the MonthSelector associated with this date picker.
        Returns:
        the month selector
      • getView

        protected final CalendarView getView()
        Gets the CalendarView 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

        final DatePicker.StandardCss css()
        Gets the css associated with this date picker for use by extended month and cell grids.
        Returns:
        the css.
      • setHighlightedDate

        void setHighlightedDate​(java.util.Date highlighted)
        Sets the highlighted date.
        Parameters:
        highlighted - highlighted date