Take a look at this patch. I added setEnabledOnDate(boolean, Date) and getEnabledOnDate(boolean). I wasn't sure if changing isDateEnabled(Date) was a good idea, so I left it alone. Can you create an isse for the enabled capability so I can link to it when I submit the patch?
On Thursday, May 10, 2012 11:45:46 AM UTC-4, Brandon Donnelson wrote: > The reason I want access to that method is for. > 1. I want a person to select only future dates > 2. I want a person to select with in a date range > 3. I want a person to select before a date > 4. I want a person to select between a choice of dates. > > > On Thursday, May 10, 2012 8:34:47 AM UTC-7, Patrick Tucker wrote: >> >> setTransientEnabledOnDates (boolean enabled, Date date) won't get you >> what you need or do the dates need to be disabled upon reload? >> >> Just thinking a setEnabledOnDates (boolean enabled, Date date) should be >> added if a more permanent disable is what you are looking for. >> >> On Thursday, May 10, 2012 11:24:44 AM UTC-4, Brandon Donnelson wrote: >> >>> Yes, I know, but it's protected. I figured you'd see that :) >>> >>> I have to override datepicker to get at its view to disable dates I >>> don't want selected in the calendar. Maybe ideally it would be better to >>> open up extending the view and model to the datepicker which are both >>> protected too. I'd love to extend either the DefaultView and add some logic >>> to it for our app. I think the original intention for the view was for >>> its extension from the comments I've read but it's been some time it would >>> seem its more mature. >>> >>> CalendarView.class - comments at the top: >>> /** >>> * Simple calendar view. Not extensible as we wish to evolve it freely >>> over >>> * time. >>> */ >>> >>> Basically everything is protected for overriding functions. I can see >>> why it's protected to improve the the methods before allowing for it to be >>> extended and for use. >>> >>> Also do you see any harm in making the 'CalendarView getView()' a public >>> method? because I don't :) >>> >>> Thanks for taking a look at this Patrick. >>> >>> Brandon >>> http://c.gwt-examples.com >>> >>> >>> On Thursday, May 10, 2012 8:09:02 AM UTC-7, Patrick Tucker wrote: >>>> >>>> DatePicker already has getView(). >>>> >>>> Do you mean in DateBox? Currently from DateBox you have to access the >>>> CalendarView though getDatePicker(). I can add it, no guarantee it >>>> will get approved though. >>>> >>>> On Thursday, May 10, 2012 11:01:08 AM UTC-4, Brandon Donnelson wrote: >>>> >>>>> I like it. :) >>>>> >>>>> While your in there could you add a method for getting the view? This >>>>> way we could get access to disabling dates when the month is selected. >>>>> >>>>> public CalendarView getCalendarView() { >>>>> return getView(); >>>>> } >>>>> >>>>> http://c.gwt-examples.com/home/ui/datepicker >>>>> >>>>> Brandon Donnelson >>>>> http://c.gwt-examples.com >>>>> >>>> -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/eg4Tzw-u0igJ. To post to this group, send email to google-web-toolkit@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Index: user/src/com/google/gwt/user/datepicker/client/CalendarView.java =================================================================== --- user/src/com/google/gwt/user/datepicker/client/CalendarView.java (revision 10969) +++ user/src/com/google/gwt/user/datepicker/client/CalendarView.java (working copy) @@ -33,7 +33,7 @@ } /** - * Adds a style name to the cell of the supplied date. This style is only set + * Adds a style name to the cell of the supplied date. This style is not set * until the next time the {@link CalendarView} is refreshed. * * @param styleName style name to add @@ -67,7 +67,7 @@ * Removes a visible style name from the cell of the supplied date. * * @param styleName style name to remove - * @param date date that will have the supplied style added + * @param date date that will have the supplied style removed */ public abstract void removeStyleFromDate(String styleName, Date date); @@ -79,6 +79,15 @@ * @param date date to enable or disable */ public abstract void setEnabledOnDate(boolean enabled, Date date); + + /** + * Sets the title on the cell of the supplied date. This title is not set + * until the next time the {@link CalendarView} is refreshed. + * + * @param title title to add + * @param date date that will have the supplied title added + */ + public abstract void setTitleOnDate(String title, Date date); /** * Allows the calendar view to update the date picker's highlighted date. Index: user/src/com/google/gwt/user/datepicker/client/DatePicker.java =================================================================== --- user/src/com/google/gwt/user/datepicker/client/DatePicker.java (revision 10969) +++ user/src/com/google/gwt/user/datepicker/client/DatePicker.java (working copy) @@ -34,7 +34,7 @@ import java.util.Date; import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; /** * Standard GWT date picker. @@ -207,11 +207,34 @@ } } - private static class DateStyler { - private Map<String, String> info = new HashMap<String, String>(); + private static class Styler { + @SuppressWarnings("deprecation") + protected static String genKey(Date d) { + return d.getYear() + "/" + d.getMonth() + "/" + d.getDate(); + } + } + + private static class DateEnabler extends Styler { + protected HashSet<String> keys = new HashSet<String>(); + + public boolean getEnabled(Date d) { + return !keys.contains(genKey(d)); + } + public void setEnabled(Date d, boolean enabled) { + if (!enabled) { + keys.add(genKey(d)); + } else { + keys.remove(genKey(d)); + } + } + } + + private static class DateStyler extends Styler { + protected HashMap<String, String> styles = new HashMap<String, String>(); + public String getStyleName(Date d) { - return info.get(genKey(d)); + return styles.get(genKey(d)); } public void setStyleName(Date d, String styleName, boolean add) { @@ -219,33 +242,42 @@ // this is a no-op. styleName = " " + styleName + " "; String key = genKey(d); - String current = info.get(key); + String current = styles.get(key); if (add) { if (current == null) { - info.put(key, styleName); + styles.put(key, styleName); } else if (current.indexOf(styleName) == -1) { - info.put(key, current + styleName); + styles.put(key, current + styleName); } } else { if (current != null) { String newValue = current.replaceAll(styleName, ""); if (newValue.trim().length() == 0) { - info.remove(key); + styles.remove(key); } else { - info.put(key, newValue); + styles.put(key, newValue); } } } } + } - @SuppressWarnings("deprecation") - private String genKey(Date d) { - return d.getYear() + "/" + d.getMonth() + "/" + d.getDate(); + private static class DateTitler extends Styler { + protected HashMap<String, String> titles = new HashMap<String, String>(); + + public String getTitle(Date d) { + return titles.get(genKey(d)); } + + public void setTitle(Date d, String title) { + titles.put(genKey(d), title); + } } + private final DateEnabler enabler = new DateEnabler(); private final DateStyler styler = new DateStyler(); + private final DateTitler titler = new DateTitler(); private final MonthSelector monthSelector; private final CalendarView view; @@ -404,6 +436,17 @@ } /** + * Get the enablement associated with a date (does not include titles set via + * {@link #setTransientEnabledOnDates(boolean, Date)} + * + * @param date the date + * @return the enablement of the date + */ + public boolean getEnabledOnDate(Date date) { + return enabler.getEnabled(date); + } + + /** * Returns the first shown date. * * @return the first date. @@ -444,6 +487,17 @@ } /** + * Gets the title associated with a date (does not include titles set via + * {@link #setTransientDateTitle}). + * + * @param date the date + * @return the title associated with this date + */ + public String getTitleOfDate(Date date) { + return titler.getTitle(date); + } + + /** * Returns the selected date, or null if none is selected. * * @return the selected date, or null @@ -529,6 +583,16 @@ } /** + * Set a date to be enabled or disabled. + */ + public void setEnabledOnDate(boolean enabled, Date date) { + enabler.setEnabled(date, enabled); + if (isDateVisible(date)) { + getView().setEnabledOnDate(enabled, date); + } + } + + /** * Sets the date picker style name. */ @Override @@ -538,6 +602,16 @@ } /** + * Set the title on the cell of the specified date. + */ + public void setTitleOnDate(String title, Date date) { + titler.setTitle(date, title); + if (isDateVisible(date)) { + getView().setTitleOnDate(title, date); + } + } + + /** * Sets a visible date to be enabled or disabled. This is only set until the * next time the DatePicker is refreshed. */ @@ -570,6 +644,15 @@ } /** + * Sets the title on the cell of the specified date, which must be visible. + * This is only set until the next time the DatePicker is refreshed. + */ + public void setTransientTitleOnDate(String title, Date date) { + assert isDateVisible(date) : date + " must be visible"; + getView().setTitleOnDate(title, date); + } + + /** * Sets the {@link DatePicker}'s value. * * @param newValue the new value Index: user/src/com/google/gwt/user/datepicker/client/DefaultCalendarView.java =================================================================== --- user/src/com/google/gwt/user/datepicker/client/DefaultCalendarView.java (revision 10969) +++ user/src/com/google/gwt/user/datepicker/client/DefaultCalendarView.java (working copy) @@ -86,10 +86,11 @@ } public void update(Date current) { - setEnabled(true); + setEnabled(getDatePicker().getEnabledOnDate(current)); getValue().setTime(current.getTime()); String value = getModel().formatDayOfMonth(getValue()); setText(value); + setTitle(getDatePicker().getTitleOfDate(current)); dateStyle = cellStyle; if (isFiller()) { dateStyle += " " + css().dayIsFiller(); @@ -202,6 +203,14 @@ } @Override + public void setTitleOnDate(String title, Date date) { + assert getDatePicker().isDateVisible(date) : "You tried to set the title " + title + " to " + + date + ". The calendar is currently showing " + getFirstDate() + + " to " + getLastDate(); + getCell(date).setTitle(title); + } + + @Override public void setup() { // Preparation CellFormatter formatter = grid.getCellFormatter();
<<attachment: DatePicker_ScreenShot.png>>