Search in sources :

Example 26 with FormLinkImpl

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

the class UserInterestsElement method setRootForm.

@Override
public void setRootForm(Form rootForm) {
    String dispatchId = component.getDispatchID();
    editLink = new FormLinkImpl(dispatchId + "_searchButton", "editInterests", "edit", Link.BUTTON);
    editLink.setTranslator(getTranslator());
    editLink.setIconLeftCSS("o_icon o_icon_edit");
    super.setRootForm(rootForm);
}
Also used : FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)

Example 27 with FormLinkImpl

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

the class TranslationToolI18nItemListCrumbController method initForm.

/*
	 * (non-Javadoc)
	 * 
	 * @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) {
    // Add the translate all button
    allTranslateButtonTop = new FormLinkImpl("allTranslateButtonTop", "allTranslateButtonTop", "generic.translateAllButton", Link.BUTTON);
    formLayout.add(allTranslateButtonTop);
    allTranslateButtonBottom = new FormLinkImpl("allTranslateButtonBottom", "allTranslateButtonBottom", "generic.translateAllButton", Link.BUTTON);
    formLayout.add(allTranslateButtonBottom);
    // Add a translate button for each package
    String currentBundleName = null;
    int bundlesCount = 0;
    for (I18nItem item : i18nItems) {
        if (!item.getBundleName().equals(currentBundleName)) {
            currentBundleName = item.getBundleName();
            String linkName = "translateBundle_" + currentBundleName;
            String label = (customizingMode ? "generic.customize.translateButton" : "generic.translateButton");
            FormLink bundleTranslateButton = new FormLinkImpl(linkName, linkName, label, Link.BUTTON_SMALL);
            // use first item of bundle
            bundleTranslateButton.setUserObject(item);
            formLayout.add(bundleTranslateButton);
            bundlesCount++;
        }
    }
    // Add all the items to velocity
    this.flc.contextPut("i18nItems", i18nItems);
    this.flc.contextPut("bundlesCount", bundlesCount);
    this.flc.contextPut("keysCount", i18nItems.size());
    // Override text labels for customizing mode
    if (customizingMode) {
        allTranslateButtonTop.setI18nKey("generic.customize.translateAllButton");
        allTranslateButtonBottom.setI18nKey("generic.customize.translateAllButton");
    }
    this.flc.contextPut("customizingMode", Boolean.valueOf(customizingMode));
    this.flc.contextPut("customizingPrefix", (customizingMode ? "customize." : ""));
}
Also used : I18nItem(org.olat.core.util.i18n.I18nItem) FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 28 with FormLinkImpl

use of org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl 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)

Example 29 with FormLinkImpl

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

the class ConditionConfigEasyController method validateGroupFields.

/**
 * @param retVal
 * @return
 */
