You can also take a look to my blog for more details and full code

http://ctasada.blogspot.com/2010/08/gwt-extend-datepickercalendarview.html

On 5 ago, 15:43, ctasada <[email protected]> wrote:
> I did it in my code without too much problems, but I agree with you
> that's quite annoying.
>
> Steps:
> 1.- Create a new package in your code:
> com.google.gwt.user.datepicker.client
>
> Copy the DefaultCalendarView.java from the GWT repository (I'm not
> sure which version I used, but was the one from 2.0)
>
> In the DateCell subclass
>    in the update method
>       change setEnabled(true) ->
> setEnabled(getDatePicker().isDateEnabled(current));
>
> In the DefaultCalendarView
>
> Create 2 new variables:
>         private Date minDate = null;
>         private Date maxDate = null;
>
> Create a new constructor (that's the one you'll use)
>
>         // FIXME: Overload Constructor and whole class just to configure the
> first
>         // day of the week :(
>         /**
>          * Constructor.
>          *
>          * @param minDate Minimum allowed date.
>          * @param maxDate Maximum allowed date.
>          */
>         public DefaultCalendarView(Date minDate, Date maxDate) {
>                 this.minDate = minDate;
>                 this.maxDate = maxDate;
>         }
>
> Replace the method isDateEnabled by:
>
>         @Override
>         public boolean isDateEnabled(Date d) {
>                 if (minDate != null && maxDate != null) {
>                         if (d.after(minDate) && d.before(maxDate)) {
>                                 return true;
>                         } else {
>                                 return false;
>                         }
>                 }
>                 return getCell(d).isEnabled();
>         }
>
> That's it.
>
> Hope it helps.
>
> On Aug 4, 4:06 pm, "[email protected]" <[email protected]> wrote:
>
>
>
> > Folks, I'm trying to make a fairly basic improvement to the default
> > GWT DatePicker. However, due to its design, I end up having to extend
> > (and largely reimplement) a few classes (incl CellGridImpl and
> > CalendarView).
>
> > Everything works fine with my implementation when compiling, and when
> > running as a webapp.
>
> > However, when I try to debug using DevMode, I get this error:
>
> > 01:27:53.944 [ERROR] [analysisgraph] Unable to load module entry point
> > class com.masergy.ina.analysis.client.AnalysisEntryPoint (see
> > associated exception for details)
> > java.lang.IllegalAccessError: tried to access class
> > com.google.gwt.user.datepicker.client.DatePickerComponent from class
> > com.masergy.ina.analysis.client.widget.BoundedCalendarView
> >     at
> > com.masergy.ina.analysis.client.widget.BoundedCalendarView.access
> > $1(BoundedCalendarView.java:1)
> >     at com.masergy.ina.analysis.client.widget.BoundedCalendarView
> > $CellGrid$DateCell.update(BoundedCalendarView.java:133)
> >     at
> > com.masergy.ina.analysis.client.widget.BoundedCalendarView.refresh(BoundedC 
> > alendarView.java:
> > 339)
> >     at
> > com.google.gwt.user.datepicker.client.DatePicker.refreshAll(DatePicker.java 
> > :
> > 622)
> >     at
> > com.google.gwt.user.datepicker.client.DatePicker.setCurrentMonth(DatePicker 
> > .java:
> > 513)
> >     at
> > com.google.gwt.user.datepicker.client.DatePicker.<init>(DatePicker.java:
> > 282)
> >     at
> > com.masergy.ina.analysis.client.widget.BoundedDatePicker.<init>(BoundedDate 
> > Picker.java:
> > 36)
> >     at
> > com.masergy.ina.analysis.client.widget.BoundedDateTimePicker.doLayout(Bound 
> > edDateTimePicker.java:
> > 103)
> >     at
> > com.masergy.ina.analysis.client.widget.BoundedDateTimePicker.<init>(Bounded 
> > DateTimePicker.java:
> > 89)
> > [...]
>
> > update() is from code I've had to reimplement from CalendarView:
> >       public void update(Date current) {
> >         setEnabled(true);
> >         getValue().setTime(current.getTime());
> >         String value = getModel().formatDayOfMonth(getValue());
> >         setText(value);
> >         dateStyle = cellStyle;
> >         if (isFiller()) {
> >           dateStyle += " " + css().dayIsFiller();
> >         } else {
> >           String extraStyle =
> > getDatePicker().getStyleOfDate(current); // <-- line 133
> >           if (extraStyle != null) {
> >             dateStyle += " " + extraStyle;
> >           }
> >         }
> >         // We want to certify that all date styles have " " before and
> > after
> >         // them for ease of adding to and replacing them.
> >         dateStyle += " ";
> >         updateStyle();
> >       }
>
> > getDatePicker() is an inherited method in the public class
> > CalendarView, but is from the package-protected DatePickerComponent
> > class.
>
> > Does this make any sense? Why is DatePicker so impossible to extend to
> > add any decent functionality? In my case, all I wanted was to override
> > the simple CalendarView.isDateEnabled() method to limit the range of
> > selectable days. But due to the overly paranoid method and field
> > access restrictions, I had to reimplement most of the entire package.
> > I'd like to avoid reimplementing the entire package, including CSS,
> > but I'm not sure that's even possible.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to