Search in sources :

Example 76 with SingleSelection

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

the class EPStructureDetailsController 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(final FormItemContainer formLayout, final Controller listener, final UserRequest ureq) {
    if (formLayout.getFormComponent("struct.title") != null) {
        formLayout.remove("struct.title");
    }
    titleEl = uifactory.addTextElement("struct.title", "struct.title", 512, editStructure.getTitle(), formLayout);
    titleEl.setNotEmptyCheck("map.title.not.empty");
    titleEl.setMandatory(true);
    // choose representation mode (table or minimized artefact-view)
    if (formLayout.getFormComponent("view.mode") != null) {
        formLayout.remove("view.mode");
    }
    final String[] theKeys = new String[] { VIEWMODE_TABLE, VIEWMODE_MINI };
    final String[] theValues = new String[] { translate("view.mode." + VIEWMODE_TABLE), translate("view.mode." + VIEWMODE_MINI) };
    viewRadio = uifactory.addRadiosHorizontal("view.mode", formLayout, theKeys, theValues);
    final String artRepMode = editStructure.getArtefactRepresentationMode();
    if (artRepMode != null) {
        viewRadio.select(artRepMode, true);
    } else {
        viewRadio.select(VIEWMODE_MINI, true);
    }
    if (formLayout.getFormComponent("struct.description") != null) {
        formLayout.remove("struct.description");
    }
    descriptionEl = uifactory.addRichTextElementForStringDataMinimalistic("struct.description", "struct.description", editStructure.getDescription(), -1, -1, formLayout, getWindowControl());
    descriptionEl.setMaxLength(2047);
    descriptionEl.setNotLongerThanCheck(2047, "map.description.too.long");
    // hint for no edit options
    if (formLayout.getFormComponent("noEditInfo") != null) {
        formLayout.remove("noEditInfo");
    }
    noEditInfo = uifactory.addStaticTextElement("noEditInfo", "no.edit.info.label", translate("no.edit.info"), formLayout);
    noEditInfo.setVisible(false);
    if (formLayout.getFormComponent("collect.restriction") != null) {
        formLayout.remove("collect.restriction");
    }
    // show restrictions only for templates and on page/structure-level, as artefacts are not linkable on maps itself
    if (editStructure instanceof EPStructureElement && rootStructure instanceof EPStructuredMapTemplate && editStructure.getRoot() != null) {
        final FormLayoutContainer collectContainer = FormLayoutContainer.createCustomFormLayout("collect.restriction", getTranslator(), velocity_root + "/restrictions.html");
        collectContainer.setRootForm(mainForm);
        collectContainer.setLabel("collect.restriction", null);
        formLayout.add(collectContainer);
        final String[] restrictionKeys = new String[] { "", RestrictionsConstants.MAX, RestrictionsConstants.EQUAL, RestrictionsConstants.MIN };
        final String[] restrictionValues = new String[restrictionKeys.length];
        restrictionValues[0] = "";
        for (int i = 1; i < restrictionKeys.length; i++) {
            restrictionValues[i] = translate("restriction." + restrictionKeys[i]);
        }
        // allow only to use enabled handlers
        final List<EPArtefactHandler<?>> handlers = portfolioModule.getArtefactHandlers();
        final String[] artefactKeys = new String[handlers.size() + 1];
        final String[] artefactValues = new String[artefactKeys.length];
        artefactValues[0] = artefactKeys[0] = "";
        for (int i = 0; i < handlers.size(); i++) {
            final EPArtefactHandler<?> handler = handlers.get(i);
            artefactKeys[i + 1] = handler.getType();
            final String handlerClass = PortfolioFilterController.HANDLER_PREFIX + handler.getClass().getSimpleName() + PortfolioFilterController.HANDLER_TITLE_SUFFIX;
            artefactValues[i + 1] = handler.getHandlerTranslator(getTranslator()).translate(handlerClass);
        }
        if (collectRestrictions.isEmpty()) {
            collectRestrictions.add(new CollectRestriction());
        }
        restrictionElements = new ArrayList<SingleSelection>();
        restrictToArtefactElements = new ArrayList<SingleSelection>();
        amountElements = new ArrayList<TextElement>();
        errorElements = new ArrayList<StaticTextElement>();
        final List<String> counts = new ArrayList<String>();
        for (final CollectRestriction restriction : collectRestrictions) {
            final int count = restrictionElements.size();
            final SingleSelection restrictionElement = uifactory.addDropdownSingleselect("collect.restriction.restriction." + count, "", collectContainer, restrictionKeys, restrictionValues, null);
            restrictionElement.setDomReplacementWrapperRequired(false);
            restrictionElement.setMandatory(true);
            if (restriction != null && StringHelper.containsNonWhitespace(restriction.getRestriction())) {
                restrictionElement.select(restriction.getRestriction(), true);
            }
            restrictionElement.setUserObject(restriction);
            final SingleSelection restrictToArtefactElement = uifactory.addDropdownSingleselect("collect.restriction.artefacts." + count, "", collectContainer, artefactKeys, artefactValues, null);
            restrictToArtefactElement.setDomReplacementWrapperRequired(false);
            restrictToArtefactElement.setMandatory(true);
            if (restriction != null && StringHelper.containsNonWhitespace(restriction.getArtefactType())) {
                restrictToArtefactElement.select(restriction.getArtefactType(), true);
            }
            String amountStr = "";
            if (restriction != null && restriction.getAmount() > 0) {
                amountStr = Integer.toString(restriction.getAmount());
            }
            final TextElement amountElement = uifactory.addTextElement("collect.restriction.amount." + count, null, 2, amountStr, collectContainer);
            amountElement.setDomReplacementWrapperRequired(false);
            amountElement.setDisplaySize(3);
            StaticTextElement errorElement = uifactory.addStaticTextElement("collect.restriction.error." + count, null, "", collectContainer);
            errorElement.setVisible(false);
            restrictionElements.add(restrictionElement);
            restrictToArtefactElements.add(restrictToArtefactElement);
            amountElements.add(amountElement);
            errorElements.add(errorElement);
            final FormLink addLink = uifactory.addFormLink("collect.restriction.add." + count, "collect.restriction.add", "collect.restriction.add", collectContainer, Link.BUTTON_SMALL);
            addLink.setDomReplacementWrapperRequired(false);
            addLink.setUserObject(restriction);
            final FormLink delLink = uifactory.addFormLink("collect.restriction.del." + count, "collect.restriction.delete", "collect.restriction.delete", collectContainer, Link.BUTTON_SMALL);
            delLink.setDomReplacementWrapperRequired(false);
            delLink.setUserObject(restriction);
            counts.add(Integer.toString(count));
        }
        collectContainer.contextPut("counts", counts);
    }
    if (formLayout.getFormComponent("save") != null) {
        formLayout.remove("save");
    }
    uifactory.addFormSubmitButton("save", formLayout);
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) EPArtefactHandler(org.olat.portfolio.EPArtefactHandler) RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement)

