This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

GWT datepicker group for seasons calendar

By: a guest on May 23rd, 2012  |  syntax: Java  |  size: 2.34 KB  |  views: 108  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Date picker overriden
  2. public class RangoDatePicker extends DatePicker {
  3.  
  4.     private final static DateTimeFormat monthFormat = DateTimeFormat.getFormat(PredefinedFormat.YEAR_MONTH);
  5.  
  6.     public RangoDatePicker(int month, int year, RangoDatePickerGroup rangoDatePickerGroup) {
  7.         super(new MonthSelector() {
  8.             private Grid grid;
  9.  
  10.             @Override
  11.             protected void refresh() {
  12.                 String formattedMonth = getModel().formatCurrentMonth();
  13.                 grid.setText(0, 0, formattedMonth);
  14.             }
  15.  
  16.             @Override
  17.             protected void setup() {
  18.                 // Set up grid.
  19.                 grid = new Grid(1, 1);
  20.  
  21.                 CellFormatter formatter = grid.getCellFormatter();
  22.                 formatter.setStyleName(0, 0, "datePickerMonth");
  23.                 formatter.setWidth(0, 0, "100%");
  24.                 grid.setStyleName("datePickerMonthSelector");
  25.                 initWidget(grid);
  26.             }
  27.         }, new DefaultCalendarView(), new CalendarModel() {
  28.             @Override
  29.             public String formatCurrentMonth() {
  30.                 return monthFormat.format(getCurrentMonth());
  31.             }
  32.         });
  33.  
  34.         // style
  35.         addStyleName("rango-cal");
  36.  
  37.         // group
  38.         rangoDatePickerGroup.addRangoCalendar(month, year, this);
  39.  
  40.         // set current month
  41.         Date currentMonth = new GregorianCalendar(year, month, 1).getTime();
  42.         this.setCurrentMonth(currentMonth);
  43.     }
  44.  
  45. }
  46.  
  47. //Date picker group
  48. public class RangoDatePickerGroup {
  49.     static HashMap<String, RangoDatePicker> datePickers = new HashMap<String, RangoDatePicker>();
  50.  
  51.     public void addRangoCalendar(int month, int year, RangoDatePicker rangoDatePicker) {
  52.         datePickers.put(key(year, month), rangoDatePicker);
  53.     }
  54.  
  55.     private String key(int year, int month) {
  56.         return year + "-" + month;
  57.     }
  58.  
  59.     public void selectDates(Date start, Date end, int colorCode) {
  60.         for (final Date date = start; date.compareTo(end) <= 0; CalendarUtil.addDaysToDate(date, 1)) {
  61.  
  62.             @SuppressWarnings("deprecation")
  63.             /* Yes, it's deprecated */
  64.             final int month = date.getMonth();
  65.             final int year = date.getYear();
  66.  
  67.             datePickers.get(key(year, month)).addStyleToDates("rango-colour"+colorCode, date);
  68.         }
  69.     }
  70.  
  71. }
  72.  
  73. //CSS
  74.  
  75. .rango-cal .datePickerDay.datePickerDayIsFiller{
  76.         visibility: hidden;
  77. }
  78. .rango-cal .datePickerDay.datePickerDayIsWeekend{
  79.         background: transparent;
  80. }
  81. .rango-cal .datePickerDay.datePickerDayIsValue{
  82.         background: transparent;
  83. }
  84. .rango-cal .datePickerDay.rango-colour-0 {
  85.         background-color: green;
  86. }
clone this paste RAW Paste Data