Hi,

I have extended DatePicker so that a date range can be selected on one
widget.  The current range is between the last two date selections and
when a date is highlighted all dates between the last selection and
the current highlighted date are emphasized.

It almost works.  The problem I am having is that HighligtEvents are
sent twice for every date, mouse-over and mouse-out, EXCEPT when a
date from another month is chosen (i.e. a date in November when the
current month is October).  In this case the HighlightEvent for the
mouse-out are missed and the also the event for the highlight of the
current date in the new month is missed.

What would help me is:

1 - if there were a way to know if the HighlightEvent was caused by
mouseover or mouseout (or separate events)
2 - when the month is changed (by clicking on a "filler" date) the
HighlightEvent should be fired for the new date that the mouse happens
to hover above.

For reference here is my code:

public class RangeDatePicker extends Composite
{
        private static final String RANGE_STYLE = "range";
        private static final String POTENTIAL_STYLE = "potential";
        private static final long DAY = 1000 * 60 * 60 * 24;
        private Date first;
        private Date second;

        public RangeDatePicker()
        {
                final DatePicker picker = new DatePicker();
                picker.addHighlightHandler(new HighlightHandler<Date>()
                {
                        private Date last;

                        public void onHighlight(HighlightEvent<Date> event)
                        {
                                GWT.log("Highlight " + event.getHighlighted() + 
" " +
picker.getHighlightedDate(), null);
                                if (second != null)
                                {
                                        // normally the same date is fires 
twice - for mouse-over and
mouse-out
                                        Range<Date> range = new 
Range<Date>(second, event.getHighlighted
());
                                        if (last != null && 
last.equals(event.getHighlighted()))
                                        {
                                                // this is a mouse-out so 
remove highlights
                                                
picker.removeStyleFromDates(POTENTIAL_STYLE, newDateRangeIterable
(range));
                                        }
                                        else
                                        {
                                                // this is a mouse-over so add 
the highlights
                                                
picker.addStyleToDates(POTENTIAL_STYLE, newDateRangeIterable
(range));
                                        }

                                        last = event.getHighlighted();
                                }
                        }
                });

                picker.addValueChangeHandler(new ValueChangeHandler<Date>()
                {
                        public void onValueChange(ValueChangeEvent<Date> event)
                        {
                                Range<Date> range = getDateRange();
                                if (range != null)
                                {
                                        
picker.removeStyleFromDates(RANGE_STYLE, newDateRangeIterable
(range));
                                }

                                // this will change the date range
                                addSelectedDate(event.getValue());

                                range = getDateRange();
                                if (range != null)
                                {
                                        
picker.removeStyleFromDates(POTENTIAL_STYLE, newDateRangeIterable
(range));
                                        picker.addStyleToDates(RANGE_STYLE, 
newDateRangeIterable(range));
                                }
                        }
                });

                initWidget(picker);
        }


        protected Iterable<Date> newDateRangeIterable(Range<Date> range)
        {
                ArrayList<Date> iterable = new ArrayList<Date>();
                for (Date d = range.getFrom(); !d.after(range.getTo()); d = new 
Date
(d.getTime() + DAY))
                {
                        iterable.add(d);
                }
                return iterable;
        }

        protected void addSelectedDate(Date value)
        {
                first = second;
                second = value;
        }

        public Range<Date> getDateRange()
        {
                if (first != null)
                {
                        return new Range<Date>(first, second);
                }
                else
                {
                        return null;
                }
        }
}

Thanks,

John

--~--~---------~--~----~------------~-------~--~----~
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