private void loadModel(UserRequest ureq) {
    IdentityEnvironment identityEnv = ureq.getUserSession().getIdentityEnvironment();

    List<Binder> currentBinders =
        portfolioService.searchOwnedBindersFromCourseTemplate(getIdentity());
    Set<CurrentBinder> currentSet = new HashSet<>();
    for (Binder currentBinder : currentBinders) {
      Long courseEntryKey = currentBinder.getEntry().getKey();
      String nodeIdent = currentBinder.getSubIdent();
      currentSet.add(new CurrentBinder(courseEntryKey, nodeIdent));
    }

    List<RepositoryEntry> entries = portfolioService.searchCourseWithBinderTemplates(getIdentity());
    List<CourseTemplateRow> rows = new ArrayList<>(entries.size());
    for (RepositoryEntry entry : entries) {
      ICourse course = CourseFactory.loadCourse(entry);
      UserCourseEnvironment uce =
          new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
      uce.getScoreAccounting().evaluateAll();

      CourseNode rootNode = uce.getCourseEnvironment().getRunStructure().getRootNode();
      loadCourseModel(rootNode, uce, rows, currentSet);
    }

    model.setObjects(rows);
    tableEl.reset();
    tableEl.reloadData();
  }
  private void updateGUI(ModelInfos modelInfos) {
    if (modelInfos.isSame()) {
      applyToAllEl.select(onKeys[0], true);
      table.setVisible(false);

      if (groupPassedEl != null) {
        groupPassedEl.setVisible(true);
        Boolean passed = modelInfos.getPassed();
        groupPassedEl.select(onKeys[0], passed != null && passed.booleanValue());
      }
      if (groupScoreEl != null) {
        groupScoreEl.setVisible(true);
        Float score = modelInfos.getScore();
        if (score != null) {
          String scoreVal = AssessmentHelper.getRoundedScore(score);
          groupScoreEl.setValue(scoreVal);
        } else {
          groupScoreEl.setValue("");
        }
      }
      if (groupCommentEl != null) {
        groupCommentEl.setVisible(true);
        String comment = modelInfos.getComment();
        if (comment != null) {
          groupCommentEl.setValue(comment);
        }
      }
    } else {
      applyToAllEl.select(onKeys[0], false);
      table.setVisible(true);
      if (groupPassedEl != null) {
        groupPassedEl.setVisible(false);
      }
      if (groupScoreEl != null) {
        groupScoreEl.setVisible(false);
      }
      if (groupCommentEl != null) {
        groupCommentEl.setVisible(false);
      }
    }

    if (StringHelper.containsNonWhitespace(modelInfos.getDuplicates())) {
      String warning =
          translate(
              "error.duplicate.memberships",
              new String[] {gtaNode.getShortTitle(), modelInfos.getDuplicates()});
      flc.contextPut("duplicateWarning", warning);
    } else {
      flc.contextRemove("duplicateWarning");
    }
  }
  @Override
  protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(CTCols.course, "select"));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(CTCols.courseNode, "select"));
    columnsModel.addFlexiColumnModel(
        new DefaultFlexiColumnModel("select", translate("select"), "select"));

    model = new CourseTemplateSearchDataModel(columnsModel);
    tableEl =
        uifactory.addTableElement(
            getWindowControl(), "table", model, 20, false, getTranslator(), formLayout);
    tableEl.setCustomizeColumns(false);
    tableEl.setEmtpyTableMessageKey("no.binders.template.available");
  }
 @Override
 protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
   if (applyToAllEl == source) {
     boolean allGroup = applyToAllEl.isAtLeastSelected(1);
     table.setVisible(!allGroup);
     if (groupPassedEl != null) {
       groupPassedEl.setVisible(allGroup);
     }
     if (groupScoreEl != null) {
       groupScoreEl.setVisible(allGroup);
     }
     if (groupCommentEl != null) {
       groupCommentEl.setVisible(allGroup);
     }
   } else if (source == saveAndDoneButton) {
     if (validateFormLogic(ureq)) {
       applyChanges(true);
       fireEvent(ureq, Event.CLOSE_EVENT);
     }
   } else if (source instanceof FormLink) {
     FormLink link = (FormLink) source;
     if ("comment".equals(link.getCmd())) {
       AssessmentRow row = (AssessmentRow) link.getUserObject();
       doEditComment(ureq, row);
     }
   }
   super.formInnerEvent(ureq, source, event);
 }
  @Override
  protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {

    addSolutionLink = uifactory.addFormLink("add.solution", formLayout, Link.BUTTON);
    addSolutionLink.setElementCssClass("o_sel_course_gta_add_solution");
    addSolutionLink.setIconLeftCSS("o_icon o_icon_upload");
    createSolutionLink = uifactory.addFormLink("create.solution", formLayout, Link.BUTTON);
    createSolutionLink.setElementCssClass("o_sel_course_gta_create_solution");
    createSolutionLink.setIconLeftCSS("o_icon o_icon_edit");

    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    columnsModel.addFlexiColumnModel(
        new DefaultFlexiColumnModel(SolCols.title.i18nKey(), SolCols.title.ordinal()));
    columnsModel.addFlexiColumnModel(
        new DefaultFlexiColumnModel(SolCols.file.i18nKey(), SolCols.file.ordinal()));
    columnsModel.addFlexiColumnModel(
        new DefaultFlexiColumnModel(SolCols.author.i18nKey(), SolCols.author.ordinal()));
    columnsModel.addFlexiColumnModel(
        new StaticFlexiColumnModel(
            "table.header.edit",
            SolCols.edit.ordinal(),
            "edit",
            new BooleanCellRenderer(
                new StaticFlexiCellRenderer(translate("edit"), "edit"),
                new StaticFlexiCellRenderer(translate("replace"), "edit"))));
    columnsModel.addFlexiColumnModel(
        new StaticFlexiColumnModel("table.header.edit", translate("delete"), "delete"));

    solutionModel = new SolutionTableModel(columnsModel);
    solutionTable =
        uifactory.addTableElement(
            getWindowControl(), "table", solutionModel, getTranslator(), formLayout);
    solutionTable.setExportEnabled(true);
    updateModel();
  }
 @Override
 protected void event(UserRequest ureq, Controller source, Event event) {
   if (commentCalloutCtrl == source) {
     cleanUp();
   } else if (editCommentCtrl == source) {
     if (event == Event.DONE_EVENT) {
       table.reset();
     }
     commentCalloutCtrl.deactivate();
     cleanUp();
   }
   super.event(ureq, source, event);
 }
  @Override
  protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("manage.transcodings.title");
    setFormDescription("manage.transcodings.description");
    setFormContextHelp("Portfolio template: Administration and editing#configuration");

    FlexiTableColumnModel transcodingModel =
        FlexiTableDataModelFactory.createFlexiTableColumnModel();
    transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.resolutions));
    transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.sumVideos));
    transcodingModel.addFlexiColumnModel(
        new DefaultFlexiColumnModel(TranscodingCols.numberTranscodings));
    transcodingModel.addFlexiColumnModel(
        new DefaultFlexiColumnModel(TranscodingCols.missingTranscodings));
    transcodingModel.addFlexiColumnModel(
        new DefaultFlexiColumnModel(
            TranscodingCols.transcode,
            "quality.transcode",
            new BooleanCellRenderer(
                new StaticFlexiCellRenderer(translate("quality.transcode"), "quality.transcode"),
                null)));
    transcodingModel.addFlexiColumnModel(
        new DefaultFlexiColumnModel(
            TranscodingCols.delete,
            "quality.delete",
            new BooleanCellRenderer(
                new StaticFlexiCellRenderer(translate("quality.delete"), "quality.delete"), null)));
    tableModel = new TranscodingTableModel(transcodingModel, getTranslator());

    transcodingTable =
        uifactory.addTableElement(
            getWindowControl(), "table", tableModel, getTranslator(), formLayout);
    transcodingTable.setCustomizeColumns(false);
    transcodingTable.setNumOfRowsEnabled(false);

    setChecks();
  }
 private void loadTable() {
   // Hardcoded same as VideoAdminSetController
   int[] resolution = {2160, 1080, 720, 480, 360, 240};
   // FIXME:FK fetch using one single SQL query
   for (int i = 0; i < resolution.length; i++) {
     int sizeOfTranscodings = availableTranscodings.get(resolution[i]).size();
     int counter = 0;
     for (OLATResource videoResource : olatresources) {
       VideoMetadata videoMetadata = videoManager.readVideoMetadataFile(videoResource);
       if (videoMetadata != null && videoMetadata.getHeight() >= resolution[i]) counter++;
     }
     resolutions.add(
         new TranscodingRow(
             resolution[i], sizeOfTranscodings, counter, mayTranscode(resolution[i])));
   }
   if (resolutions != null) tableModel.setObjects(resolutions);
   transcodingTable.reset(true, true, true);
 }
  private void updateModel() {
    List<Solution> solutionList = solutions.getSolutions();
    List<SolutionRow> rows = new ArrayList<>(solutionList.size());
    for (Solution solution : solutionList) {
      String filename = solution.getFilename();
      String author = null;

      VFSItem item = solutionContainer.resolve(filename);
      if (item instanceof MetaTagged) {
        MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
        if (metaInfo != null && metaInfo.getAuthorIdentityKey() != null) {
          author = userManager.getUserDisplayName(metaInfo.getAuthorIdentityKey());
        }
      }

      rows.add(new SolutionRow(solution, author));
    }
    solutionModel.setObjects(rows);
    solutionTable.reset();
  }
  /**
   * Perform a search for the given search value in the search result providers and clear any GUI
   * errors that might be on the page
   *
   * @param searchValue
   * @param ureq
   */
  private void doSearchGroups(String searchValue, UserRequest ureq) {
    if (StringHelper.containsNonWhitespace(searchValue)) {
      SearchBusinessGroupParams param1s = new SearchBusinessGroupParams();
      param1s.setNameOrDesc(searchValue);
      List<BusinessGroup> group1s = businessGroupService.findBusinessGroups(param1s, null, 0, -1);
      filterGroups(group1s);

      SearchBusinessGroupParams param2s = new SearchBusinessGroupParams();
      param2s.setCourseTitle(searchValue);
      List<BusinessGroup> group2s = businessGroupService.findBusinessGroups(param2s, null, 0, -1);
      filterGroups(group2s);

      List<BusinessGroup> groups = new ArrayList<BusinessGroup>(group1s.size() + group2s.size());
      groups.addAll(group1s);
      groups.addAll(group2s);

      List<Long> groupKeysWithRelations = PersistenceHelper.toKeys(groups);
      List<BGRepositoryEntryRelation> resources =
          businessGroupService.findRelationToRepositoryEntries(groupKeysWithRelations, 0, -1);

      List<GroupWrapper> groupWrappers = new ArrayList<GroupWrapper>();
      for (BusinessGroup group : groups) {
        StringBuilder sb = new StringBuilder();
        for (BGRepositoryEntryRelation resource : resources) {
          if (resource.getGroupKey().equals(group.getKey())) {
            if (sb.length() > 0) sb.append(", ");
            sb.append(resource.getRepositoryEntryDisplayName());
          }
        }

        GroupWrapper wrapper = new GroupWrapper(group, sb.toString());
        wrapper.setTutor(createSelection("tutor_" + group.getKey()));
        wrapper.setParticipant(createSelection("participant_" + group.getKey()));
        groupWrappers.add(wrapper);
      }

      table.reset();
      tableDataModel.setObjects(groupWrappers);
      errorComp.clearError();
    }
  }
  /** @return True if all results are the same */
  private ModelInfos loadModel() {
    // load participants, load datas
    ICourse course = CourseFactory.loadCourse(courseEnv.getCourseResourceableId());
    List<Identity> identities =
        businessGroupService.getMembers(assessedGroup, GroupRoles.participant.name());

    Map<Identity, AssessmentEntry> identityToEntryMap = new HashMap<>();
    List<AssessmentEntry> entries =
        course
            .getCourseEnvironment()
            .getAssessmentManager()
            .getAssessmentEntries(assessedGroup, gtaNode);
    for (AssessmentEntry entry : entries) {
      identityToEntryMap.put(entry.getIdentity(), entry);
    }

    int count = 0;
    boolean same = true;
    StringBuilder duplicateWarning = new StringBuilder();
    Float scoreRef = null;
    Boolean passedRef = null;
    String commentRef = null;

    List<AssessmentRow> rows = new ArrayList<>(identities.size());
    for (Identity identity : identities) {
      AssessmentEntry entry = identityToEntryMap.get(identity);

      ScoreEvaluation scoreEval = null;
      if (withScore || withPassed) {
        scoreEval = gtaNode.getUserScoreEvaluation(entry);
        if (scoreEval == null) {
          scoreEval = ScoreEvaluation.EMPTY_EVALUATION;
        }
      }

      String comment = null;
      if (withComment && entry != null) {
        comment = entry.getComment();
      }

      boolean duplicate = duplicateMemberKeys.contains(identity.getKey());
      if (duplicate) {
        if (duplicateWarning.length() > 0) duplicateWarning.append(", ");
        duplicateWarning.append(StringHelper.escapeHtml(userManager.getUserDisplayName(identity)));
      }

      AssessmentRow row = new AssessmentRow(identity, duplicate);
      rows.add(row);

      if (withScore) {
        Float score = scoreEval.getScore();
        String pointVal = AssessmentHelper.getRoundedScore(score);
        TextElement pointEl = uifactory.addTextElement("point" + count, null, 5, pointVal, flc);
        pointEl.setDisplaySize(5);
        row.setScoreEl(pointEl);
        if (count == 0) {
          scoreRef = score;
        } else if (!same(scoreRef, score)) {
          same = false;
        }
      }

      if (withPassed && cutValue == null) {
        Boolean passed = scoreEval.getPassed();
        MultipleSelectionElement passedEl =
            uifactory.addCheckboxesHorizontal("check" + count, null, flc, onKeys, onValues);
        if (passed != null && passed.booleanValue()) {
          passedEl.select(onKeys[0], passed.booleanValue());
        }
        row.setPassedEl(passedEl);
        if (count == 0) {
          passedRef = passed;
        } else if (!same(passedRef, passed)) {
          same = false;
        }
      }

      if (withComment) {
        FormLink commentLink =
            uifactory.addFormLink(
                "comment-" + CodeHelper.getRAMUniqueID(),
                "comment",
                "comment",
                null,
                flc,
                Link.LINK);
        if (StringHelper.containsNonWhitespace(comment)) {
          commentLink.setIconLeftCSS("o_icon o_icon_comments");
        } else {
          commentLink.setIconLeftCSS("o_icon o_icon_comments_none");
        }
        commentLink.setUserObject(row);
        row.setComment(comment);
        row.setCommentEditLink(commentLink);

        if (count == 0) {
          commentRef = comment;
        } else if (!same(commentRef, comment)) {
          same = false;
        }
      }

      count++;
    }

    model.setObjects(rows);
    table.reset();

    return new ModelInfos(same, scoreRef, passedRef, commentRef, duplicateWarning.toString());
  }
  @Override
  protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {

    FormLayoutContainer groupGradingCont =
        FormLayoutContainer.createDefaultFormLayout("groupGrading", getTranslator());
    groupGradingCont.setRootForm(mainForm);
    formLayout.add(groupGradingCont);

    applyToAllEl =
        uifactory.addCheckboxesHorizontal(
            "applytoall", "group.apply.toall", groupGradingCont, onKeys, onValues);
    applyToAllEl.addActionListener(FormEvent.ONCHANGE);
    applyToAllEl.setElementCssClass("o_sel_course_gta_apply_to_all");

    if (withPassed && cutValue == null) {
      groupPassedEl =
          uifactory.addCheckboxesHorizontal(
              "checkgroup", "group.passed", groupGradingCont, onKeys, onValues);
      groupPassedEl.setElementCssClass("o_sel_course_gta_group_passed");
    }

    if (withScore) {
      String pointVal = "";
      groupScoreEl =
          uifactory.addTextElement("pointgroup", "group.score", 5, pointVal, groupGradingCont);
      groupScoreEl.setElementCssClass("o_sel_course_gta_group_score");
    }

    if (withComment) {
      String comment = "";
      groupCommentEl =
          uifactory.addTextAreaElement(
              "usercomment", "group.comment", 2500, 5, 40, true, comment, groupGradingCont);
      groupCommentEl.setElementCssClass("o_sel_course_gta_group_comment");
    }

    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    if (isAdministrativeUser) {
      columnsModel.addFlexiColumnModel(
          new DefaultFlexiColumnModel(Cols.username.i18nKey(), Cols.username.ordinal()));
    }

    int i = 0;
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
      int colIndex = GTACoachedGroupGradingController.USER_PROPS_OFFSET + i++;
      if (userPropertyHandler == null) continue;

      String propName = userPropertyHandler.getName();
      boolean visible =
          userManager.isMandatoryUserProperty(
              GTACoachedGroupGradingController.USER_PROPS_ID, userPropertyHandler);
      if (visible) {
        FlexiColumnModel col;
        if (UserConstants.FIRSTNAME.equals(propName) || UserConstants.LASTNAME.equals(propName)) {
          col =
              new DefaultFlexiColumnModel(
                  userPropertyHandler.i18nColumnDescriptorLabelKey(),
                  colIndex,
                  userPropertyHandler.getName(),
                  true,
                  propName,
                  new StaticFlexiCellRenderer(
                      userPropertyHandler.getName(), new TextFlexiCellRenderer()));
        } else {
          col =
              new DefaultFlexiColumnModel(
                  true,
                  userPropertyHandler.i18nColumnDescriptorLabelKey(),
                  colIndex,
                  true,
                  propName);
        }
        columnsModel.addFlexiColumnModel(col);
      }
    }

    if (withPassed && cutValue == null) {
      columnsModel.addFlexiColumnModel(
          new DefaultFlexiColumnModel(Cols.passedEl.i18nKey(), Cols.passedEl.ordinal()));
    }

    if (withScore) {
      columnsModel.addFlexiColumnModel(
          new DefaultFlexiColumnModel(Cols.scoreEl.i18nKey(), Cols.scoreEl.ordinal()));
    }

    if (withComment) {
      columnsModel.addFlexiColumnModel(
          new DefaultFlexiColumnModel(Cols.commentEl.i18nKey(), Cols.commentEl.ordinal()));
    }

    model = new GroupAssessmentModel(gtaNode, userPropertyHandlers, getLocale(), columnsModel);
    table =
        uifactory.addTableElement(
            getWindowControl(), "group-list", model, getTranslator(), formLayout);
    table.setCustomizeColumns(true);
    table.setEditMode(true);
    table.setAndLoadPersistedPreferences(ureq, "gtagroup-assessment");

    FormLayoutContainer buttonsCont =
        FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    formLayout.add(buttonsCont);
    uifactory.addFormSubmitButton("save", buttonsCont);
    saveAndDoneButton = uifactory.addFormLink("save.done", buttonsCont, Link.BUTTON);
    uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
  }