use of org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl in project openolat by klemens.
the class UserInterestsController method formInnerEvent.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formInnerEvent(org.olat.core.gui.UserRequest, org.olat.core.gui.components.form.flexible.FormItem, org.olat.core.gui.components.form.flexible.impl.FormEvent)
*/
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
super.formInnerEvent(ureq, source, event);
// did the user click on a check box?
if (this.checkboxGroups.contains(source)) {
// find out which checkboxes are selected at the moment.
Set<String> currentSelection = getCurrentSelection();
// if the user has not selected the maximum number of boxes...
if (getSelectionCount() < maxNumOfInterests) {
// ...enable all checkboxes
for (MultipleSelectionElement checkboxGroup : this.checkboxGroups) {
MultipleSelectionElementImpl multipleSelectionElementImpl = (MultipleSelectionElementImpl) checkboxGroup;
multipleSelectionElementImpl.setEnabled(multipleSelectionElementImpl.getKeys(), true);
}
} else {
// ... otherwise, disable all checkboxes except the selected ones.
for (MultipleSelectionElement checkboxGroup : this.checkboxGroups) {
MultipleSelectionElementImpl multipleSelectionElementImpl = (MultipleSelectionElementImpl) checkboxGroup;
Set<String> allUncheckedCheckboxes = new HashSet<String>(multipleSelectionElementImpl.getKeys());
allUncheckedCheckboxes.removeAll(currentSelection);
multipleSelectionElementImpl.setEnabled(allUncheckedCheckboxes, false);
}
showWarning("form.warning.maxNumber");
}
}
}
Aggregations