Search in sources :

Example 11 with MultipleSelectionElementImpl

use of org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl in project OpenOLAT by OpenOLAT.

the class UserInterestsController method setSelectedInterests.

/**
 * Selects all checkboxes whose i18n keys are contained in the space-delimited <code>selectedInterestsKeys</code>.
 *
 * @param selectedInterestsIDs
 */
public void setSelectedInterests(String selectedInterestsIDs) {
    if (selectedInterestsIDs != null) {
        Set<String> selectedInterestsIDsAsSet = new HashSet<String>(Arrays.asList(selectedInterestsIDs.trim().split(":")));
        // for each ID we get, ...
        for (String selectedInterestID : selectedInterestsIDsAsSet) {
            if (!selectedInterestID.equals("")) {
                // ... we have to loop over all checkbox groups since we don't know which one the ID belongs to.
                for (MultipleSelectionElement checkboxGroup : this.checkboxGroups) {
                    String key = UserInterestsPropertyHandler.SUBCATEGORY_I18N_PREFIX + selectedInterestID;
                    MultipleSelectionElementImpl checkboxGroupImpl = (MultipleSelectionElementImpl) checkboxGroup;
                    if (checkboxGroupImpl.getKeys().contains(key)) {
                        checkboxGroup.select(key, true);
                    }
                }
            }
        }
    }
}
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)

Example 12 with MultipleSelectionElementImpl

use of org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl in project OpenOLAT by OpenOLAT.

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)

Example 13 with MultipleSelectionElementImpl

use of org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl in project OpenOLAT by OpenOLAT.

the class FormUIFactory method addCheckboxesHorizontal.

/**
 * Create a multiple selection element with check-boxes horizontal aligned.
 *
 * @param name
 * @param i18nLabel
 * @param formLayout
 * @param keys
 * @param values
 * @return
 */
public MultipleSelectionElement addCheckboxesHorizontal(String name, String i18nLabel, FormItemContainer formLayout, String[] keys, String[] values) {
    MultipleSelectionElement mse = new MultipleSelectionElementImpl(name);
    mse.setKeysAndValues(keys, values);
    setLabelIfNotNull(i18nLabel, mse);
    formLayout.add(mse);
    return mse;
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) MultipleSelectionElementImpl(org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl)

Example 14 with MultipleSelectionElementImpl

use of org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl in project OpenOLAT by OpenOLAT.

the class GroupSearchController method createSelection.

private MultipleSelectionElement createSelection(String name) {
    MultipleSelectionElement selection = new MultipleSelectionElementImpl(name, Layout.horizontal);
    selection.setKeysAndValues(new String[] { "on" }, new String[] { "" });
    tableCont.add(name, selection);
    return selection;
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) MultipleSelectionElementImpl(org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl)

Example 15 with MultipleSelectionElementImpl

use of org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl in project OpenOLAT by OpenOLAT.

the class EditMembershipController method createSelection.

private MultipleSelectionElement createSelection(boolean selected, boolean enabled, String role) {
    String name = "cb" + UUID.randomUUID().toString().replace("-", "");
    MultipleSelectionElement selection = new MultipleSelectionElementImpl(name, Layout.horizontal);
    selection.setElementCssClass("o_sel_role");
    selection.addActionListener(FormEvent.ONCHANGE);
    selection.setKeysAndValues(keys, values, new String[] { "o_sel_role_".concat(role) }, null);
    flc.add(name, selection);
    selection.select(keys[0], selected);
    selection.setEnabled(enabled);
    return selection;
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) MultipleSelectionElementImpl(org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl)

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