Search in sources :

Example 1 with MultipleSelectionElementImpl

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

the class FormUIFactory method addCheckboxesVertical.

/**
 * Create a multiple selection element with check-boxes that is rendered in vertical columns
 * @param name
 * @param i18nLabel
 * @param formLayout
 * @param keys
 * @param values
 * @param cssClasses
 * @param columns
 * @return
 */
public MultipleSelectionElement addCheckboxesVertical(String name, String i18nLabel, FormItemContainer formLayout, String[] keys, String[] values, String[] cssClasses, String[] iconLeftCSS, int columns) {
    MultipleSelectionElement mse = new MultipleSelectionElementImpl(name, Layout.vertical, columns);
    mse.setKeysAndValues(keys, values, cssClasses, iconLeftCSS);
    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 2 with MultipleSelectionElementImpl

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

the class FormUIFactory method addCheckboxesDropdown.

public MultipleSelectionElement addCheckboxesDropdown(String name, String i18nLabel, FormItemContainer formLayout, String[] keys, String[] values, String[] cssClasses, String[] iconLeftCSS) {
    MultipleSelectionElement mse = new MultipleSelectionElementImpl(name, Layout.dropdown);
    mse.setKeysAndValues(keys, values, cssClasses, iconLeftCSS);
    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 3 with MultipleSelectionElementImpl

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

the class UserInterestsController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer, org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormDescription("userinterests.description");
    // Draw the checkboxes
    for (int i = 0; i < this.availableUserInterests.size(); i++) {
        UserInterestsCategory category = this.availableUserInterests.get(i);
        Vector<String> keys = new Vector<String>();
        for (UserInterestsCategory subcategory : category.getSubcategories()) {
            keys.add(UserInterestsPropertyHandler.SUBCATEGORY_I18N_PREFIX + subcategory.getId());
        }
        String[] values = new String[keys.size()];
        for (int j = 0; j < values.length; j++) {
            values[j] = translate(keys.get(j));
        }
        MultipleSelectionElement interestCheckboxes = uifactory.addCheckboxesVertical("interest_" + category.getId(), formLayout, keys.toArray(new String[0]), values, null, 2);
        this.checkboxGroups.add(interestCheckboxes);
        interestCheckboxes.setLabel(UserInterestsPropertyHandler.CATEGORY_I18N_PREFIX + category.getId(), null);
        interestCheckboxes.addActionListener(FormEvent.ONCHANGE);
        if (i != this.availableUserInterests.size() - 1) {
            uifactory.addSpacerElement("spacer_" + category.getId(), formLayout, false);
        }
    }
    // Check boxes for the given interests
    this.setSelectedInterests(this.selectedInterestsIDs);
    // Disable the checkboxes if already the maximum number is selected.
    if (getSelectionCount() >= maxNumOfInterests) {
        Set<String> currentSelection = getCurrentSelection();
        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");
    }
    // Add submit and cancel buttons
    final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("finish", buttonLayout);
    uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) MultipleSelectionElementImpl(org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl) Vector(java.util.Vector) HashSet(java.util.HashSet)

Example 4 with MultipleSelectionElementImpl

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

the class UserInterestsController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer, org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormDescription("userinterests.description");
    // Draw the checkboxes
    for (int i = 0; i < this.availableUserInterests.size(); i++) {
        UserInterestsCategory category = this.availableUserInterests.get(i);
        Vector<String> keys = new Vector<String>();
        for (UserInterestsCategory subcategory : category.getSubcategories()) {
            keys.add(UserInterestsPropertyHandler.SUBCATEGORY_I18N_PREFIX + subcategory.getId());
        }
        String[] values = new String[keys.size()];
        for (int j = 0; j < values.length; j++) {
            values[j] = translate(keys.get(j));
        }
        MultipleSelectionElement interestCheckboxes = uifactory.addCheckboxesVertical("interest_" + category.getId(), formLayout, keys.toArray(new String[0]), values, null, 2);
        this.checkboxGroups.add(interestCheckboxes);
        interestCheckboxes.setLabel(UserInterestsPropertyHandler.CATEGORY_I18N_PREFIX + category.getId(), null);
        interestCheckboxes.addActionListener(FormEvent.ONCHANGE);
        if (i != this.availableUserInterests.size() - 1) {
            uifactory.addSpacerElement("spacer_" + category.getId(), formLayout, false);
        }
    }
    // Check boxes for the given interests
    this.setSelectedInterests(this.selectedInterestsIDs);
    // Disable the checkboxes if already the maximum number is selected.
    if (getSelectionCount() >= maxNumOfInterests) {
        Set<String> currentSelection = getCurrentSelection();
        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");
    }
    // Add submit and cancel buttons
    final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("finish", buttonLayout);
    uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) MultipleSelectionElementImpl(org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl) Vector(java.util.Vector) HashSet(java.util.HashSet)

Example 5 with MultipleSelectionElementImpl

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

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)

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