public class SearchAvailMultipleResults extends ListGrid {

  public SearchAvailMultipleResults() {

    List<String> month1 = new ArrayList<String>();
    List<String> month2 = new ArrayList<String>();
    List<ListGridField> columns = new ArrayList<ListGridField>();
    String month1Name = "";
    int month1Code = -1;
    String month2Name = "";
    int month2Code = -1;

    setWidth(750);
    setHeight(224);
    setHeaderHeight(40);

    Calendar tempCal = Calendar.getInstance();
    Calendar cal = Calendar.getInstance();

    Date now = tempCal.getTime();
    tempCal.add(Calendar.MONTH, 1);
    Date end = tempCal.getTime();

    Date currD = cal.getTime();
    String columnId;
    int i = 1;
    month1Code = cal.get(Calendar.MONTH);
    month1Name = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());

    while (!currD.equals(end)) {
      System.out.println("Date: " + currD.toString());
      if (cal.get(Calendar.DAY_OF_WEEK) == 7)
        System.out.println("Weekend : Saturday");
      if (cal.get(Calendar.DAY_OF_WEEK) == 1)
        System.out.println("Weekend : Sunday");

      columnId = "day" + i;
      columns.add(new ListGridField(columnId, cal.get(Calendar.DAY_OF_MONTH)));

      month2Code = cal.get(Calendar.MONTH);
      if (month1Code != month2Code) {
        month2Name = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());
        month2.add(columnId);
      } else {
        month1.add(columnId);
      }

      cal.add(Calendar.DAY_OF_MONTH, 1);
      currD = cal.getTime();
      i++;
    }

    ListGridField nameField = new ListGridField("companyName", "Company Name");
    if (columns.size() == 31)
      setFields(nameField, columns.get(0), columns.get(1), columns.get(2), columns.get(3), columns.get(4), columns.get(5), columns.get(6),
          columns.get(7), columns.get(8), columns.get(9), columns.get(10), columns.get(11), columns.get(12), columns.get(13),
          columns.get(14), columns.get(15), columns.get(16), columns.get(17), columns.get(18), columns.get(19), columns.get(20),
          columns.get(21), columns.get(22), columns.get(23), columns.get(24), columns.get(25), columns.get(26), columns.get(27),
          columns.get(28),columns.get(29),columns.get(30),columns.get(31));
    if (columns.size() == 30)
      setFields(nameField, columns.get(0), columns.get(1), columns.get(2), columns.get(3), columns.get(4), columns.get(5), columns.get(6),
          columns.get(7), columns.get(8), columns.get(9), columns.get(10), columns.get(11), columns.get(12), columns.get(13),
          columns.get(14), columns.get(15), columns.get(16), columns.get(17), columns.get(18), columns.get(19), columns.get(20),
          columns.get(21), columns.get(22), columns.get(23), columns.get(24), columns.get(25), columns.get(26), columns.get(27),
          columns.get(28),columns.get(29),columns.get(30));
    if (columns.size() == 29)
      setFields(nameField, columns.get(0), columns.get(1), columns.get(2), columns.get(3), columns.get(4), columns.get(5), columns.get(6),
          columns.get(7), columns.get(8), columns.get(9), columns.get(10), columns.get(11), columns.get(12), columns.get(13),
          columns.get(14), columns.get(15), columns.get(16), columns.get(17), columns.get(18), columns.get(19), columns.get(20),
          columns.get(21), columns.get(22), columns.get(23), columns.get(24), columns.get(25), columns.get(26), columns.get(27),
          columns.get(28),columns.get(29));
    if (columns.size() == 28)
      setFields(nameField, columns.get(0), columns.get(1), columns.get(2), columns.get(3), columns.get(4), columns.get(5), columns.get(6),
          columns.get(7), columns.get(8), columns.get(9), columns.get(10), columns.get(11), columns.get(12), columns.get(13),
          columns.get(14), columns.get(15), columns.get(16), columns.get(17), columns.get(18), columns.get(19), columns.get(20),
          columns.get(21), columns.get(22), columns.get(23), columns.get(24), columns.get(25), columns.get(26), columns.get(27),
          columns.get(28));

    String[] month1HSpan = new String[month1.size()];
    String[] month2HSpan = new String[month2.size()];
    for (int j = 0; j < month1.size(); j++)
      month1HSpan[j] = month1.get(j);
    
    for (int j = 0; j < month2.size(); j++)
      month2HSpan[j] = month2.get(j);
    
    setHeaderSpans(new HeaderSpan("2011", new String[] { "companyName" }), 
                   new HeaderSpan(month1Name, month1HSpan), 
                   new HeaderSpan(month2Name, month2HSpan));

  }
}
   