Example 77 with SingleSelection

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

the class LandingPagesAdminController method initRuleWrapper.

private RuleWrapper initRuleWrapper(int pos, Rule rule, FormItemContainer formLayout) {
    int i = counter.incrementAndGet();
    RuleWrapper wrapper = new RuleWrapper(rule);
    wrapper.setPosition(pos);
    SingleSelection roleEl = uifactory.addDropdownSingleselect("role-" + i, null, formLayout, roleKeys, roleValues, null);
    String role = rule.getRole();
    for (int j = roleKeys.length; j-- > 0; ) {
        if (roleKeys[j].equals(role)) {
            roleEl.select(roleKeys[j], true);
        }
    }
    wrapper.setRoleEl(roleEl);
    SingleSelection attrNameEl = uifactory.addDropdownSingleselect("attr-key-" + i, null, formLayout, attrKeys, attrValues, null);
    String userAttributeKey = rule.getUserAttributeKey();
    for (int j = attrKeys.length; j-- > 0; ) {
        if (attrKeys[j].equals(userAttributeKey)) {
            attrNameEl.select(attrKeys[j], true);
        }
    }
    wrapper.setAttrNameEl(attrNameEl);
    TextElement valEl = uifactory.addTextElement("attr-val-" + i, null, 256, "", formLayout);
    valEl.setValue(rule.getUserAttributeValue());
    wrapper.setAttrValueEl(valEl);
    TextElement landingPageEl = uifactory.addTextElement("l-page-" + i, null, 256, "", formLayout);
    landingPageEl.setValue(rule.getLandingPath());
    wrapper.setLandingPageEl(landingPageEl);
    formLayout.add(landingPageEl);
    FormLink chooser = uifactory.addFormLink("chooser-" + i, "chooser", RCols.landingPageChooser.i18nKey(), null, formLayout, Link.BUTTON);
    chooser.setIconRightCSS("o_icon o_icon_caret");
    chooser.setUserObject(wrapper);
    wrapper.setLandingPageChooser(chooser);
    return wrapper;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 78 with SingleSelection

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

the class SitesConfigurationController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source == tableEl) {
        if (event instanceof SelectionEvent) {
            SelectionEvent se = (SelectionEvent) event;
            if ("up".equals(se.getCommand())) {
                SiteDefRow row = model.getObject(se.getIndex());
                moveUp(row);
                doUpdateOrders();
                tableEl.getComponent().setDirty(true);
            } else if ("down".equals(se.getCommand())) {
                SiteDefRow row = model.getObject(se.getIndex());
                moveDown(row);
                doUpdateOrders();
                tableEl.getComponent().setDirty(true);
            }
        }
    } else if (source instanceof SingleSelection) {
        if (source.getName().startsWith("site.security.") && source.getUserObject() instanceof SiteDefRow) {
            SiteDefRow row = (SiteDefRow) source.getUserObject();
            String selectCallbackId = row.getSecurityCallbackEl().getSelectedKey();
            boolean needAlt = (securityCallbacks.containsKey(selectCallbackId) && securityCallbacks.get(selectCallbackId) instanceof SiteViewSecurityCallback);
            if (row.getAlternativeControllerEl().isVisible() != needAlt) {
                row.getAlternativeControllerEl().setVisible(needAlt);
                tableEl.reset();
            }
        }
        doSaveSettings();
    } else if (source instanceof MultipleSelectionElement || source instanceof SingleSelection) {
        doSaveSettings();
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : SiteViewSecurityCallback(org.olat.core.gui.control.navigation.SiteViewSecurityCallback) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)

