Search in sources :

Example 16 with FormItem

use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.

the class CourseLayoutGeneratorController method prepareStyleEditor.

private void prepareStyleEditor(Map<String, Map<String, Object>> customConfig) {
    // keep config order
    guiWrapper = new LinkedHashMap<String, Map<String, FormItem>>();
    List<AbstractLayoutElement> allElements = customCMgr.getAllAvailableElements();
    List<AbstractLayoutAttribute> allAttribs = customCMgr.getAllAvailableAttributes();
    styleFlc.contextPut("allAttribs", allAttribs);
    // needed reference to get listener back.
    styleFlc.setUserObject(this);
    for (AbstractLayoutElement abstractLayoutElement : allElements) {
        String elementType = abstractLayoutElement.getLayoutElementTypeName();
        Map<String, Object> elConf = customConfig.get(elementType);
        AbstractLayoutElement concreteElmt = abstractLayoutElement.createInstance(elConf);
        HashMap<String, FormItem> elAttribGui = new HashMap<String, FormItem>();
        List<AbstractLayoutAttribute> attributes = concreteElmt.getAvailableAttributes();
        for (AbstractLayoutAttribute attrib : attributes) {
            String compName = elementType + ELEMENT_ATTRIBUTE_DELIM + attrib.getLayoutAttributeTypeName();
            FormItem fi = attrib.getFormItem(compName, styleFlc);
            fi.addActionListener(FormEvent.ONCHANGE);
            elAttribGui.put(attrib.getLayoutAttributeTypeName(), fi);
        }
        guiWrapper.put(elementType, elAttribGui);
    }
    styleFlc.contextPut("guiWrapper", guiWrapper);
}
Also used : AbstractLayoutElement(org.olat.course.config.ui.courselayout.elements.AbstractLayoutElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormItem(org.olat.core.gui.components.form.flexible.FormItem) AbstractLayoutAttribute(org.olat.course.config.ui.courselayout.attribs.AbstractLayoutAttribute) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 17 with FormItem

use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.

the class ColorSpecialHandler method getValue.

@Override
public String getValue() {
    FormLayoutContainer innerFLC = (FormLayoutContainer) getFormItem();
    Map<String, FormItem> items = innerFLC.getFormComponents();
    String ddValue = "";
    String inputValue = "";
    FormItem inputItem = null;
    for (Entry<String, FormItem> fiEntry : items.entrySet()) {
        String compName = fiEntry.getKey();
        FormItem fi = fiEntry.getValue();
        if (compName.endsWith("sel") && fi instanceof SingleSelection) {
            ddValue = ((SingleSelection) fi).isOneSelected() ? ((SingleSelection) fi).getSelectedKey() : "";
        }
        if (compName.endsWith("value") && fi instanceof TextElement) {
            inputItem = fi;
            inputValue = ((TextElement) fi).getValue();
        }
    }
    if (ddValue.equals("") && StringHelper.containsNonWhitespace(inputValue)) {
        // use input-value if valid
        Pattern pattern = Pattern.compile(HEX_PATTERN);
        Matcher matcher = pattern.matcher(inputValue);
        if (matcher.matches()) {
            hasError = false;
            return inputValue;
        } else {
            hasError = true;
            inputItem.setErrorKey("color.hex.error", null);
            return "";
        }
    }
    if (!ddValue.equals("") && StringHelper.containsNonWhitespace(inputValue)) {
        inputItem.setErrorKey("color.double.error", null);
    }
    return ddValue;
}
Also used : Pattern(java.util.regex.Pattern) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) Matcher(java.util.regex.Matcher) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 18 with FormItem

use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.

