Search in sources :

Example 56 with MultipleSelectionElement

use of org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement 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 57 with MultipleSelectionElement

use of org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement 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)

Example 58 with MultipleSelectionElement

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

the class UserInterestsController method getSelectedInterests.

/**
 * Returns a string which contains the identifiers of the selected checkboxes, delimited by colons.
 *
 * @return a string which contains the i18n keys of the selected checkboxes, delimited by colons.
 */
public String getSelectedInterests() {
    // Retrieve the i18n keys of the selected checkboxes
    Set<String> selectedInterestsKeysAsSet = new HashSet<String>();
    for (MultipleSelectionElement checkboxGroup : this.checkboxGroups) {
        selectedInterestsKeysAsSet.addAll(checkboxGroup.getSelectedKeys());
    }
    if (selectedInterestsKeysAsSet.size() > 0) {
        // convert these keys into IDs
        @SuppressWarnings("hiding") Set<String> selectedInterestsIDs = new HashSet<String>();
        for (String selectedInterestKey : selectedInterestsKeysAsSet) {
            selectedInterestsIDs.add(selectedInterestKey.replace(UserInterestsPropertyHandler.SUBCATEGORY_I18N_PREFIX, ""));
        }
        StringBuffer selectedInterestsKeys = new StringBuffer();
        selectedInterestsKeys.append(":");
        for (String selectedInterestID : selectedInterestsIDs) {
            selectedInterestsKeys.append(selectedInterestID);
            selectedInterestsKeys.append(":");
        }
        return selectedInterestsKeys.toString();
    } else {
        return "";
    }
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) HashSet(java.util.HashSet)

Example 59 with MultipleSelectionElement

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

the class VideoAdminSetController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == deactivationHintController) {
        if (event == Event.CANCELLED_EVENT) {
        } else {
            if (DialogBoxUIFactory.isYesEvent(event)) {
                videoModule.setTranscodingEnabled(false);
                enableTranscodingEl.select("on", false);
                updateResolutionOptions();
            } else {
                MultipleSelectionElement el = (MultipleSelectionElement) deactivationHintController.getUserObject();
                el.select("on", true);
            }
        }
    }
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)

Example 60 with MultipleSelectionElement

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

