Search in sources :

Example 81 with SingleSelection

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

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 82 with SingleSelection

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

the class LicenseAdminConfigController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (enabledEl == source) {
        doEnableHandlers();
    } else if (addLicenseTypeButton == source) {
        doAddLicenseType(ureq);
    } else if (tableEl == source) {
        if (event instanceof SelectionEvent) {
            SelectionEvent se = (SelectionEvent) event;
            String cmd = se.getCommand();
            LicenseTypeRow licenseTypeRow = dataModel.getObject(se.getIndex());
            if (CMD_UP.equals(cmd)) {
                doUp(se.getIndex());
            } else if (CMD_DOWN.equals(cmd)) {
                doDown(se.getIndex());
            } else if (CMD_TRANSLATE.equals(cmd)) {
                doOpenTranslator(ureq, licenseTypeRow.getLicenseType());
            } else if (CMD_EDIT.equals(cmd)) {
                doEditLicenseType(ureq, licenseTypeRow.getLicenseType());
            }
        }
    } else if (source instanceof MultipleSelectionElement) {
        MultipleSelectionElement multipleSelectionElement = (MultipleSelectionElement) source;
        doActivateLicenseType(multipleSelectionElement);
    } else if (source instanceof SingleSelection) {
        SingleSelection singleSelection = (SingleSelection) source;
        String name = singleSelection.getName();
        if (name.startsWith(DEFAULT_LICENSE_TYPE_PREFIX)) {
            doSetDefaultLicenceType(source, singleSelection);
        } else if (name.startsWith(LICENSOR_CREATOR_TYPE_PREFIX)) {
            doSetLicensorCreator(source, singleSelection);
        }
    } else if (source instanceof FormLink) {
        Object userObject = source.getUserObject();
        if (userObject instanceof LicenseHandler) {
            LicenseHandler handler = (LicenseHandler) userObject;
            doEditLicensorConstant(ureq, handler);
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) LicenseHandler(org.olat.core.commons.services.license.LicenseHandler) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 83 with SingleSelection

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

the class LicenseAdminConfigController method reloadDefaultLicenseTypeEl.

private void reloadDefaultLicenseTypeEl(LicenseHandler handler) {
    SingleSelection defaultLicenseTypeEl = defaultLicenseTypeEls.get(handler.getType());
    if (defaultLicenseTypeEl != null) {
        List<LicenseType> activatedLicenseTypes = licenseService.loadActiveLicenseTypes(handler);
        Collections.sort(activatedLicenseTypes);
        String[] licenseTypeKeys = getLicenseTypeKeys(activatedLicenseTypes);
        String[] licenseTypeValues = getLicenseTypeValues(activatedLicenseTypes);
        defaultLicenseTypeEl.setKeysAndValues(licenseTypeKeys, licenseTypeValues, null);
        String defaultLicenseTypeKey = licenseModule.getDefaultLicenseTypeKey(handler);
        if (Arrays.asList(licenseTypeKeys).contains(defaultLicenseTypeKey)) {
            defaultLicenseTypeEl.select(defaultLicenseTypeKey, true);
        }
    }
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 84 with SingleSelection

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

the class FormUIFactory method addRadiosHorizontal.

/**
 * Add horizontal aligned radio buttons. <br>
 *
 * @param name
 * @param i18nLabel
 * @param formLayout
 * @param theKeys
 * @param theValues
 * @return
 */
public SingleSelection addRadiosHorizontal(final String name, final String i18nLabel, FormItemContainer formLayout, final String[] theKeys, final String[] theValues) {
    SingleSelection ss = new SingleSelectionImpl(name, name, SingleSelection.Layout.horizontal);
    ss.setKeysAndValues(theKeys, theValues, null);
    setLabelIfNotNull(i18nLabel, ss);
    formLayout.add(ss);
    return ss;
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) SingleSelectionImpl(org.olat.core.gui.components.form.flexible.impl.elements.SingleSelectionImpl)

Example 85 with SingleSelection

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

the class AttributeEasyRowAdderController method setAttributeConditions.

/**
 * Method to initialize this form with the given extended conditions
 *
 * @param cond
 */
public void setAttributeConditions(final List<ExtendedCondition> cond) {
    if (getRowCount() > 1) {
        throw new AssertException("more than one row found, don't know what do do");
    }
    if (!isinit) {
        throw new AssertException("must call init() before calling setAttributeConditions() !");
    }
    // use default initialized rows when no conditions have to be set
    if (cond.size() == 0) {
        return;
    }
    // remove default row from init process to make process of generating the
    // existing configuration easier
    removeRowAt(0);
    for (final Iterator<ExtendedCondition> iterator = cond.iterator(); iterator.hasNext(); ) {
        final ExtendedCondition extendedCondition = iterator.next();
        final int row = getRowCount();
        // now count is always one more than the row position, thus the next position to add a row
        // is the same as the current row count
        addRowAt(row);
        // set value in attribute selection
        SingleSelection ssi = (SingleSelection) flc.getFormComponent(columnAttribute.get(row));
        ssi.select(extendedCondition.getAttribute(), true);
        // set value in operator selection
        ssi = (SingleSelection) flc.getFormComponent(columnOperator.get(row));
        ssi.select(extendedCondition.getOperator().getOperatorKey(), true);
        // set the selectable values for this attribute if available and set the
        // preselected / predefined value.
        final String attribute = extendedCondition.getAttribute();
        updateValueElementForAttribute(attribute, row, extendedCondition.getValue());
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection)

Aggregations

SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)88 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)34 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)26 FormItem (org.olat.core.gui.components.form.flexible.FormItem)18 ArrayList (java.util.ArrayList)14 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)12 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)12 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)12 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)10 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)8 CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)8 File (java.io.File)6 Map (java.util.Map)6 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)6 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)6 SliderWrapper (org.olat.modules.forms.ui.model.SliderWrapper)6 UserManager (org.olat.user.UserManager)6 HashMap (java.util.HashMap)4 List (java.util.List)4 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)4