Search in sources :

Example 71 with TextElement

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

the class RegistrationForm2 method getFirstName.

protected String getFirstName() {
    FormItem fi = propFormItems.get("firstName");
    TextElement fn = (TextElement) fi;
    return fn.getValue().trim();
}
Also used : StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormItem(org.olat.core.gui.components.form.flexible.FormItem)

Example 72 with TextElement

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

the class RegistrationForm2 method getLastName.

protected String getLastName() {
    FormItem fi = propFormItems.get("lastName");
    TextElement fn = (TextElement) fi;
    return fn.getValue().trim();
}
Also used : StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormItem(org.olat.core.gui.components.form.flexible.FormItem)

Example 73 with TextElement

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

the class I18nConfigSubNewLangController 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) {
    // New language elements:
    // A title, displayed in fieldset
    setFormTitle("configuration.management.create.title");
    String[] args = new String[] { "<a href='http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt' target='_blank'><i class='o_icon o_icon_link_extern'> </i> ISO639</a>", "<a href='http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html' target='_blank'><i class='o_icon o_icon_link_extern'> </i> ISO3166</a>" };
    setFormDescription("configuration.management.create.description", args);
    // 
    // a) the language code
    newLanguage = uifactory.addTextElement("configuration.management.create.language", "configuration.management.create.language", 2, "", formLayout);
    newLanguage.setExampleKey("configuration.management.create.language.example", null);
    newLanguage.setMandatory(true);
    newLanguage.setRegexMatchCheck("[a-z]{2}", "configuration.management.create.language.error");
    newLanguage.setDisplaySize(2);
    newLanguage.addActionListener(FormEvent.ONCHANGE);
    // b) the country code
    newCountry = uifactory.addTextElement("configuration.management.create.country", "configuration.management.create.country", 2, "", formLayout);
    newCountry.setExampleKey("configuration.management.create.country.example", null);
    newCountry.setRegexMatchCheck("[A-Z]{0,2}", "configuration.management.create.country.error");
    newCountry.addActionListener(FormEvent.ONCHANGE);
    newCountry.setDisplaySize(2);
    // c) the variant, only available when country code is filled out
    newVariant = uifactory.addTextElement("configuration.management.create.variant", "configuration.management.create.variant", 50, "", formLayout);
    newVariant.setExampleKey("configuration.management.create.variant.example", null);
    newVariant.setRegexMatchCheck("[A-Za-z0-9_]*", "configuration.management.create.variant.error");
    newVariant.setDisplaySize(10);
    // Rule1: hide variant when country is empty
    Set<FormItem> hideItems = new HashSet<FormItem>();
    RulesFactory.createHideRule(newCountry, "", hideItems, formLayout);
    hideItems.add(newVariant);
    // Rule 2: show variant when country is not empty
    FormItemDependencyRule showRule = new FormItemDependencyRuleImpl(newCountry, ".{2}", hideItems, FormItemDependencyRuleImpl.MAKE_VISIBLE) {

        @Override
        protected boolean doesTrigger() {
            TextElement te = (TextElement) this.triggerElement;
            String val = te.getValue();
            // 
            if (val == null && triggerVal == null) {
                // triggerVal and val are NULL -> true
                return true;
            } else if (val != null) {
                // val can be compared
                String stringTriggerValString = (String) triggerVal;
                boolean matches = val.matches(stringTriggerValString);
                return matches;
            } else {
                // triggerVal is null but val is not null -> false
                return false;
            }
        }
    };
    formLayout.addDependencyRule(showRule);
    // 
    // Language name and translator data
    newTranslatedInEnglish = uifactory.addTextElement("configuration.management.create.inEnglish", "configuration.management.create.inEnglish", 255, "", formLayout);
    newTranslatedInEnglish.setExampleKey("configuration.management.create.inEnglish.example", null);
    newTranslatedInEnglish.setMandatory(true);
    newTranslatedInEnglish.setNotEmptyCheck("configuration.management.create.inEnglish.error");
    newTranslatedInLanguage = uifactory.addTextElement("configuration.management.create.inYourLanguage", "configuration.management.create.inYourLanguage", 255, "", formLayout);
    newTranslatedInLanguage.setExampleKey("configuration.management.create.inYourLanguage.example", null);
    newTranslator = uifactory.addTextElement("configuration.management.create.translator", "configuration.management.create.translator", 255, "", formLayout);
    newTranslator.setExampleKey("configuration.management.create.translator.example", null);
    // Add warn message
    String warnPage = Util.getPackageVelocityRoot(this.getClass()) + "/i18nConfigurationNewWarnMessage.html";
    FormLayoutContainer logoutWarnMessage = FormLayoutContainer.createCustomFormLayout("logoutWarnMessage", getTranslator(), warnPage);
    formLayout.add(logoutWarnMessage);
    // Add cancel and submit in button group layout
    FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
    formLayout.add(buttonGroupLayout);
    cancelButton = uifactory.addFormLink("cancel", buttonGroupLayout, Link.BUTTON);
    uifactory.addFormSubmitButton("configuration.management.create", buttonGroupLayout);
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormItemDependencyRule(org.olat.core.gui.components.form.flexible.FormItemDependencyRule) FormItemDependencyRuleImpl(org.olat.core.gui.components.form.flexible.impl.rules.FormItemDependencyRuleImpl) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) HashSet(java.util.HashSet)

