/**
  * Called when a key is pressed down on an element
  *
  * @param row The row in the list that was selected at the time of the key press.
  * @param keycode The javascript keycode of which key was pressed.
  */
 public void keyDown(int row, int keycode) {
   if (keycode == KEYCODE_DELETE) {
     mScheduleController.removeItem(mScheduleItems.get(row));
     mScheduleItems.remove(row);
     mLastRowSelected = -1;
     //			this.drawList();
   }
 }
  /** Called when the user double clicks an item in the list */
  public void doubleClick(int row, int col) {
    highlightRow(row);
    final ScheduleItemGWT item = mScheduleItems.get(row);

    mScheduleController.editItem(false, item, null, -1);
  }
  /** Clears the current view and draws the list using the current set of schedule items. */
  public void drawList() {
    clear();

    final StringBuilder builder = new StringBuilder();
    builder.append("<div id=\"ListTableContainer\" onscroll=\"tableContainerScroll()\">");
    builder.append("<table id=\"ListTable\"><tr id=\"headerRow\">");

    // Add column header
    builder.append("<td class=\"columnHeader\" id='h'");
    builder
        .append("onclick=\"calendarListSort(")
        .append(columnIndices.COURSE_NAME.ordinal())
        .append(")\"");
    builder.append(">Course");
    if (mCurrentSort == sortBy.COURSE_NAME_ASC) builder.append(" &#9660;");
    else if (mCurrentSort == sortBy.COURSE_NAME_DESC) builder.append(" &#9650;");
    builder.append("</td>");

    builder.append("<td class=\"columnHeader\" id='h'");
    builder
        .append("onclick=\"calendarListSort(")
        .append(columnIndices.SECTION_NUMBER.ordinal())
        .append(")\"");
    builder.append(">Section Number");
    if (mCurrentSort == sortBy.SECTION_NUMBER_ASC) builder.append(" &#9660;");
    else if (mCurrentSort == sortBy.SECTION_NUMBER_DESC) builder.append(" &#9650;");
    builder.append("</td>");

    builder.append("<td class=\"columnHeader\" id='h'>Type</td>");

    builder.append("<td class=\"columnHeader\" id='h'>SCU</td>");

    builder.append("<td class=\"columnHeader\" id='h'>WTU</td>");

    builder.append("<td class=\"columnHeader\" id='h'");
    builder
        .append("onclick=\"calendarListSort(")
        .append(columnIndices.INSTRUCTOR.ordinal())
        .append(")\"");
    builder.append(">Instructor");
    if (mCurrentSort == sortBy.INSTRUCTOR_ASC) builder.append(" &#9660;");
    else if (mCurrentSort == sortBy.INSTRUCTOR_DESC) builder.append(" &#9650;");
    builder.append("</td>");

    builder.append("<td class=\"columnHeader\" id='h'>Location</td>");

    builder.append("<td class=\"columnHeader\" id='h'");
    builder
        .append("onclick=\"calendarListSort(")
        .append(columnIndices.DAYS.ordinal())
        .append(")\"");
    builder.append(">Days");
    if (mCurrentSort == sortBy.DAYS_ASC) builder.append(" &#9660;");
    else if (mCurrentSort == sortBy.DAYS_DESC) builder.append(" &#9650;");
    builder.append("</td>");

    builder.append("<td class=\"columnHeader\" id='h'");
    builder
        .append("onclick=\"calendarListSort(")
        .append(columnIndices.START_TIME.ordinal())
        .append(")\"");
    builder.append(">Start Time");
    if (mCurrentSort == sortBy.START_TIME_ASC) builder.append(" &#9660;");
    else if (mCurrentSort == sortBy.START_TIME_DESC) builder.append(" &#9650;");
    builder.append("</td>");

    builder.append("<td class=\"columnHeader\" id='h'");
    builder
        .append("onclick=\"calendarListSort(")
        .append(columnIndices.END_TIME.ordinal())
        .append(")\"");
    builder.append(">End Time");
    if (mCurrentSort == sortBy.END_TIME_ASC) builder.append(" &#9660;");
    else if (mCurrentSort == sortBy.END_TIME_DESC) builder.append(" &#9650;");
    builder.append("</td>");

    builder.append("<td class=\"columnHeader\" id='h'>Capacity</td>");

    builder.append("</tr>");

    int tableRow = 0;
    for (ScheduleItemGWT item : mScheduleItems) {
      int tableCol = 0;

      if (item.isConflicted()) {
        builder.append("<tr class=\"conflictedItem\">");
      } else {
        builder.append("<tr>");
      }

      builder.append(
          "<td "
              + "class=\"item\" id=\"x"
              + tableCol
              + "y"
              + tableRow
              + "\" "
              + "ondblclick=\"calendarListDoubleClick("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmousedown=\"calendarListMouseDown("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmouseup=\"calendarListMouseUp("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "tabindex=\"0\" "
              + "onkeydown=\"calendarListKeyDown("
              + tableRow
              + ",event.which)\" "
              + "onselectstart=\"return false\" "
              + ">"
              + mScheduleController.getCourseString(item.getCourseID())
              + "</td>");
      tableCol++;
      builder.append(
          "<td "
              + "class=\"item\" id=\"x"
              + tableCol
              + "y"
              + tableRow
              + "\" "
              + "ondblclick=\"calendarListDoubleClick("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmousedown=\"calendarListMouseDown("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmouseup=\"calendarListMouseUp("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "tabindex=\"0\" "
              + "onkeydown=\"calendarListKeyDown("
              + tableRow
              + ",event.which)\" "
              + "onselectstart=\"return false\" "
              + ">"
              + item.getSection()
              + "</td>");
      tableCol++;

      builder.append(
          "<td "
              + "class=\"item\" id=\"x"
              + tableCol
              + "y"
              + tableRow
              + "\" "
              + "ondblclick=\"calendarListDoubleClick("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmousedown=\"calendarListMouseDown("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmouseup=\"calendarListMouseUp("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "tabindex=\"0\" "
              + "onkeydown=\"calendarListKeyDown("
              + tableRow
              + ",event.which)\" "
              + "onselectstart=\"return false\" "
              + ">"
              + mScheduleController.getCourse(item.getCourseID()).getType()
              + "</td>");
      tableCol++;

      builder.append(
          "<td "
              + "class=\"item\" id=\"x"
              + tableCol
              + "y"
              + tableRow
              + "\" "
              + "ondblclick=\"calendarListDoubleClick("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmousedown=\"calendarListMouseDown("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmouseup=\"calendarListMouseUp("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "tabindex=\"0\" "
              + "onkeydown=\"calendarListKeyDown("
              + tableRow
              + ",event.which)\" "
              + "onselectstart=\"return false\" "
              + ">"
              + mScheduleController.getCourse(item.getCourseID()).getScu()
              + "</td>");
      tableCol++;

      builder.append(
          "<td "
              + "class=\"item\" id=\"x"
              + tableCol
              + "y"
              + tableRow
              + "\" "
              + "ondblclick=\"calendarListDoubleClick("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmousedown=\"calendarListMouseDown("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmouseup=\"calendarListMouseUp("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "tabindex=\"0\" "
              + "onkeydown=\"calendarListKeyDown("
              + tableRow
              + ",event.which)\" "
              + "onselectstart=\"return false\" "
              + ">"
              + mScheduleController.getCourse(item.getCourseID()).getWtu()
              + "</td>");
      tableCol++;

      builder.append(
          "<td "
              + "class=\"item\" id=\"x"
              + tableCol
              + "y"
              + tableRow
              + "\" "
              + "ondblclick=\"calendarListDoubleClick("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmousedown=\"calendarListMouseDown("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmouseup=\"calendarListMouseUp("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "tabindex=\"0\" "
              + "onkeydown=\"calendarListKeyDown("
              + tableRow
              + ",event.which)\" "
              + "onselectstart=\"return false\" "
              + ">");

      if (mScheduleController.getInstructor(item.getInstructorID()) != null) {
        builder.append(mScheduleController.getInstructor(item.getInstructorID()).getLastName());
        builder.append(", ");
        builder.append(mScheduleController.getInstructor(item.getInstructorID()).getFirstName());
      } else {
        builder.append("STAFF");
      }

      builder.append("</td>");
      tableCol++;

      builder.append(
          "<td "
              + "class=\"item\" id=\"x"
              + tableCol
              + "y"
              + tableRow
              + "\" "
              + "ondblclick=\"calendarListDoubleClick("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmousedown=\"calendarListMouseDown("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmouseup=\"calendarListMouseUp("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "tabindex=\"0\" "
              + "onkeydown=\"calendarListKeyDown("
              + tableRow
              + ",event.which)\" "
              + "onselectstart=\"return false\" "
              + ">");

      if (mScheduleController.getLocation(item.getLocationID()) != null) {
        builder.append(mScheduleController.getLocation(item.getLocationID()).getRoom());
      } else {
        builder.append("TBA");
      }

      builder.append("</td>");
      tableCol++;

      builder.append(
          "<td "
              + "class=\"item\" id=\"x"
              + tableCol
              + "y"
              + tableRow
              + "\" "
              + "ondblclick=\"calendarListDoubleClick("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmousedown=\"calendarListMouseDown("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmouseup=\"calendarListMouseUp("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "tabindex=\"0\" "
              + "onkeydown=\"calendarListKeyDown("
              + tableRow
              + ",event.which)\" "
              + "onselectstart=\"return false\" "
              + ">"
              + getDaysString(item.getDays())
              + "</td>");
      tableCol++;

      builder.append(
          "<td "
              + "class=\"item\" id=\"x"
              + tableCol
              + "y"
              + tableRow
              + "\" "
              + "ondblclick=\"calendarListDoubleClick("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmousedown=\"calendarListMouseDown("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmouseup=\"calendarListMouseUp("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "tabindex=\"0\" "
              + "onkeydown=\"calendarListKeyDown("
              + tableRow
              + ",event.which)\" "
              + "onselectstart=\"return false\" "
              + ">");

      int startRow = CalendarTableView.getStartRow(item);
      if (startRow >= 0 && startRow < ScheduleEditWidget.START_TIMES.length)
        builder.append(ScheduleEditWidget.START_TIMES[startRow]);

      builder.append("</td>");

      tableCol++;

      builder.append(
          "<td "
              + "class=\"item\" id=\"x"
              + tableCol
              + "y"
              + tableRow
              + "\" "
              + "ondblclick=\"calendarListDoubleClick("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmousedown=\"calendarListMouseDown("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmouseup=\"calendarListMouseUp("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "tabindex=\"0\" "
              + "onkeydown=\"calendarListKeyDown("
              + tableRow
              + ",event.which)\" "
              + "onselectstart=\"return false\" "
              + ">");

      int endRow = CalendarTableView.getEndRow(item) + 1;
      if (endRow >= 0 && endRow < ScheduleEditWidget.END_TIMES.length)
        builder.append(ScheduleEditWidget.END_TIMES[endRow]);

      builder.append("</td>");
      tableCol++;

      builder.append(
          "<td "
              + "class=\"item\" id=\"x"
              + tableCol
              + "y"
              + tableRow
              + "\" "
              + "ondblclick=\"calendarListDoubleClick("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmousedown=\"calendarListMouseDown("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "onmouseup=\"calendarListMouseUp("
              + tableRow
              + ","
              + tableCol
              + ")\" "
              + "tabindex=\"0\" "
              + "onkeydown=\"calendarListKeyDown("
              + tableRow
              + ",event.which)\" "
              + "onselectstart=\"return false\" "
              + ">"
              + mScheduleController.getCourse(item.getCourseID()).getMaxEnroll()
              + "</td>");
      tableCol++;

      builder.append("</tr>");
      // builder.append("<tr height=0><td class=\"rowSpacer\" colspan=\"12\"></td></tr>");
      tableRow++;
    }

    builder.append("</table>");
    builder.append("</div>");

    mInnerHTML = builder.toString();
    setHTML(mInnerHTML);
    setLeftOffset(mLeftOffset);
    setTopOffset(mScheduleController.getWidget().getAbsoluteTop());
  }