private void resetTypeLinks() {
   for (final FormToggle link : typeCmpList) {
     link.toggleOff();
     selectedTypeList.clear();
   }
   typeEditBtn.toggleOff();
 }
 private void resetTagLinks() {
   for (final FormToggle link : tagCmpList) {
     link.toggleOff();
     selectedTagsList.clear();
   }
   tagEditBtn.toggleOff();
 }
  private void updateTypeFlc() {
    final List<String> allActiveTypeToggles = new ArrayList<String>();
    for (final FormToggle link : typeCmpList) {
      final String type = (String) link.getUserObject();
      if (selectedTypeList.contains(type)) {
        if (!link.isOn()) {
          link.toggleOn();
        }
        allActiveTypeToggles.add(type);
      } else if (link.isOn()) {
        link.toggleOff();
      }
    }

    if (allActiveTypeToggles.containsAll(selectedTypeList)) {
      typeEditBtn.toggleOff();
    } else {
      typeEditBtn.toggleOn();
    }
    if (selectedTypeList.isEmpty()) {
      typeAllBtn.toggleOn();
    } else {
      typeAllBtn.toggleOff();
    }
  }
 private void initTagFlc() {
   tagFlc.setLabel("filter.tag", null);
   tagAllBtn = uifactory.addToggleButton("filter.all", null, tagFlc, null, null);
   tagAllBtn.toggleOff();
   tagNoneBtn = uifactory.addToggleButton("filter.notag", null, tagFlc, null, null);
   final Map<String, String> userTags = ePFMgr.getUsersMostUsedTags(getIdentity(), 8);
   int i = 1;
   tagCmpList = new ArrayList<FormToggle>();
   final LinkedList<Entry<String, String>> sortEntrySet =
       new LinkedList<Entry<String, String>>(userTags.entrySet());
   Collections.sort(
       sortEntrySet,
       new Comparator<Entry<String, String>>() {
         @Override
         public int compare(final Entry<String, String> arg0, final Entry<String, String> arg1) {
           return arg0.getValue().compareTo(arg1.getValue());
         }
       });
   final List<String> allActiveTagToggles = new ArrayList<String>();
   for (final Entry<String, String> entry : sortEntrySet) {
     final String tag = entry.getValue();
     final String tagCmpName = TAG_CMP_IDENTIFIER + i;
     if (tagFlc.getComponent(tagCmpName) != null) {
       tagFlc.remove(tagCmpName);
     }
     final FormToggle link = uifactory.addToggleButton(tagCmpName, tag, tagFlc, null, null);
     link.setLabel("tag.one", new String[] {tag});
     link.setUserObject(tag);
     if (!selectedTagsList.isEmpty() && selectedTagsList.contains(tag)) {
       link.toggleOn();
       allActiveTagToggles.add(tag);
     }
     tagCmpList.add(link);
     i++;
   }
   tagFlc.contextPut("tagCmpList", tagCmpList);
   tagEditBtn = uifactory.addToggleButton("filter.edit", null, tagFlc, null, null);
   tagEditBtn.toggleOff();
   if (!allActiveTagToggles.containsAll(selectedTagsList)) {
     tagEditBtn.toggleOn();
   }
   if (selectedTagsList.isEmpty()) {
     tagAllBtn.toggleOn();
   }
 }
 private void initOrUpdateTypeFlc(final int limit) {
   typeFlc.setLabel("filter.view", null);
   typeAllBtn = uifactory.addToggleButton("filter.all", null, typeFlc, null, null);
   typeAllBtn.toggleOff();
   final List<EPArtefactHandler<?>> handlers = portfolioModule.getAllAvailableArtefactHandlers();
   typeCmpList = new ArrayList<FormToggle>();
   int i = 0;
   final List<String> allActiveTypeToggles = new ArrayList<String>();
   for (final EPArtefactHandler<?> handler : handlers) {
     final String handlerClass =
         PortfolioFilterController.HANDLER_PREFIX
             + handler.getClass().getSimpleName()
             + HANDLER_TITLE_SUFFIX;
     FormToggle link = (FormToggle) typeFlc.getFormComponent(handlerClass);
     if (link == null) {
       final PackageTranslator handlerTrans = handler.getHandlerTranslator(getTranslator());
       typeFlc.setTranslator(handlerTrans);
       link = uifactory.addToggleButton(handlerClass, null, typeFlc, null, null);
       link.setUserObject(handler.getType());
     }
     if (selectedTypeList.contains(handler.getType())) {
       link.toggleOn();
       allActiveTypeToggles.add(handler.getType());
     } else {
       link.toggleOff();
     }
     typeCmpList.add(link);
     i++;
     if (i > limit) {
       break;
     }
   }
   typeFlc.contextPut("typeCmpList", typeCmpList);
   typeEditBtn = uifactory.addToggleButton("filter.edit", null, typeFlc, null, null);
   typeEditBtn.toggleOff();
   if (!allActiveTypeToggles.containsAll(selectedTypeList)) {
     typeEditBtn.toggleOn();
   }
   if (selectedTypeList.isEmpty()) {
     typeAllBtn.toggleOn();
   }
 }
 /**
  * org.olat.presentation.framework.components.form.flexible.FormItem,
  * org.olat.presentation.framework.components.form.flexible.impl.FormEvent)
  */
 @SuppressWarnings("unused")
 @Override
 protected void formInnerEvent(
     final UserRequest ureq, final FormItem source, final FormEvent event) {
   if (source instanceof FormLink) {
     final FormLink link = (FormLink) source;
     if (link.getName().startsWith(TAG_CMP_IDENTIFIER)) {
       // a tag-Link got clicked, find out which
       final String selectedTag = (String) link.getUserObject();
       if (!selectedTagsList.contains(selectedTag)) {
         selectedTagsList.add(selectedTag);
         tagAllBtn.toggleOff();
         tagNoneBtn.toggleOff();
       } else {
         selectedTagsList.remove(selectedTag);
         if (selectedTagsList.isEmpty()) {
           tagAllBtn.toggleOn();
         }
       }
       filterSettings.setTagFilter(selectedTagsList);
       fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
     } else if (link.getName().startsWith(HANDLER_PREFIX)) {
       // a type-link got clicked
       final String selectedType = (String) link.getUserObject();
       if (!selectedTypeList.contains(selectedType)) {
         selectedTypeList.add(selectedType);
         typeAllBtn.toggleOff();
       } else {
         selectedTypeList.remove(selectedType);
         if (selectedTypeList.isEmpty()) {
           typeAllBtn.toggleOn();
         }
       }
       filterSettings.setTypeFilter(selectedTypeList);
       fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
     }
   }
   if (source == tagAllBtn) {
     resetTagLinks();
     tagNoneBtn.toggleOff();
     filterSettings.setTagFilter(selectedTagsList);
     fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
   } else if (source == tagNoneBtn) {
     resetTagLinks();
     tagAllBtn.toggleOff();
     filterSettings.setNoTagFilter();
     fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
   } else if (source == typeAllBtn) {
     resetTypeLinks();
     filterSettings.setTypeFilter(selectedTypeList);
     fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
   } else if (source == dateStart || source == dateEnd) {
     if (validateFormLogic(ureq)) {
       final List<Date> dateList = new ArrayList<Date>();
       final Date selStartDate = dateStart.getDate();
       final Date selEndDate = dateEnd.getDate();
       dateList.add(selStartDate);
       dateList.add(selEndDate);
       filterSettings.setDateFilter(dateList);
       fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
     }
   } else if (source == typeEditBtn) {
     popupTypesCallout(ureq);
   } else if (source == tagEditBtn) {
     popupTagsCallout(ureq);
   } else if (source == searchFld) {
     final String searchText = searchFld.getValue();
     filterSettings.setTextFilter(searchText);
     fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings));
   } else if (source == filterSave) {
     if (StringHelper.containsNonWhitespace(filterName.getValue())) {
       final String oldFilterName = filterSettings.getFilterName();
       filterSettings.setFilterName(filterName.getValue());
       filterSettings.setTextFilter(searchFld.getValue());
       if (filterSave.getUserObject() != null && filterName.getValue().equals(oldFilterName)) {
         // fake update, delete before adding again
         final String filterID = (String) filterSave.getUserObject();
         ePFMgr.deleteFilterFromUsersList(getIdentity(), filterID);
       }
       if (!filterName.getValue().equals(oldFilterName) && oldFilterName != null) {
         // set another id, to distinguish from old
         filterSettings.setFilterIdToUniqueId();
       }
       final List<EPFilterSettings> filterList = ePFMgr.getSavedFilterSettings(getIdentity());
       // create a new or insert existing again
       filterList.add(filterSettings);
       ePFMgr.setSavedFilterSettings(getIdentity(), filterList);
       toggleSaveUpdateFilterButtons(true);
       showInfo("filter.saved", filterSettings.getFilterName());
       updateUI(ureq, filterSettings);
     }
   } else if (source == filterDel) {
     if (filterDel.getUserObject() != null) {
       ePFMgr.deleteFilterFromUsersList(getIdentity(), (String) filterDel.getUserObject());
       // refresh ui
       filterName.setValue("");
       toggleSaveUpdateFilterButtons(false);
       showInfo("filter.deleted");
       updateUI(ureq, new EPFilterSettings());
     }
   } else if (source == filterName) {
     final String oldFilterName = filterSettings.getFilterName();
     if (filterSave.getUserObject() != null && !filterName.getValue().equals(oldFilterName)) {
       toggleSaveUpdateFilterButtons(false);
     } else if (filterName.getValue().equals(oldFilterName)) {
       toggleSaveUpdateFilterButtons(true);
     }
   } else if (source == filterSel) {
     if (filterSel.isOneSelected()) {
       final int filterIndex = filterSel.getSelected();
       if (filterIndex == 0) {
         final EPFilterSettings newSettings = new EPFilterSettings();
         updateUI(ureq, newSettings);
         fireEvent(ureq, new PortfolioFilterChangeEvent(newSettings));
       } else if (filterIndex > 0 && filterIndex - 1 < nonEmptyFilters.size()) {
         final EPFilterSettings newSettings = nonEmptyFilters.get(filterIndex - 1);
         if (!filterSettings.getFilterId().equals(newSettings.getFilterId())) {
           updateUI(ureq, newSettings);
           fireEvent(ureq, new PortfolioFilterChangeEvent(newSettings));
         }
       }
     }
   }
 }