the class MemberSearchForm method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer leftContainer = FormLayoutContainer.createDefaultFormLayout("left_1", getTranslator());
    leftContainer.setRootForm(mainForm);
    formLayout.add(leftContainer);
    // user property
    login = uifactory.addTextElement("login", "search.login", 128, "", leftContainer);
    login.setDisplaySize(28);
    userPropertyHandlers = userManager.getUserPropertyHandlersFor(getClass().getCanonicalName(), false);
    propFormItems = new HashMap<String, FormItem>();
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, getClass().getCanonicalName(), false, leftContainer);
        fi.setTranslator(this.getTranslator());
        // DO NOT validate email field => see OLAT-3324, OO-155, OO-222
        if (userPropertyHandler instanceof EmailProperty && fi instanceof TextElement) {
            TextElement textElement = (TextElement) fi;
            textElement.setItemValidatorProvider(null);
        }
        if (fi instanceof TextElement) {
            ((TextElement) fi).setDisplaySize(28);
        }
        propFormItems.put(userPropertyHandler.getName(), fi);
    }
    // others
    FormLayoutContainer rightContainer = FormLayoutContainer.createDefaultFormLayout("right_1", getTranslator());
    rightContainer.setRootForm(mainForm);
    formLayout.add(rightContainer);
    // roles
    String[] roleValues = new String[roleKeys.length];
    for (int i = roleKeys.length; i-- > 0; ) {
        roleValues[i] = translate("search." + roleKeys[i]);
    }
    rolesEl = uifactory.addCheckboxesHorizontal("roles", "search.roles", rightContainer, roleKeys, roleValues);
    for (String roleKey : roleKeys) {
        rolesEl.select(roleKey, true);
    }
    String[] openValues = new String[originKeys.length];
    for (int i = originKeys.length; i-- > 0; ) {
        openValues[i] = translate("search." + originKeys[i]);
    }
    originEl = uifactory.addRadiosHorizontal("openBg", "search.origin", rightContainer, originKeys, openValues);
    originEl.select("all", true);
    FormLayoutContainer buttonLayout = FormLayoutContainer.createDefaultFormLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);
    searchButton = uifactory.addFormLink("search", buttonLayout, Link.BUTTON);
    searchButton.setCustomEnabledLinkCSS("btn btn-primary");
}
Also used : EmailProperty(org.olat.user.propertyhandlers.EmailProperty) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 19 with FormItem

use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.

the class UserSearchForm method validate.

private boolean validate() {
    boolean atLeastOne = false;
    if (login.isVisible()) {
        atLeastOne = StringHelper.containsNonWhitespace(login.getValue());
    }
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler != null) {
            FormItem ui = propFormItems.get(userPropertyHandler.getName());
            String uiValue = userPropertyHandler.getStringValue(ui);
            if (StringHelper.containsNonWhitespace(uiValue) && !uiValue.equals("-")) {
                atLeastOne = true;
            }
        }
    }
    if (!atLeastOne) {
        showWarning("error.search.form.notempty");
    }
    return atLeastOne;
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 20 with FormItem

use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.

the class MetadataBulkChangeController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (checkboxSwitch.contains(source)) {
        MultipleSelectionElement checkbox = (MultipleSelectionElement) source;
        FormItem item = (FormItem) checkbox.getUserObject();
        item.setVisible(checkbox.isAtLeastSelected(1));
        checkboxContainer.get(checkbox).setDirty(true);
    } else if (licenseEl == source) {
        updateLicenseVisibility();
        licenseWrapperCont.setDirty(true);
    } else {
        super.formInnerEvent(ureq, source, event);
    }
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) FormItem(org.olat.core.gui.components.form.flexible.FormItem)

Aggregations

FormItem (org.olat.core.gui.components.form.flexible.FormItem)142 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)62 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)34 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)30 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)22 Identity (org.olat.core.id.Identity)20 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)16 User (org.olat.core.id.User)16 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)14 UserManager (org.olat.user.UserManager)12 EmailProperty (org.olat.user.propertyhandlers.EmailProperty)12 HashSet (java.util.HashSet)10 Translator (org.olat.core.gui.translator.Translator)10 File (java.io.File)8 Map (java.util.Map)8 Component (org.olat.core.gui.components.Component)8 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)8 Date (java.util.Date)6 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)6