Search in sources :

Example 6 with ItemValidatorProvider

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

the class Generic127CharTextPropertyHandler method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale, org.olat.core.id.User, java.lang.String, boolean, org.olat.core.gui.components.form.flexible.FormItemContainer)
 */
@Override
public FormItem addFormItem(Locale locale, final User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    org.olat.core.gui.components.form.flexible.elements.TextElement tElem = null;
    tElem = FormUIFactory.getInstance().addTextElement(getName(), i18nFormElementLabelKey(), 127, getInternalValue(user), formItemContainer);
    tElem.setItemValidatorProvider(new ItemValidatorProvider() {

        @Override
        public boolean isValidValue(String value, ValidationError validationError, Locale llocale) {
            return Generic127CharTextPropertyHandler.this.isValidValue(user, value, validationError, llocale);
        }
    });
    tElem.setLabel(i18nFormElementLabelKey(), null);
    UserManager um = UserManager.getInstance();
    if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
        tElem.setEnabled(false);
    }
    if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
        tElem.setMandatory(true);
    }
    return tElem;
}
Also used : Locale(java.util.Locale) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) UserManager(org.olat.user.UserManager) ValidationError(org.olat.core.gui.components.form.ValidationError) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement)

Example 7 with ItemValidatorProvider

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

the class LLEditForm method addNewFormLink.

/**
 * Add a new form link line to the list of link elements.
 *
 * @param link the link model object
 */
private void addNewFormLink(int index, final LLModel link) {
    // add link target
    TextElement lTarget = uifactory.addTextElement("target" + counter, null, -1, link.getTarget(), flc);
    lTarget.setPlaceholderKey("target.example", null);
    lTarget.clearError();
    lTarget.setEnabled(!link.isIntern());
    lTarget.setDisplaySize(40);
    lTarget.setMandatory(true);
    lTarget.setNotEmptyCheck("ll.table.target.error");
    lTarget.setItemValidatorProvider(new ItemValidatorProvider() {

        public boolean isValidValue(String value, ValidationError validationError, Locale locale) {
            try {
                if (!value.contains("://")) {
                    value = "http://".concat(value);
                }
                new URL(value);
            } catch (MalformedURLException e) {
                validationError.setErrorKey("ll.table.target.error.format");
                return false;
            }
            return true;
        }
    });
    lTarget.addActionListener(FormEvent.ONCHANGE);
    lTarget.setUserObject(link);
    lTargetInputList.add(index, lTarget);
    // add html target
    SingleSelection htmlTargetSelection = uifactory.addDropdownSingleselect("html_target" + counter, flc, new String[] { BLANK_KEY, SELF_KEY }, new String[] { translate("ll.table.html_target"), translate("ll.table.html_target.self") }, null);
    htmlTargetSelection.setUserObject(link);
    htmlTargetSelection.select((SELF_KEY.equals(link.getHtmlTarget()) ? SELF_KEY : BLANK_KEY), true);
    lHtmlTargetInputList.add(index, htmlTargetSelection);
    // add link description
    TextElement lDescription = uifactory.addTextElement("description" + counter, null, -1, link.getDescription(), flc);
    lDescription.clearError();
    lDescription.setDisplaySize(20);
    lDescription.setNotEmptyCheck("ll.table.description.error");
    lDescription.setMandatory(true);
    lDescription.setPlaceholderKey("ll.table.description", null);
    lDescription.setUserObject(link);
    lDescriptionInputList.add(index, lDescription);
    // add link comment
    TextElement lComment = uifactory.addTextAreaElement("comment" + counter, null, -1, 2, 50, true, link.getComment(), flc);
    lComment.setPlaceholderKey("ll.table.comment", null);
    lComment.setDisplaySize(20);
    lComment.setUserObject(link);
    lCommentInputList.add(index, lComment);
    // add link add action button
    FormLink addButton = new FormLinkImpl("add" + counter, "add" + counter, "", Link.BUTTON_SMALL + Link.NONTRANSLATED);
    addButton.setUserObject(link);
    addButton.setDomReplacementWrapperRequired(false);
    addButton.setIconLeftCSS("o_icon o_icon-lg o_icon-fw o_icon_add");
    flc.add(addButton);
    lAddButtonList.add(index, addButton);
    // add link deletion action button
    FormLink delButton = new FormLinkImpl("delete" + counter, "delete" + counter, "", Link.BUTTON_SMALL + Link.NONTRANSLATED);
    delButton.setUserObject(link);
    delButton.setDomReplacementWrapperRequired(false);
    delButton.setIconLeftCSS("o_icon o_icon-lg o_icon-fw o_icon_delete_item");
    flc.add(delButton);
    lDelButtonList.add(index, delButton);
    // custom media action button
    FormLink mediaButton = new FormLinkImpl("media" + counter, "media" + counter, "  ", Link.NONTRANSLATED);
    mediaButton.setIconLeftCSS("o_icon o_icon_browse o_icon-lg");
    mediaButton.setDomReplacementWrapperRequired(false);
    mediaButton.setUserObject(link);
    flc.add(mediaButton);
    lCustomMediaButtonList.add(index, mediaButton);
    // increase the counter to enable unique component names
    counter++;
}
Also used : Locale(java.util.Locale) MalformedURLException(java.net.MalformedURLException) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl) ValidationError(org.olat.core.gui.components.form.ValidationError) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) URL(java.net.URL)