Example 74 with TextElement

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

the class SingleKeyTranslatorController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Map<Locale, Locale> allOverlays = i18nModule.getOverlayLocales();
    Collection<String> enabledKeys = i18nModule.getEnabledLanguageKeys();
    bundles = new ArrayList<>();
    for (String key : enabledKeys) {
        Locale loc = i18nMng.getLocaleOrNull(key);
        if (loc != null)
            bundles.add(new I18nRowBundle(key, allOverlays.get(loc), loc));
    }
    // build the form
    textElements = new HashMap<>();
    for (I18nRowBundle i18nRowBundle : bundles) {
        uifactory.addStaticTextElement(LBL_NAME_PREFIX + i18nRowBundle.getLanguageKey(), null, i18nRowBundle.getKeyTranslator().getLocale().getDisplayLanguage(getLocale()), formLayout);
        String value = "";
        if (i18nRowBundle.hasTranslationForValue(i18nItemKeys[0])) {
            value = i18nRowBundle.getKeyTranslator().translate(i18nItemKeys[0]);
        }
        TextElement te = uifactory.addTextElement(TXT_NAME_PREFIX + i18nRowBundle.getLanguageKey(), null, 255, value, formLayout);
        te.setMandatory(true);
        te.setDisplaySize(60);
        textElements.put(i18nRowBundle.getLanguageKey(), te);
    }
    FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("ok_cancel", getTranslator());
    buttonLayout.setRootForm(mainForm);
    uifactory.addFormSubmitButton("ok", buttonLayout);
    uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
    formLayout.add(buttonLayout);
}
Also used : Locale(java.util.Locale) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 75 with TextElement

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

the class AttributeEasyRowAdderController method addRowAt.

/**
 * Internal method to add a new row at the given position
 *
 * @param i
 */
