Search in sources :

Example 16 with MultipleSelectionElementImpl

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");
        }
    }
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) MultipleSelectionElementImpl(org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl) HashSet(java.util.HashSet)

Aggregations

MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)16 MultipleSelectionElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl)16 HashSet (java.util.HashSet)6 Vector (java.util.Vector)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2