Search in sources :

Example 1 with FormItemDependencyRuleImpl

use of org.olat.core.gui.components.form.flexible.impl.rules.FormItemDependencyRuleImpl 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 2 with FormItemDependencyRuleImpl

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

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)

Aggregations

HashSet (java.util.HashSet)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 FormItemDependencyRule (org.olat.core.gui.components.form.flexible.FormItemDependencyRule)2 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 FormItemDependencyRuleImpl (org.olat.core.gui.components.form.flexible.impl.rules.FormItemDependencyRuleImpl)2