the class PortfolioAdminController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // module configuration
    FormLayoutContainer moduleFlc = FormLayoutContainer.createDefaultFormLayout("flc_module", getTranslator());
    formLayout.add(moduleFlc);
    String[] enabledValues = new String[] { translate("enabled") };
    String[] enabledPortfolioValues = new String[] { translate("enabled"), translate("portfolio.v1.module.enabled") };
    portfoliosEnabled = uifactory.addCheckboxesVertical("portfolio.module.enabled", moduleFlc, enabledPortfolioKeys, enabledPortfolioValues, 1);
    if (portfolioModule.isEnabled() || portfolioV2Module.isEnabled()) {
        portfoliosEnabled.select(enabledPortfolioKeys[0], true);
    }
    if (portfolioModule.isEnabled()) {
        portfoliosEnabled.select(enabledPortfolioKeys[1], true);
    }
    portfoliosEnabled.addActionListener(FormEvent.ONCHANGE);
    createBinderEl = uifactory.addCheckboxesVertical("portfolio.user.create.binder", moduleFlc, BINDER_CREATE_KEYS, translateKeys(BINDER_CREATE_KEYS), 1);
    createBinderEl.addActionListener(FormEvent.ONCHANGE);
    String[] entryPointKeys = new String[] { PortfolioV2Module.ENTRY_POINT_TOC, PortfolioV2Module.ENTRY_POINT_ENTRIES };
    String[] entryPointValues = new String[] { translate("binder.entry.point.toc"), translate("binder.entry.point.entries") };
    entryPointEl = uifactory.addDropdownSingleselect("binder.entry.point", "binder.entry.point", moduleFlc, entryPointKeys, entryPointValues, null);
    entryPointEl.addActionListener(FormEvent.ONCHANGE);
    String entryPoint = portfolioV2Module.getBinderEntryPoint();
    for (String entryPointKey : entryPointKeys) {
        if (entryPointKey.equals(entryPoint)) {
            entryPointEl.select(entryPointKey, true);
        }
    }
    if (!entryPointEl.isOneSelected()) {
        entryPointEl.select(entryPointKeys[0], true);
    }
    sectionVisibilityEl = uifactory.addCheckboxesVertical("section.enabled", moduleFlc, SECTION_VISIBILITY_KEYS, translateKeys(SECTION_VISIBILITY_KEYS), 1);
    sectionVisibilityEl.addActionListener(FormEvent.ONCHANGE);
    entryElementsVisibilityEl = uifactory.addCheckboxesVertical("entries.elements.enabled", moduleFlc, ENTRIES_ELEMENTS_KEYS, translateKeys(ENTRIES_ELEMENTS_KEYS), 1);
    entryElementsVisibilityEl.addActionListener(FormEvent.ONCHANGE);
    commentsVisibilityEl = uifactory.addCheckboxesVertical("comments.enabled", moduleFlc, COMMENTS_KEYS, translateKeys(COMMENTS_KEYS), 1);
    commentsVisibilityEl.addActionListener(FormEvent.ONCHANGE);
    entriesViewEl = uifactory.addDropdownSingleselect("entries.view", moduleFlc, ENTRIES_VIEW_KEYS, translateKeys(ENTRIES_VIEW_KEYS));
    String selectedKey = ENTRIES_BOTH_ENABLED;
    if (portfolioV2Module.isEntriesTableEnabled() && !portfolioV2Module.isEntriesListEnabled()) {
        selectedKey = ENTRIES_TABLE_ENABLED;
    } else if (!portfolioV2Module.isEntriesTableEnabled() && portfolioV2Module.isEntriesListEnabled()) {
        selectedKey = ENTRIES_LIST_ENABLED;
    }
    entriesViewEl.select(selectedKey, true);
    entriesViewEl.addActionListener(FormEvent.ONCHANGE);
    // handlers configuration
    FormLayoutContainer handlersFlc = FormLayoutContainer.createDefaultFormLayout("flc_handlers", getTranslator());
    formLayout.add(handlersFlc);
    List<EPArtefactHandler<?>> handlers = portfolioModule.getAllAvailableArtefactHandlers();
    for (EPArtefactHandler<?> handler : handlers) {
        Translator handlerTrans = handler.getHandlerTranslator(getTranslator());
        handlersFlc.setTranslator(handlerTrans);
        String handlerClass = PortfolioFilterController.HANDLER_PREFIX + handler.getClass().getSimpleName() + PortfolioFilterController.HANDLER_TITLE_SUFFIX;
        MultipleSelectionElement handlerEnabled = uifactory.addCheckboxesHorizontal(handlerClass, handlersFlc, enabledKeys, enabledValues);
        handlerEnabled.select(enabledKeys[0], handler.isEnabled());
        handlerEnabled.setUserObject(handler);
        handlerEnabled.addActionListener(FormEvent.ONCHANGE);
        handlersEnabled.add(handlerEnabled);
    }
    // configure steps in artefact collection wizard
    wizardFlc = FormLayoutContainer.createDefaultFormLayout("flc_wizard", getTranslator());
    formLayout.add(wizardFlc);
    copyrightStepCB = uifactory.addCheckboxesHorizontal("wizard.step.copyright", wizardFlc, enabledKeys, enabledValues);
    copyrightStepCB.select(enabledKeys[0], portfolioModule.isCopyrightStepEnabled());
    copyrightStepCB.addActionListener(FormEvent.ONCHANGE);
    reflexionStepCB = uifactory.addCheckboxesHorizontal("wizard.step.reflexion", wizardFlc, enabledKeys, enabledValues);
    reflexionStepCB.select(enabledKeys[0], portfolioModule.isReflexionStepEnabled());
    reflexionStepCB.addActionListener(FormEvent.ONCHANGE);
    wizardFlc.setVisible(portfoliosEnabled.isSelected(1));
    updateV2UI();
}
Also used : EPArtefactHandler(org.olat.portfolio.EPArtefactHandler) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) Translator(org.olat.core.gui.translator.Translator) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Aggregations

MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)136 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)22 ArrayList (java.util.ArrayList)20 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)16 MultipleSelectionElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.MultipleSelectionElementImpl)16 HashMap (java.util.HashMap)12 HashSet (java.util.HashSet)12 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)12 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)10 FormItem (org.olat.core.gui.components.form.flexible.FormItem)8 Identity (org.olat.core.id.Identity)8 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)8 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)6 ICourse (org.olat.course.ICourse)6 Checkbox (org.olat.course.nodes.cl.model.Checkbox)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)5 VFSItem (org.olat.core.util.vfs.VFSItem)5 Section (org.olat.modules.portfolio.Section)5 File (java.io.File)4 UserShortDescription (org.olat.admin.user.UserShortDescription)4