Search in sources :

Example 46 with SingleSelection

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

the class AttributeEasyRowAdderController method setAttributeConditions.

/**
 * Method to initialize this form with the given extended conditions
 *
 * @param cond
 */
public void setAttributeConditions(final List<ExtendedCondition> cond) {
    if (getRowCount() > 1) {
        throw new AssertException("more than one row found, don't know what do do");
    }
    if (!isinit) {
        throw new AssertException("must call init() before calling setAttributeConditions() !");
    }
    // use default initialized rows when no conditions have to be set
    if (cond.size() == 0) {
        return;
    }
    // remove default row from init process to make process of generating the
    // existing configuration easier
    removeRowAt(0);
    for (final Iterator<ExtendedCondition> iterator = cond.iterator(); iterator.hasNext(); ) {
        final ExtendedCondition extendedCondition = iterator.next();
        final int row = getRowCount();
        // now count is always one more than the row position, thus the next position to add a row
        // is the same as the current row count
        addRowAt(row);
        // set value in attribute selection
        SingleSelection ssi = (SingleSelection) flc.getFormComponent(columnAttribute.get(row));
        ssi.select(extendedCondition.getAttribute(), true);
        // set value in operator selection
        ssi = (SingleSelection) flc.getFormComponent(columnOperator.get(row));
        ssi.select(extendedCondition.getOperator().getOperatorKey(), true);
        // set the selectable values for this attribute if available and set the
        // preselected / predefined value.
        final String attribute = extendedCondition.getAttribute();
        updateValueElementForAttribute(attribute, row, extendedCondition.getValue());
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection)

Example 47 with SingleSelection

use of org.olat.core.gui.components.form.flexible.elements.SingleSelection 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 48 with SingleSelection

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

the class AttributeEasyRowAdderController method updateValueElementForAttribute.

/**
 * Internal method to update a row's value element. This can be a text input box or a selection drop down depending on the shibboleth module configuration and the selected attribute. The method
 * will set the given value as the users selected / inputed value
 *
 * @param attribute The attribute key. Must not be NULL
 * @param row the row ID
 * @param value The value that should be selected / used in the text input field. Can be NULL.
 */
private void updateValueElementForAttribute(final String attribute, final int row, final String value) {
    String[] selectableKeys = getSelectableKeys(attribute);
    // Get the value text input and selection drop down form elements for this
    // row. Don't use the element name since there we have the global row
    // counter in the name and _not_ the current row id!
    final SingleSelection iselect = (SingleSelection) flc.getFormComponent(columnValueSelection.get(row));
    final TextElement tei = (TextElement) flc.getFormComponent(columnValueText.get(row));
    if (selectableKeys.length > 0) {
        attributeAsSelectBox(attribute, value, selectableKeys, iselect, tei);
    } else {
        attributeAsTextField(value, iselect, tei);
    }
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection)

Example 49 with SingleSelection

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

the class AttributeEasyRowAdderController method formInnerEvent.

/**
 * @see org.olat.core.gui.components.form.flexible.FormDefaultController#formInnerEvent(org.olat.core.gui.components.form.flexible.FormItem, org.olat.core.gui.components.form.flexible.FormEvent)
 */
@Override
protected void formInnerEvent(final UserRequest ureq, final FormItem source, final FormEvent event) {
    if (isinit) {
        final String compName = source.getName();
        if (columnAddRow.contains(compName)) {
            // add link clicked
            final int clickPos = ((Integer) source.getUserObject()).intValue();
            addRowAt(clickPos + 1);
        } else if (columnRemoveRow.contains(compName)) {
            // remove link clicked
            final int clickPos = ((Integer) source.getUserObject()).intValue();
            removeRowAt(clickPos);
        }
        if (compName.startsWith(PRE_ATTRIBUTE)) {
            // one of the attribute selection drop boxes has been clicked
            final SingleSelection s1 = (SingleSelection) source;
            String attr;
            if (s1.isOneSelected()) {
                attr = s1.getSelectedKey();
            } else {
                // Special case: two new rows, modify the attribute on the second one
                // without touching the first one -> nothing selected on the first row
                // In this case we use the first one which is the visible one.
                attr = s1.getKey(0);
            }
            // update the value form element depending on the selected attribute
            final int clickPos = ((Integer) s1.getUserObject()).intValue();
            updateValueElementForAttribute(attr, clickPos, null);
        }
    }
    // update whole container to reflect changes.
    this.flc.setDirty(true);
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection)

Example 50 with SingleSelection

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

the class AttributeEasyRowAdderController method getAttributeConditions.

/**
 * Method to get a list of extended conditions represented in this form
 *
 * @return
 */
public List<ExtendedCondition> getAttributeConditions() {
    final List<ExtendedCondition> le = new ArrayList<ExtendedCondition>();
    for (final Iterator<String> iterator = columnAttribute.iterator(); iterator.hasNext(); ) {
        final String aname = iterator.next();
        final String row = aname.replace(PRE_ATTRIBUTE, "");
        final SingleSelection attribute = (SingleSelection) flc.getFormComponent(PRE_ATTRIBUTE + row);
        final String condName = attribute.getSelectedKey();
        final SingleSelection operator = (SingleSelection) flc.getFormComponent(PRE_OPERATOR + row);
        final String condOperator = operator.getSelectedKey();
        String condValue = "";
        final SingleSelection valuessi = (SingleSelection) flc.getFormComponent(PRE_VALUE_SELECTION + row);
        if (valuessi.isVisible()) {
            if (valuessi.isOneSelected()) {
                condValue = valuessi.getSelectedKey();
            } else {
                // user did not actively select one, maybe because the first one was already the one he wanted. Use this one
                condValue = valuessi.getKey(0);
            }
        } else {
            final TextElement valuetei = (TextElement) flc.getFormComponent(PRE_VALUE_TEXT + row);
            condValue = valuetei.getValue();
        }
        le.add(new ExtendedCondition(condName, condOperator, condValue));
    }
    return le;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) ArrayList(java.util.ArrayList)

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