Example 8 with ItemValidatorProvider

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

the class LinksPortletEditController 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) {
    title = uifactory.addTextElement("link.title", "link.title", 200, portletLink.getTitle(), formLayout);
    title.setMandatory(true);
    title.setNotEmptyCheck("link.title.not.empty");
    desc = uifactory.addRichTextElementForStringDataMinimalistic("link.desc", "link.desc", portletLink.getDescription(), 5, -1, formLayout, getWindowControl());
    linkURL = uifactory.addTextElement("link.url", "link.url", 1024, portletLink.getUrl(), formLayout);
    linkURL.setMandatory(true);
    linkURL.setNotEmptyCheck("link.url.not.empty");
    linkURL.setItemValidatorProvider(new ItemValidatorProvider() {

        @Override
        public boolean isValidValue(String value, final ValidationError validationError, final Locale locale) {
            try {
                if (!value.contains("://")) {
                    value = "http://".concat(value);
                }
                new URL(value);
            } catch (final MalformedURLException e) {
                validationError.setErrorKey("link.url.not.empty");
                return false;
            }
            return true;
        }
    });
    openPopup = uifactory.addCheckboxesHorizontal("link.open.new.window", "link.open.new.window", formLayout, new String[] { TARGET_BLANK }, new String[] { "" });
    if (portletLink.getTarget().equals(TARGET_BLANK)) {
        openPopup.selectAll();
    }
    // language
    Map<String, String> locdescs = I18nManager.getInstance().getEnabledLanguagesTranslated();
    Set<String> lkeys = locdescs.keySet();
    String[] languageKeys = new String[lkeys.size() + 1];
    String[] languageValues = new String[lkeys.size() + 1];
    languageKeys[0] = "*";
    languageValues[0] = translate("link.lang.all");
    int p = 1;
    for (Iterator<String> iter = lkeys.iterator(); iter.hasNext(); ) {
        String key = iter.next();
        languageKeys[p] = key;
        languageValues[p] = locdescs.get(key);
        p++;
    }
    language = uifactory.addDropdownSingleselect("link.language", formLayout, languageKeys, languageValues, null);
    String langKey = portletLink.getLanguage();
    if (Arrays.asList(languageKeys).contains(langKey)) {
        language.select(langKey, true);
    }
    uifactory.addFormSubmitButton("save", formLayout);
}
Also used : Locale(java.util.Locale) MalformedURLException(java.net.MalformedURLException) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) ValidationError(org.olat.core.gui.components.form.ValidationError) URL(java.net.URL)

Example 9 with ItemValidatorProvider

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

the class LLEditForm method addNewFormLink.

/**
 * Add a new form link line to the list of link elements.
 *
 * @param link the link model object
 */
