Fixes issue 3181 by firing the show range event at the correct time.
Review by:jlabanca

git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4345 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/event/logical/shared/ShowRangeEvent.java b/user/src/com/google/gwt/event/logical/shared/ShowRangeEvent.java
index b97fe93..34d3c88 100644
--- a/user/src/com/google/gwt/event/logical/shared/ShowRangeEvent.java
+++ b/user/src/com/google/gwt/event/logical/shared/ShowRangeEvent.java
@@ -20,7 +20,8 @@
 import com.google.gwt.event.shared.HasHandlers;

 

 /**

- * Represents a show range event.

+ * Represents a show range event. This logical event should be used when a

+ * widget displays a range of values to the user.  This event should not be fired until a widget is displaying t

  * 

  * @param <V> the type of range

  */

diff --git a/user/src/com/google/gwt/user/datepicker/client/DatePicker.java b/user/src/com/google/gwt/user/datepicker/client/DatePicker.java
index e6705a5..e5dacfb 100644
--- a/user/src/com/google/gwt/user/datepicker/client/DatePicker.java
+++ b/user/src/com/google/gwt/user/datepicker/client/DatePicker.java
@@ -240,13 +240,14 @@
       return d.getYear() + "/" + d.getMonth() + "/" + d.getDate();

     }

   }

+

   private final DateStyler styler = new DateStyler();

+

   private final MonthSelector monthSelector;

   private final CalendarView view;

   private final CalendarModel model;

   private Date value;

   private Date highlighted;

-

   private StandardCss css = StandardCss.DEFAULT;

 

   /**

@@ -281,11 +282,11 @@
     setCurrentMonth(new Date());

     addStyleToDates(css().dayIsToday(), new Date());

   }

-  

+

   public HandlerRegistration addHighlightHandler(HighlightHandler<Date> handler) {

     return addHandler(handler, HighlightEvent.getType());

   }

-  

+

   public HandlerRegistration addShowRangeHandler(ShowRangeHandler<Date> handler) {

     return addHandler(handler, ShowRangeEvent.getType());

   }

@@ -307,7 +308,7 @@
   }

 

   /**

-   * Add a style name to the given dates. 

+   * Add a style name to the given dates.

    */

   public void addStyleToDates(String styleName, Date date) {

     styler.setStyleName(date, styleName, true);

@@ -317,7 +318,7 @@
   }

 

   /**

-   * Add a style name to the given dates. 

+   * Add a style name to the given dates.

    */

   public void addStyleToDates(String styleName, Date date, Date... moreDates) {

     addStyleToDates(styleName, date);

@@ -336,7 +337,7 @@
   }

 

   /**

-   * Adds the given style name to the specified dates, which must be visible. 

+   * 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) {

@@ -345,7 +346,7 @@
   }

 

   /**

-   * Adds the given style name to the specified dates, which must be visible. 

+   * 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 final void addTransientStyleToDates(String styleName, Date date,

@@ -357,7 +358,7 @@
   }

 

   /**

-   * Adds the given style name to the specified dates, which must be visible. 

+   * 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 final void addTransientStyleToDates(String styleName,

@@ -379,6 +380,7 @@
    * A datepicker <b> may </b> show days not in the current month. It

    * <b>must</b> show all days in the current month.

    * </p>

+   * 

    * @return the current month

    * 

    */

@@ -416,8 +418,8 @@
   }

 

   /**

-   * Gets the style associated with a date (does not include styles

-   * set via {@link #addTransientStyleToDates}).

+   * Gets the style associated with a date (does not include styles set via

+   * {@link #addTransientStyleToDates}).

    * 

    * @param date the date

    * @return the styles associated with this date

@@ -459,6 +461,11 @@
     return (date != null && (first.equals(date) || last.equals(date) || (first.before(date) && last.after(date))));

   }

 

+  @Override

+  public void onLoad() {

+    ShowRangeEvent.fire(this, getFirstDate(), getLastDate());

+  }

+

   /**

    * Removes the styleName from the given dates (even if it is transient).

    */

@@ -472,7 +479,8 @@
   /**

    * Removes the styleName from the given dates (even if it is transient).

    */

-  public void removeStyleFromDates(String styleName, Date date, Date... moreDates) {

+  public void removeStyleFromDates(String styleName, Date date,

+      Date... moreDates) {

     removeStyleFromDates(styleName, date);

     for (Date d : moreDates) {

       removeStyleFromDates(styleName, d);

@@ -526,8 +534,8 @@
    * 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, Date... moreDates) {

+  public final void setTransientEnabledOnDates(boolean enabled, Date date,

+      Date... moreDates) {

     setTransientEnabledOnDates(enabled, date);

     for (Date d : moreDates) {

       setTransientEnabledOnDates(enabled, d);

@@ -609,9 +617,12 @@
   protected final void refreshAll() {

     highlighted = null;

     getModel().refresh();

+

     getView().refresh();

     getMonthSelector().refresh();

-    ShowRangeEvent.fire(this, getFirstDate(), getLastDate());

+    if (isAttached()) {

+      ShowRangeEvent.fire(this, getFirstDate(), getLastDate());

+    }

   }

 

   /**