/**
   * This method is used to print collection breakdown data
   *
   * @param result
   */
  void setCollectionBreakDownPrintData(ArrayList<UserDataDo> result) {
    try {
      printResourceData.clear();
      UserDataDo maxAvgValue =
          Collections.max(
              result,
              new Comparator<UserDataDo>() {
                public int compare(UserDataDo o1, UserDataDo o2) {
                  Long obj1 = new Long(o1.getTimeSpent());
                  Long obj2 = new Long(o2.getTimeSpent());
                  return obj1.compareTo(obj2);
                }
              });

      final AdvancedFlexTable adTable = new AdvancedFlexTable();
      adTable.getElement().setAttribute("style", "background: #fff; width: 1000px;");

      adTable.setHeaderWidget(0, getHeaderLbl(i18n.GL3259(), 35));
      adTable.setHeaderWidget(1, getHeaderLbl(i18n.GL0308(), 55));
      adTable.setHeaderWidget(2, getHeaderLbl(i18n.GL3260(), 600));
      adTable.setHeaderWidget(3, getHeaderLbl(i18n.GL2084(), 110));
      adTable.setHeaderWidget(4, getHeaderLbl(i18n.GL3261(), 50));
      adTable.setHeaderWidget(5, getHeaderLbl(i18n.GL3273(), 60));

      int rowVal = 0;
      for (int i = 0; i < result.size(); i++) {
        adTable.setWidget(rowVal, 0, new Label(String.valueOf(result.get(i).getItemSequence())));

        // set Format
        String resourceCategory =
            result.get(i).getResourceFormat() != null
                ? result.get(i).getResourceFormat().trim()
                : "";
        String categoryStyle = "";
        if (resourceCategory.equalsIgnoreCase("website")
            || resourceCategory.equalsIgnoreCase("webpage")) {
          resourceCategory = "webpage";
          categoryStyle = res.css().category_new_type_webpage();
        } else if (resourceCategory.equalsIgnoreCase("slide")
            || resourceCategory.equalsIgnoreCase("image")) {
          resourceCategory = "image";
          categoryStyle = res.css().category_new_type_image();
        } else if (resourceCategory.equalsIgnoreCase("handout")
            || resourceCategory.equalsIgnoreCase("lesson")
            || resourceCategory.equalsIgnoreCase("textbook")
            || resourceCategory.equalsIgnoreCase("text")) {
          resourceCategory = "text";
          categoryStyle = res.css().category_new_type_text();
        } else if (resourceCategory.equalsIgnoreCase("exam")) {
          resourceCategory = "webpage";
          categoryStyle = res.css().category_new_type_webpage();
        } else if (resourceCategory.equalsIgnoreCase("video")) {
          resourceCategory = "video";
          categoryStyle = res.css().category_new_type_video();
        } else if (resourceCategory.equalsIgnoreCase("interactive")) {
          resourceCategory = "webpage";
          categoryStyle = res.css().category_new_type_interactive();
        } else if (resourceCategory.equalsIgnoreCase("audio")) {
          resourceCategory = "audio";
          categoryStyle = res.css().category_new_type_audio();
        } else {
          categoryStyle = res.css().category_new_type_other();
        }
        Label categorylbl = new Label();
        categorylbl.addStyleName(categoryStyle);
        categorylbl.addStyleName(res.css().setMarginAuto());
        adTable.setWidget(rowVal, 1, categorylbl);

        // Set Question Title
        Label questionTitle = new Label(AnalyticsUtil.html2text(result.get(i).getTitle()));
        questionTitle.setStyleName(res.css().alignCenterAndBackground());
        questionTitle.addStyleName(res.css().alignLeft());
        adTable.setWidget(rowVal, 2, questionTitle);

        // Set time spent
        HorizontalPanel timeSpentpnl = new HorizontalPanel();
        timeSpentpnl.add(AnalyticsUtil.getTimeStampLabel(result.get(i).getAvgTimeSpent()));
        Label progressBar = new Label();
        progressBar.setStyleName(res.css().setProgressBar());
        timeSpentpnl.add(progressBar);
        double maxAvgVal =
            ((double) result.get(i).getAvgTimeSpent()) / ((double) maxAvgValue.getTimeSpent());
        progressBar.getElement().getStyle().setWidth(maxAvgVal * 100, Unit.PX);
        adTable.setWidget(rowVal, 3, timeSpentpnl);

        // set Views label
        // HorizontalPanel viewpnl=new HorizontalPanel();
        Label viewlbl = new Label(Integer.toString(result.get(i).getViews()));
        viewlbl.setStyleName(res.css().alignCenterAndBackground());
        /* viewpnl.add(viewlbl);
        Label viewProgressBar=new Label();
        viewProgressBar.setStyleName(res.css().setProgressBar());
        viewpnl.add(viewProgressBar);
        float maxViewVal = ((float) result.get(i).getViews())/((float) maxViews.getViews());
        viewProgressBar.getElement().getStyle().setWidth(maxViewVal*100, Unit.PX);*/
        adTable.setWidget(rowVal, 4, viewlbl);

        // Set reactions
        int reaction = result.get(i).getAvgReaction();
        HTMLPanel reactionpnl = new HTMLPanel("");
        reactionpnl.add(new AnalyticsReactionWidget(reaction));
        Label reactioncount = new Label();
        reactionpnl.add(reactioncount);
        reactioncount.setText(reaction + "/5");
        reactioncount.setStyleName(res.css().alignCenterAndBackground());
        adTable.setWidget(rowVal, 5, reactionpnl);
        rowVal++;
      }
      printResourceData.add(adTable);
      printWidget.add(printResourceData);
    } catch (Exception e) {
      AppClientFactory.printSevereLogger(
          "CollectionSummaryTeacherView : setCollectionBreakDownPrintData : " + e.getMessage());
    }
  }
  /**
   * This method is used to display collection break down data.
   *
   * @param result
   * @param loadingImage
   */
  void setCollectionBreakDown(ArrayList<UserDataDo> result, final HTMLPanel loadingImage) {

    UserDataDo maxAvgValue =
        Collections.max(
            result,
            new Comparator<UserDataDo>() {
              public int compare(UserDataDo o1, UserDataDo o2) {
                Long obj1 = new Long(o1.getTimeSpent());
                Long obj2 = new Long(o2.getTimeSpent());
                return obj1.compareTo(obj2);
              }
            });

    final SortTable sortableTable = new SortTable();
    sortableTable.setStyleName(res.css().tableMain());
    sortableTable.getElement().setId("collectionbreak");
    sortableTable.setBorderWidth(1);
    sortableTable.setCellPadding(4);
    sortableTable.setCellSpacing(1);
    sortableTable.setWidth("800");
    sortableTable.getElement().getStyle().setBackgroundColor("#fff");
    sortableTable.addColumnHeader(i18n.GL3259(), 0);
    sortableTable.addColumnHeader(i18n.GL3267(), 1);
    sortableTable.addColumnHeader(i18n.GL3182(), 2);
    sortableTable.addColumnHeader(i18n.GL3268(), 3);
    sortableTable.addColumnHeader(i18n.GL0934(), 4);
    sortableTable.addColumnHeader(i18n.GL3261(), 5);
    sortableTable.getRowFormatter().addStyleName(0, res.css().tableHeader());

    int rowVal = 1;
    for (int i = 0; i < result.size(); i++) {
      Label number = new Label(String.valueOf(result.get(i).getItemSequence()));
      number.setStyleName(res.css().alignCenterAndBackground());
      sortableTable.setWidget(rowVal, 0, number);
      // set Format
      String resourceCategory =
          result.get(i).getResourceFormat() != null ? result.get(i).getResourceFormat().trim() : "";
      String categoryStyle = "";
      if (resourceCategory.equalsIgnoreCase("website")
          || resourceCategory.equalsIgnoreCase("webpage")) {
        resourceCategory = "webpage";
        categoryStyle = res.css().category_new_type_webpage();
      } else if (resourceCategory.equalsIgnoreCase("slide")
          || resourceCategory.equalsIgnoreCase("image")) {
        resourceCategory = "image";
        categoryStyle = res.css().category_new_type_image();
      } else if (resourceCategory.equalsIgnoreCase("handout")
          || resourceCategory.equalsIgnoreCase("lesson")
          || resourceCategory.equalsIgnoreCase("textbook")
          || resourceCategory.equalsIgnoreCase("text")) {
        resourceCategory = "text";
        categoryStyle = res.css().category_new_type_text();
      } else if (resourceCategory.equalsIgnoreCase("exam")) {
        resourceCategory = "webpage";
        categoryStyle = res.css().category_new_type_webpage();
      } else if (resourceCategory.equalsIgnoreCase("video")) {
        resourceCategory = "video";
        categoryStyle = res.css().category_new_type_video();
      } else if (resourceCategory.equalsIgnoreCase("interactive")) {
        resourceCategory = "webpage";
        categoryStyle = res.css().category_new_type_interactive();
      } else if (resourceCategory.equalsIgnoreCase("audio")) {
        resourceCategory = "audio";
        categoryStyle = res.css().category_new_type_audio();
      } else {
        categoryStyle = res.css().category_new_type_other();
      }
      Label categorylbl = new Label();
      categorylbl.setStyleName(res.css().alignCenterAndBackground());
      categorylbl.addStyleName(categoryStyle);
      categorylbl.addStyleName(res.css().setMarginAuto());
      sortableTable.setWidget(rowVal, 1, categorylbl);

      // Set Question Title
      Label questionTitle =
          new Label(
              AnalyticsUtil.html2text(
                  result.get(i).getTitle() != null ? result.get(i).getTitle() : ""));
      questionTitle.setStyleName(res.css().alignCenterAndBackground());
      questionTitle.addStyleName(res.css().alignLeft());
      sortableTable.setWidget(rowVal, 2, questionTitle);

      // Set time spent
      HorizontalPanel timeSpentpnl = new HorizontalPanel();
      timeSpentpnl.add(AnalyticsUtil.getTimeStampLabel(result.get(i).getAvgTimeSpent()));
      Label progressBar = new Label();
      progressBar.setStyleName(res.css().setProgressBar());
      timeSpentpnl.add(progressBar);
      double maxAvgVal =
          ((double) result.get(i).getAvgTimeSpent()) / ((double) maxAvgValue.getTimeSpent());
      progressBar.getElement().getStyle().setWidth(maxAvgVal * 100, Unit.PX);
      sortableTable.setWidget(rowVal, 3, timeSpentpnl);

      // set Views label
      Label viewlbl = new Label(Integer.toString(result.get(i).getViews()));
      viewlbl.setStyleName(res.css().alignCenterAndBackground());
      sortableTable.setWidget(rowVal, 4, viewlbl);

      // Set reactions
      int reaction = result.get(i).getAvgReaction();
      HTMLPanel reactionpnl = new HTMLPanel("");
      reactionpnl.add(new AnalyticsReactionWidget(reaction));
      Label reactioncount = new Label();
      reactionpnl.add(reactioncount);
      reactioncount.setText(reaction + "/5");
      reactioncount.setStyleName(res.css().alignCenterAndBackground());
      sortableTable.setWidget(rowVal, 5, reactionpnl);
      if (rowVal % 2 == 0) {
        sortableTable
            .getRowFormatter()
            .getElement(rowVal)
            .setAttribute("style", "background-color: #fafafa");
      }
      rowVal++;
    }
    if (result.size() == 0) {
      Label erroeMsg = new Label();
      erroeMsg.setStyleName(res.css().displayMessageTextForScoredQuestions());
      erroeMsg.setText(i18n.GL3467());
      teacherResourceBreakdownData.add(erroeMsg);
    }
    teacherResourceBreakdownData.add(sortableTable);
    filterDropDown.addChangeHandler(
        new ChangeHandler() {
          @Override
          public void onChange(ChangeEvent event) {
            teacherResourceBreakdownData.clear();
            int selectedIndex = filterDropDown.getSelectedIndex();
            sortableTable.setStyleName("collectionProgressTable");
            sortableTable.getElement().setId("collectionbreak");
            if (selectedIndex == 1) {
              if (questionsData.size() > 0) {
                setCollectionBreakDown(questionsData, loadingImage);
              } else {
                Label erroeMsg = new Label();
                erroeMsg.setStyleName(res.css().displayMessageTextForOEQuestions());
                erroeMsg.setText(i18n.GL3274());
                teacherResourceBreakdownData.add(erroeMsg);
              }
            } else if (selectedIndex == 2) {
              if (resourceData.size() > 0) {
                setCollectionBreakDown(resourceData, loadingImage);
              } else {
                Label erroeMsg = new Label();
                erroeMsg.setStyleName(res.css().displayMessageTextForOEQuestions());
                erroeMsg.setText(i18n.GL3467());
                teacherResourceBreakdownData.add(erroeMsg);
              }
            } else {
              if (allData.size() > 0) {
                setCollectionBreakDown(allData, loadingImage);
              } else {
                Label erroeMsg = new Label();
                erroeMsg.setStyleName(res.css().displayMessageTextForOEQuestions());
                erroeMsg.setText(i18n.GL3467());
                teacherResourceBreakdownData.add(erroeMsg);
              }
            }
            sortableTable.addDomHandler(new ClickOnTableCell(), ClickEvent.getType());
          }
        });
    loadingImage.setVisible(false);
  }
  /* (non-Javadoc)
   * @see org.ednovo.gooru.client.mvp.analytics.collectionSummaryTeacher.IsCollectionSummaryTeacherView#setTeacherResourceData(java.util.ArrayList, org.ednovo.gooru.shared.model.analytics.CollectionSummaryMetaDataDo, com.google.gwt.user.client.ui.HTMLPanel)
   */
  @Override
  public void setTeacherResourceData(
      ArrayList<UserDataDo> resourcesData,
      CollectionSummaryMetaDataDo collectionMetaData,
      HTMLPanel loadingImage) {
    this.collectionMetaData = collectionMetaData;

    teacherTabContainer.clearStyles();
    teacherTabContainer.setScoredQuestionsHilight();
    hideAllPanels();
    teacherResourceBreakdownDatapnl.setVisible(true);

    teacherScoredData.clear();
    teacherOpenendedData.clear();
    teacherResourceBreakdownData.clear();
    questionsData.clear();
    openendedData.clear();

    collectionProgressCount = 0;
    questionRowIndex.clear();
    resourceRowIndex.clear();
    // Set collection meta data
    if (collectionMetaData != null) {
      collectionOverViewWidget.setData(collectionMetaData, true);
      collectionSummaryWidget.setDataAnalyticsData(collectionMetaData, null);
      printWidget.add(collectionSummaryWidget);
      printWidget.add(collectionOverViewWidget);
      totalTimeSpentlbl.setText(getTimeSpent(collectionMetaData.getAvgTimeSpent()));
      totalViewlbl.setText(Integer.toString(collectionMetaData.getViews()));
      totalAvgReactionlbl.clear();
      totalAvgReactionlbl.add(new AnalyticsReactionWidget(collectionMetaData.getAvgReaction()));
    }
    Collections.sort(
        resourcesData,
        new Comparator<UserDataDo>() {
          public int compare(UserDataDo o1, UserDataDo o2) {
            Integer obj1 = new Integer(o1.getItemSequence());
            Integer obj2 = new Integer(o2.getItemSequence());
            return obj1.compareTo(obj2);
          }
        });
    // This is used for segrate data based on the category
    for (UserDataDo userDataDo : resourcesData) {
      if (QUESTION.equalsIgnoreCase(userDataDo.getResourceFormat())) {
        if (OE.equalsIgnoreCase(userDataDo.getType())) {
          openendedData.add(userDataDo);
        } else {
          questionsData.add(userDataDo);
        }
        questionRowIndex.add(collectionProgressCount);
      } else {
        resourceData.add(userDataDo);
        resourceRowIndex.add(collectionProgressCount);
      }
      collectionProgressCount++;
    }
    this.allData = resourcesData;
    setScoredQuestionsData(questionsData);
    setQuestionsPrintData(questionsData);
    setOpenendedQuestionsData(openendedData);
    setOpenendedQuestionsPrintData(openendedData);
    setCollectionBreakDown(resourcesData, loadingImage);
    setCollectionBreakDownPrintData(resourcesData);
  }