private void addNewFormLink(int index, final LLModel link) {
    // add link target
    TextElement lTarget = uifactory.addTextElement("target" + counter, null, -1, link.getTarget(), flc);
    lTarget.setPlaceholderKey("target.example", null);
    lTarget.clearError();
    lTarget.setEnabled(!link.isIntern());
    lTarget.setDisplaySize(40);
    lTarget.setMandatory(true);
    lTarget.setNotEmptyCheck("ll.table.target.error");
    lTarget.setItemValidatorProvider(new ItemValidatorProvider() {

        public boolean isValidValue(String value, ValidationError validationError, Locale locale) {
            try {
                if (!value.contains("://")) {
                    value = "http://".concat(value);
                }
                new URL(value);
            } catch (MalformedURLException e) {
                validationError.setErrorKey("ll.table.target.error.format");
                return false;
            }
            return true;
        }
    });
    lTarget.addActionListener(FormEvent.ONCHANGE);
    lTarget.setUserObject(link);
    lTargetInputList.add(index, lTarget);
    // add html target
    SingleSelection htmlTargetSelection = uifactory.addDropdownSingleselect("html_target" + counter, flc, new String[] { BLANK_KEY, SELF_KEY }, new String[] { translate("ll.table.html_target"), translate("ll.table.html_target.self") }, null);
    htmlTargetSelection.setUserObject(link);
    htmlTargetSelection.select((SELF_KEY.equals(link.getHtmlTarget()) ? SELF_KEY : BLANK_KEY), true);
    lHtmlTargetInputList.add(index, htmlTargetSelection);
    // add link description
    TextElement lDescription = uifactory.addTextElement("description" + counter, null, -1, link.getDescription(), flc);
    lDescription.clearError();
    lDescription.setDisplaySize(20);
    lDescription.setNotEmptyCheck("ll.table.description.error");
    lDescription.setMandatory(true);
    lDescription.setPlaceholderKey("ll.table.description", null);
    lDescription.setUserObject(link);
    lDescriptionInputList.add(index, lDescription);
    // add link comment
    TextElement lComment = uifactory.addTextAreaElement("comment" + counter, null, -1, 2, 50, true, link.getComment(), flc);
    lComment.setPlaceholderKey("ll.table.comment", null);
    lComment.setDisplaySize(20);
    lComment.setUserObject(link);
    lCommentInputList.add(index, lComment);
    // add link add action button
    FormLink addButton = new FormLinkImpl("add" + counter, "add" + counter, "", Link.BUTTON_SMALL + Link.NONTRANSLATED);
    addButton.setUserObject(link);
    addButton.setDomReplacementWrapperRequired(false);
    addButton.setIconLeftCSS("o_icon o_icon-lg o_icon-fw o_icon_add");
    flc.add(addButton);
    lAddButtonList.add(index, addButton);
    // add link deletion action button
    FormLink delButton = new FormLinkImpl("delete" + counter, "delete" + counter, "", Link.BUTTON_SMALL + Link.NONTRANSLATED);
    delButton.setUserObject(link);
    delButton.setDomReplacementWrapperRequired(false);
    delButton.setIconLeftCSS("o_icon o_icon-lg o_icon-fw o_icon_delete_item");
    flc.add(delButton);
    lDelButtonList.add(index, delButton);
    // custom media action button
    FormLink mediaButton = new FormLinkImpl("media" + counter, "media" + counter, "  ", Link.NONTRANSLATED);
    mediaButton.setIconLeftCSS("o_icon o_icon_browse o_icon-lg");
    mediaButton.setDomReplacementWrapperRequired(false);
    mediaButton.setUserObject(link);
    flc.add(mediaButton);
    lCustomMediaButtonList.add(index, mediaButton);
    // increase the counter to enable unique component names
    counter++;
}
Also used : Locale(java.util.Locale) MalformedURLException(java.net.MalformedURLException) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl) ValidationError(org.olat.core.gui.components.form.ValidationError) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) URL(java.net.URL)

Example 10 with ItemValidatorProvider

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

the class EmailProperty method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale, org.olat.core.id.User, java.lang.String, boolean, org.olat.core.gui.components.form.flexible.FormItemContainer)
 */
@Override
public FormItem addFormItem(Locale locale, final User user, String usageIdentifyer, final boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    org.olat.core.gui.components.form.flexible.elements.TextElement tElem = null;
    tElem = (org.olat.core.gui.components.form.flexible.elements.TextElement) super.addFormItem(locale, user, usageIdentifyer, isAdministrativeUser, formItemContainer);
    // to validate the input a special isValidValue is used.
    if (usageIdentifyer.equals(UserBulkChangeStep00.class.getCanonicalName())) {
        tElem.setItemValidatorProvider(new ItemValidatorProvider() {

            @Override
            public boolean isValidValue(String value, ValidationError validationError, Locale locale2) {
                UserBulkChangeManager ubcMan = CoreSpringFactory.getImpl(UserBulkChangeManager.class);
                Context vcContext = new VelocityContext();
                if (user == null) {
                    vcContext = ubcMan.getDemoContext(locale2);
                } else // should be used if user-argument !=null --> move to right place
                {
                    Long userKey = user.getKey();
                    Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(userKey);
                    ubcMan.setUserContext(identity, vcContext);
                }
                value = value.replace("$", "$!");
                String evaluatedValue = ubcMan.evaluateValueWithUserContext(value, vcContext);
                return EmailProperty.this.isValidValue(user, evaluatedValue, validationError, locale2);
            }
        });
    }
    return tElem;
}
Also used : Locale(java.util.Locale) VelocityContext(org.apache.velocity.VelocityContext) Context(org.apache.velocity.context.Context) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) VelocityContext(org.apache.velocity.VelocityContext) UserBulkChangeStep00(org.olat.admin.user.bulkChange.UserBulkChangeStep00) UserBulkChangeManager(org.olat.admin.user.bulkChange.UserBulkChangeManager) ValidationError(org.olat.core.gui.components.form.ValidationError) Identity(org.olat.core.id.Identity)

Aggregations

Locale (java.util.Locale)10 ValidationError (org.olat.core.gui.components.form.ValidationError)10 ItemValidatorProvider (org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider)10 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)4 UserManager (org.olat.user.UserManager)4 Date (java.util.Date)2 VelocityContext (org.apache.velocity.VelocityContext)2 Context (org.apache.velocity.context.Context)2 UserBulkChangeManager (org.olat.admin.user.bulkChange.UserBulkChangeManager)2 UserBulkChangeStep00 (org.olat.admin.user.bulkChange.UserBulkChangeStep00)2 DateChooser (org.olat.core.gui.components.form.flexible.elements.DateChooser)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)2 Identity (org.olat.core.id.Identity)2