private boolean validateGroupFields() {
    boolean retVal = true;
    if (groupSwitch.getSelectedKeys().size() == 1) {
        List<Long> activeGroupSelection = null;
        List<Long> activeAreaSelection = null;
        groupChooseSubContainer.clearError();
        if (!isEmpty(easyGroupList)) {
            // check whether groups exist
            activeGroupSelection = getKeys(easyGroupList);
            Set<Long> missingGroups = new HashSet<Long>();
            List<BusinessGroupShort> existingGroups = businessGroupService.loadShortBusinessGroups(activeGroupSelection);
            a_a: for (Long activeGroupKey : activeGroupSelection) {
                for (BusinessGroupShort group : existingGroups) {
                    if (group.getKey().equals(activeGroupKey)) {
                        continue a_a;
                    }
                }
                missingGroups.add(activeGroupKey);
            }
            if (missingGroups.size() > 0) {
                retVal = false;
                String labelKey = missingGroups.size() == 1 ? "error.notfound.name" : "error.notfound.names";
                String csvMissGrps = toString(missingGroups);
                String[] params = new String[] { "-", csvMissGrps };
                // create error with link to fix it
                String vc_errorPage = velocity_root + "/erroritem.html";
                FormLayoutContainer errorGroupItemLayout = FormLayoutContainer.createCustomFormLayout("errorgroupitem", getTranslator(), vc_errorPage);
                groupChooseSubContainer.setErrorComponent(errorGroupItemLayout, this.flc);
                // FIXING LINK ONLY IF A DEFAULTCONTEXT EXISTS
                fixGroupError = new FormLinkImpl("error.fix", "create");
                // link
                fixGroupError.setCustomEnabledLinkCSS("btn btn-default");
                errorGroupItemLayout.add(fixGroupError);
                fixGroupError.setErrorKey(labelKey, params);
                fixGroupError.showError(true);
                fixGroupError.showLabel(false);
                // String[].lenght > 1 -> show bulkmode creation group
                if (missingGroups.size() > 1) {
                    fixGroupError.setUserObject(new String[] { csvMissGrps, "dummy" });
                } else {
                    fixGroupError.setUserObject(new String[] { csvMissGrps });
                }
                groupChooseSubContainer.showError(true);
            } else {
                // no more errors
                groupChooseSubContainer.clearError();
            }
        }
        areaChooseSubContainer.clearError();
        if (!isEmpty(easyAreaList)) {
            // check whether areas exist
            activeAreaSelection = getKeys(easyAreaList);
            List<Long> missingAreas = new ArrayList<Long>();
            List<BGArea> cnt = areaManager.loadAreas(activeAreaSelection);
            a_a: for (Long activeAreaKey : activeAreaSelection) {
                for (BGArea element : cnt) {
                    if (element.getKey().equals(activeAreaKey)) {
                        continue a_a;
                    }
                }
                missingAreas.add(activeAreaKey);
            }
            if (missingAreas.size() > 0) {
                retVal = false;
                String labelKey = missingAreas.size() == 1 ? "error.notfound.name" : "error.notfound.names";
                String csvMissAreas = toString(missingAreas);
                String[] params = new String[] { "-", csvMissAreas };
                // create error with link to fix it
                String vc_errorPage = velocity_root + "/erroritem.html";
                FormLayoutContainer errorAreaItemLayout = FormLayoutContainer.createCustomFormLayout("errorareaitem", getTranslator(), vc_errorPage);
                areaChooseSubContainer.setErrorComponent(errorAreaItemLayout, this.flc);
                // FXINGIN LINK ONLY IF DEFAULT CONTEXT EXISTS
                // erstellen
                fixAreaError = new FormLinkImpl("error.fix", "create");
                // link
                fixAreaError.setCustomEnabledLinkCSS("btn btn-default");
                errorAreaItemLayout.add(fixAreaError);
                fixAreaError.setErrorKey(labelKey, params);
                fixAreaError.showError(true);
                fixAreaError.showLabel(false);
                // String[].lenght > 1 -> show bulkmode creation group
                if (missingAreas.size() > 1) {
                    fixAreaError.setUserObject(new String[] { csvMissAreas, "dummy" });
                } else {
                    fixAreaError.setUserObject(new String[] { csvMissAreas });
                }
                areaChooseSubContainer.showError(true);
            } else {
                areaChooseSubContainer.clearError();
            }
        }
        boolean easyGroupOK = (!isEmpty(easyGroupList) && activeGroupSelection != null && !activeGroupSelection.isEmpty());
        boolean easyAreaOK = (!isEmpty(easyAreaList) && activeAreaSelection != null && !activeAreaSelection.isEmpty());
        if (easyGroupOK || easyAreaOK) {
            // clear general error
            groupSubContainer.clearError();
        } else {
            // error concerns both fields -> set it as switch error
            groupSubContainer.setErrorKey("form.easy.error.group", null);
            retVal = false;
        }
    }
    return retVal;
}
Also used : ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl) BGArea(org.olat.group.area.BGArea) BusinessGroupShort(org.olat.group.BusinessGroupShort) HashSet(java.util.HashSet)

Example 30 with FormLinkImpl

use of org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl 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)

Aggregations

FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)52 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)12 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)8 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 FormItem (org.olat.core.gui.components.form.flexible.FormItem)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 BusinessGroupShort (org.olat.group.BusinessGroupShort)4 BGArea (org.olat.group.area.BGArea)4 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Locale (java.util.Locale)2 TimeZone (java.util.TimeZone)2 ValidationError (org.olat.core.gui.components.form.ValidationError)2 DateChooser (org.olat.core.gui.components.form.flexible.elements.DateChooser)2 AutoCompleterImpl (org.olat.core.gui.components.form.flexible.impl.elements.AutoCompleterImpl)2 ItemValidatorProvider (org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider)2