Search in sources :

Example 1 with SpecialAttributeFormItemHandler

use of org.olat.course.config.ui.courselayout.attribs.SpecialAttributeFormItemHandler in project openolat by klemens.

the class CourseLayoutGeneratorController method compileCustomConfigFromGuiWrapper.

private Map<String, Map<String, Object>> compileCustomConfigFromGuiWrapper() {
    // get config from wrapper-object
    elWithErrorExists = false;
    Map<String, Map<String, Object>> customConfig = new HashMap<String, Map<String, Object>>();
    for (Iterator<Entry<String, Map<String, FormItem>>> iterator = guiWrapper.entrySet().iterator(); iterator.hasNext(); ) {
        Entry<String, Map<String, FormItem>> type = iterator.next();
        String cIdent = type.getKey();
        Map<String, Object> elementConfig = new HashMap<String, Object>();
        Map<String, FormItem> element = type.getValue();
        for (Entry<String, FormItem> entry : element.entrySet()) {
            String attribName = entry.getKey();
            if (!attribName.equals(PreviewLA.IDENTIFIER)) {
                // exclude preview
                FormItem foItem = entry.getValue();
                String value = "";
                if (foItem instanceof SingleSelection) {
                    value = ((SingleSelection) foItem).isOneSelected() ? ((SingleSelection) foItem).getSelectedKey() : "";
                } else if (foItem.getUserObject() != null && foItem.getUserObject() instanceof SpecialAttributeFormItemHandler) {
                    // enclosed item
                    SpecialAttributeFormItemHandler specHandler = (SpecialAttributeFormItemHandler) foItem.getUserObject();
                    value = specHandler.getValue();
                    if (specHandler.hasError()) {
                        elWithErrorExists = true;
                    }
                } else {
                    throw new AssertException("implement a getValue for this FormItem to get back a processable value.");
                }
                elementConfig.put(attribName, value);
            }
        }
        customConfig.put(cIdent, elementConfig);
    }
    return customConfig;
}
Also used : AssertException(org.olat.core.logging.AssertException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormItem(org.olat.core.gui.components.form.flexible.FormItem) SpecialAttributeFormItemHandler(org.olat.course.config.ui.courselayout.attribs.SpecialAttributeFormItemHandler) Entry(java.util.Map.Entry) RepositoryEntry(org.olat.repository.RepositoryEntry) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with SpecialAttributeFormItemHandler

use of org.olat.course.config.ui.courselayout.attribs.SpecialAttributeFormItemHandler in project OpenOLAT by OpenOLAT.

the class CourseLayoutGeneratorController method compileCustomConfigFromGuiWrapper.

private Map<String, Map<String, Object>> compileCustomConfigFromGuiWrapper() {
    // get config from wrapper-object
    elWithErrorExists = false;
    Map<String, Map<String, Object>> customConfig = new HashMap<String, Map<String, Object>>();
    for (Iterator<Entry<String, Map<String, FormItem>>> iterator = guiWrapper.entrySet().iterator(); iterator.hasNext(); ) {
        Entry<String, Map<String, FormItem>> type = iterator.next();
        String cIdent = type.getKey();
        Map<String, Object> elementConfig = new HashMap<String, Object>();
        Map<String, FormItem> element = type.getValue();
        for (Entry<String, FormItem> entry : element.entrySet()) {
            String attribName = entry.getKey();
            if (!attribName.equals(PreviewLA.IDENTIFIER)) {
                // exclude preview
                FormItem foItem = entry.getValue();
                String value = "";
                if (foItem instanceof SingleSelection) {
                    value = ((SingleSelection) foItem).isOneSelected() ? ((SingleSelection) foItem).getSelectedKey() : "";
                } else if (foItem.getUserObject() != null && foItem.getUserObject() instanceof SpecialAttributeFormItemHandler) {
                    // enclosed item
                    SpecialAttributeFormItemHandler specHandler = (SpecialAttributeFormItemHandler) foItem.getUserObject();
                    value = specHandler.getValue();
                    if (specHandler.hasError()) {
                        elWithErrorExists = true;
                    }
                } else {
                    throw new AssertException("implement a getValue for this FormItem to get back a processable value.");
                }
                elementConfig.put(attribName, value);
            }
        }
        customConfig.put(cIdent, elementConfig);
    }
    return customConfig;
}
Also used : AssertException(org.olat.core.logging.AssertException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormItem(org.olat.core.gui.components.form.flexible.FormItem) SpecialAttributeFormItemHandler(org.olat.course.config.ui.courselayout.attribs.SpecialAttributeFormItemHandler) Entry(java.util.Map.Entry) RepositoryEntry(org.olat.repository.RepositoryEntry) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 AssertException (org.olat.core.logging.AssertException)2 SpecialAttributeFormItemHandler (org.olat.course.config.ui.courselayout.attribs.SpecialAttributeFormItemHandler)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2