Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

GWT based year calendar showing a date range

By: a guest on May 22nd, 2012  |  syntax: Java  |  size: 1.51 KB  |  views: 192  |  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.     final DateTimeFormat format = DateTimeFormat.getFormat("yyyy-M-dd");
  2.     final DateTimeFormat monthFormat = DateTimeFormat.getFormat("MMMM");
  3.  
  4.     final FlexTable flexTable = new FlexTable();
  5.    
  6.     final DatePicker[] datePickers = new DatePicker[12];
  7.    
  8.     class MyDatePicker extends DatePicker {
  9.  
  10.       MyDatePicker() {
  11.         super(new DefaultMonthSelector(), new DefaultCalendarView(),
  12.             new CalendarModel() {
  13.               @Override
  14.               public String formatCurrentMonth() {
  15.                 return monthFormat.format(getCurrentMonth());
  16.               }
  17.             });
  18.       }
  19.     }
  20.    
  21.     for (int row = 0; row < 4; row ++) {
  22.       for (int col = 0; col < 3; col ++) {
  23.        
  24.         final DatePicker datePicker = new MyDatePicker();
  25.          
  26.         final int monthZeroBased = (row * 3) + col;
  27.         datePicker.setCurrentMonth(format.parse("2012-" + (monthZeroBased + 1) + "-01"));
  28.         datePicker.addStyleName("my-cal");
  29.        
  30.         flexTable.setWidget(row, col, datePicker);
  31.         datePickers[monthZeroBased] = datePicker;
  32.       }
  33.     }
  34.    
  35.    
  36.  
  37.     final Date start = format.parse("2012-01-17");
  38.     final Date end = format.parse("2012-03-28");
  39.  
  40.     for (final Date date = start; date.compareTo(end) <= 0; CalendarUtil
  41.         .addDaysToDate(date, 1)) {
  42.  
  43.      
  44.       @SuppressWarnings("deprecation") /* Yes, it's deprecated */
  45.       final int month = date.getMonth();
  46.      
  47.       datePickers[month].addStyleToDates("my-green", date);
  48.     }