Example 79 with SingleSelection

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

the class AbstractLayoutAttribute method getFormItem.

// as per default attaches a dropdown and selects what is given
public FormItem getFormItem(String compName, FormItemContainer formLayout) {
    FormUIFactory uifact = FormUIFactory.getInstance();
    SingleSelection fi = uifact.addDropdownSingleselect(compName, null, formLayout, availKeys, availValues, availCSS);
    if (attributeValue != null && Arrays.asList(availKeys).contains(attributeValue)) {
        fi.select(attributeValue, true);
        fi.showLabel(false);
    }
    return fi;
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormUIFactory(org.olat.core.gui.components.form.flexible.FormUIFactory)

Example 80 with SingleSelection

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

the class ColorLA method getFormItem.

/**
 * @see org.olat.course.config.ui.courselayout.attribs.AbstractLayoutAttribute#getFormItem(java.lang.String, org.olat.core.gui.components.form.flexible.FormItemContainer)
 * get a dropdown and an input field wrapped in a FormLayoutContainer
 */
@Override
public FormItem getFormItem(String compName, FormItemContainer formLayout) {
    FormUIFactory uifact = FormUIFactory.getInstance();
    FormLayoutContainer colorFLC = FormLayoutContainer.createVerticalFormLayout(compName, formLayout.getTranslator());
    formLayout.add(compName, colorFLC);
    FormItem dropDown = super.getFormItem(compName + "sel", formLayout);
    dropDown.addActionListener(FormEvent.ONCHANGE);
    colorFLC.add(dropDown);
    String inputValue = "";
    if (getAttributeValue() != null && !((SingleSelection) dropDown).isOneSelected()) {
        inputValue = getAttributeValue();
    }
    TextElement inputEl = uifact.addTextElement(compName + "value", null, 7, inputValue, colorFLC);
    inputEl.setDisplaySize(7);
    colorFLC.setUserObject(new ColorSpecialHandler(colorFLC));
    return colorFLC;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormUIFactory(org.olat.core.gui.components.form.flexible.FormUIFactory)

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