private void addRowAt(final int rowPos) {
    // 1) Make room for the new row if the row is inserted between existing
    // rows. Increment the row id in the user object of the form elements and
    // move them in the form element arrays
    final Map<String, FormItem> formComponents = flc.getFormComponents();
    for (int move = rowPos + 1; move <= columnAttribute.size(); move++) {
        FormItem oldPos = formComponents.get(columnAttribute.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = formComponents.get(columnOperator.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = formComponents.get(columnValueText.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = formComponents.get(columnValueSelection.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = formComponents.get(columnAddRow.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
        oldPos = formComponents.get(columnRemoveRow.get(move - 1));
        oldPos.setUserObject(Integer.valueOf(move));
    }
    // 2) create the new row
    // get gui translated shib attributes - fallback is to use the key also as value
    final String[] guiTranslatedAttKeys = new String[attrKeys.length];
    for (int j = 0; j < attrKeys.length; j++) {
        final String key = attrKeys[j];
        // OLAT-5089: use translate(String key, String[] args, boolean fallBackToDefaultLocale) version
        // of Translator because that's the only one not
        String translated = getTranslator().translate(key, null, Level.OFF);
        if (translated.indexOf(Translator.NO_TRANSLATION_ERROR_PREFIX) == 0) {
            final Translator translator = UserManager.getInstance().getPropertyHandlerTranslator(getTranslator());
            final String prefix = "form.name.";
            // OLAT-5089: use translate(String key, String[] args, boolean fallBackToDefaultLocale) version
            // of Translator because that's the only one not
            translated = translator.translate(prefix + key, null, Level.OFF);
            if (translated.indexOf(Translator.NO_TRANSLATION_ERROR_PREFIX) == 0) {
                // could not translate this key, use key for non-translated values
                guiTranslatedAttKeys[j] = key;
            } else {
                guiTranslatedAttKeys[j] = translated;
            }
        } else {
            guiTranslatedAttKeys[j] = translated;
        }
    }
    // sort after the values
    ArrayHelper.sort(attrKeys, guiTranslatedAttKeys, false, true, true);
    // use this sorted keys-values
    final SingleSelection attribute = uifactory.addDropdownSingleselect(PRE_ATTRIBUTE + rowCreationCounter, null, flc, attrKeys, guiTranslatedAttKeys, null);
    attribute.setUserObject(Integer.valueOf(rowPos));
    attribute.addActionListener(FormEvent.ONCHANGE);
    columnAttribute.add(rowPos, attribute.getName());
    // 2b) Operator selector
    final String[] values = OperatorManager.getRegisteredAndAlreadyTranslatedOperatorLabels(getLocale(), operatorKeys);
    final FormItem operator = uifactory.addDropdownSingleselect(PRE_OPERATOR + rowCreationCounter, null, flc, operatorKeys, values, null);
    operator.setUserObject(Integer.valueOf(rowPos));
    columnOperator.add(rowPos, operator.getName());
    // 2c) Attribute value - can be either a text input field or a selection
    // drop down box - create both and hide the selection box
    // 
    final TextElement valuetxt = uifactory.addTextElement(PRE_VALUE_TEXT + rowCreationCounter, null, -1, null, flc);
    valuetxt.setDisplaySize(25);
    valuetxt.setNotEmptyCheck("form.easy.error.attribute");
    valuetxt.setUserObject(Integer.valueOf(rowPos));
    columnValueText.add(rowPos, valuetxt.getName());
    // now the selection box
    final FormItem iselect = uifactory.addDropdownSingleselect(PRE_VALUE_SELECTION + rowCreationCounter, null, flc, new String[0], new String[0], null);
    iselect.setUserObject(Integer.valueOf(rowPos));
    iselect.setVisible(false);
    columnValueSelection.add(rowPos, iselect.getName());
    // 3) Init values for this row, assume selection of attribute at position 0
    if (ArrayUtils.contains(attrKeys, preselectedAttribute)) {
        attribute.select(preselectedAttribute, true);
        updateValueElementForAttribute(attribute.getKey(ArrayUtils.indexOf(attrKeys, preselectedAttribute)), rowPos, preselectedAttributeValue);
    } else {
        updateValueElementForAttribute(attribute.getKey(0), rowPos, null);
    }
    // 4) Add the 'add' and 'remove' buttons
    final FormLinkImpl addL = new FormLinkImpl("add_" + rowCreationCounter, "add." + rowPos, "+", Link.BUTTON_SMALL + Link.NONTRANSLATED);
    addL.setUserObject(Integer.valueOf(rowPos));
    flc.add(addL);
    columnAddRow.add(rowPos, addL.getName());
    // 
    final FormLinkImpl removeL = new FormLinkImpl("remove_" + rowCreationCounter, "remove." + rowPos, "-", Link.BUTTON_SMALL + Link.NONTRANSLATED);
    removeL.setUserObject(Integer.valueOf(rowPos));
    flc.add(removeL);
    columnRemoveRow.add(rowPos, removeL.getName());
    // new row created, increment counter for unique form element id's
    rowCreationCounter++;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) AttributeTranslator(org.olat.shibboleth.util.AttributeTranslator) Translator(org.olat.core.gui.translator.Translator) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)

Aggregations

TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)146 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)40 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)36 FormItem (org.olat.core.gui.components.form.flexible.FormItem)34 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)30 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)26 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)24 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)18 ArrayList (java.util.ArrayList)16 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)16 Identity (org.olat.core.id.Identity)12 HashMap (java.util.HashMap)8 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)8 EmailProperty (org.olat.user.propertyhandlers.EmailProperty)8 Date (java.util.Date)6 DateChooser (org.olat.core.gui.components.form.flexible.elements.DateChooser)6 StaticTextElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.StaticTextElementImpl)6 TextElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.TextElementImpl)6 RichTextElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextElementImpl)6 File (java.io.File)4