Search in sources :

Example 1 with AbstractLayoutElement

use of org.olat.course.config.ui.courselayout.elements.AbstractLayoutElement in project OpenOLAT by OpenOLAT.

the class CourseLayoutGeneratorController method prepareStyleEditor.

private void prepareStyleEditor(Map<String, Map<String, Object>> customConfig) {
    // keep config order
    guiWrapper = new LinkedHashMap<String, Map<String, FormItem>>();
    List<AbstractLayoutElement> allElements = customCMgr.getAllAvailableElements();
    List<AbstractLayoutAttribute> allAttribs = customCMgr.getAllAvailableAttributes();
    styleFlc.contextPut("allAttribs", allAttribs);
    // needed reference to get listener back.
    styleFlc.setUserObject(this);
    for (AbstractLayoutElement abstractLayoutElement : allElements) {
        String elementType = abstractLayoutElement.getLayoutElementTypeName();
        Map<String, Object> elConf = customConfig.get(elementType);
        AbstractLayoutElement concreteElmt = abstractLayoutElement.createInstance(elConf);
        HashMap<String, FormItem> elAttribGui = new HashMap<String, FormItem>();
        List<AbstractLayoutAttribute> attributes = concreteElmt.getAvailableAttributes();
        for (AbstractLayoutAttribute attrib : attributes) {
            String compName = elementType + ELEMENT_ATTRIBUTE_DELIM + attrib.getLayoutAttributeTypeName();
            FormItem fi = attrib.getFormItem(compName, styleFlc);
            fi.addActionListener(FormEvent.ONCHANGE);
            elAttribGui.put(attrib.getLayoutAttributeTypeName(), fi);
        }
        guiWrapper.put(elementType, elAttribGui);
    }
    styleFlc.contextPut("guiWrapper", guiWrapper);
}
Also used : AbstractLayoutElement(org.olat.course.config.ui.courselayout.elements.AbstractLayoutElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormItem(org.olat.core.gui.components.form.flexible.FormItem) AbstractLayoutAttribute(org.olat.course.config.ui.courselayout.attribs.AbstractLayoutAttribute) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with AbstractLayoutElement

use of org.olat.course.config.ui.courselayout.elements.AbstractLayoutElement in project openolat by klemens.

the class CourseLayoutGeneratorController method prepareStyleEditor.

private void prepareStyleEditor(Map<String, Map<String, Object>> customConfig) {
    // keep config order
    guiWrapper = new LinkedHashMap<String, Map<String, FormItem>>();
    List<AbstractLayoutElement> allElements = customCMgr.getAllAvailableElements();
    List<AbstractLayoutAttribute> allAttribs = customCMgr.getAllAvailableAttributes();
    styleFlc.contextPut("allAttribs", allAttribs);
    // needed reference to get listener back.
    styleFlc.setUserObject(this);
    for (AbstractLayoutElement abstractLayoutElement : allElements) {
        String elementType = abstractLayoutElement.getLayoutElementTypeName();
        Map<String, Object> elConf = customConfig.get(elementType);
        AbstractLayoutElement concreteElmt = abstractLayoutElement.createInstance(elConf);
        HashMap<String, FormItem> elAttribGui = new HashMap<String, FormItem>();
        List<AbstractLayoutAttribute> attributes = concreteElmt.getAvailableAttributes();
        for (AbstractLayoutAttribute attrib : attributes) {
            String compName = elementType + ELEMENT_ATTRIBUTE_DELIM + attrib.getLayoutAttributeTypeName();
            FormItem fi = attrib.getFormItem(compName, styleFlc);
            fi.addActionListener(FormEvent.ONCHANGE);
            elAttribGui.put(attrib.getLayoutAttributeTypeName(), fi);
        }
        guiWrapper.put(elementType, elAttribGui);
    }
    styleFlc.contextPut("guiWrapper", guiWrapper);
}
Also used : AbstractLayoutElement(org.olat.course.config.ui.courselayout.elements.AbstractLayoutElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormItem(org.olat.core.gui.components.form.flexible.FormItem) AbstractLayoutAttribute(org.olat.course.config.ui.courselayout.attribs.AbstractLayoutAttribute) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with AbstractLayoutElement

use of org.olat.course.config.ui.courselayout.elements.AbstractLayoutElement in project OpenOLAT by OpenOLAT.

the class CustomConfigManager method saveCustomConfigAndCompileCSS.

/**
 * save the custom css configuration in a reprocessable format (map with inner map)
 * also generates the two needed css-files (main / iframe)
 * @param customConfig
 * @param courseEnvironment
 */
public void saveCustomConfigAndCompileCSS(Map<String, Map<String, Object>> customConfig, CourseEnvironment courseEnvironment) {
    VFSContainer themeBase = null;
    VFSContainer base = null;
    base = (VFSContainer) courseEnvironment.getCourseBaseContainer().resolve(CourseLayoutHelper.LAYOUT_COURSE_SUBFOLDER);
    if (base == null) {
        base = courseEnvironment.getCourseBaseContainer().createChildContainer(CourseLayoutHelper.LAYOUT_COURSE_SUBFOLDER);
    }
    themeBase = (VFSContainer) base.resolve("/" + CourseLayoutHelper.CONFIG_KEY_CUSTOM);
    if (themeBase == null) {
        themeBase = base.createChildContainer(CourseLayoutHelper.CONFIG_KEY_CUSTOM);
    }
    VFSLeaf configTarget = (VFSLeaf) themeBase.resolve(CUSTOM_CONFIG_XML);
    if (configTarget == null) {
        configTarget = themeBase.createChildLeaf(CUSTOM_CONFIG_XML);
    }
    XStream xStream = XStreamHelper.createXStreamInstance();
    xStream.toXML(customConfig, configTarget.getOutputStream(false));
    // compile the css-files
    StringBuffer sbMain = new StringBuffer();
    StringBuffer sbIFrame = new StringBuffer();
    for (Entry<String, Map<String, Object>> iterator : customConfig.entrySet()) {
        String type = iterator.getKey();
        Map<String, Object> elementConfig = iterator.getValue();
        AbstractLayoutElement configuredLayEl = createLayoutElementByType(type, elementConfig);
        sbIFrame.append(configuredLayEl.getCSSForIFrame());
        sbMain.append(configuredLayEl.getCSSForMain());
    }
    // attach line for logo, if there is any to cssForMain:
    appendLogoPart(sbMain, themeBase);
    VFSLeaf mainFile = (VFSLeaf) themeBase.resolve(MAIN_CSS);
    if (mainFile == null)
        mainFile = themeBase.createChildLeaf(MAIN_CSS);
    VFSLeaf iFrameFile = (VFSLeaf) themeBase.resolve(IFRAME_CSS);
    if (iFrameFile == null)
        iFrameFile = themeBase.createChildLeaf(IFRAME_CSS);
    FileUtils.save(mainFile.getOutputStream(false), sbMain.toString(), "utf-8");
    FileUtils.save(iFrameFile.getOutputStream(false), sbIFrame.toString(), "utf-8");
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AbstractLayoutElement(org.olat.course.config.ui.courselayout.elements.AbstractLayoutElement) XStream(com.thoughtworks.xstream.XStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with AbstractLayoutElement

use of org.olat.course.config.ui.courselayout.elements.AbstractLayoutElement in project openolat by klemens.

the class CustomConfigManager method saveCustomConfigAndCompileCSS.

/**
 * save the custom css configuration in a reprocessable format (map with inner map)
 * also generates the two needed css-files (main / iframe)
 * @param customConfig
 * @param courseEnvironment
 */
public void saveCustomConfigAndCompileCSS(Map<String, Map<String, Object>> customConfig, CourseEnvironment courseEnvironment) {
    VFSContainer themeBase = null;
    VFSContainer base = null;
    base = (VFSContainer) courseEnvironment.getCourseBaseContainer().resolve(CourseLayoutHelper.LAYOUT_COURSE_SUBFOLDER);
    if (base == null) {
        base = courseEnvironment.getCourseBaseContainer().createChildContainer(CourseLayoutHelper.LAYOUT_COURSE_SUBFOLDER);
    }
    themeBase = (VFSContainer) base.resolve("/" + CourseLayoutHelper.CONFIG_KEY_CUSTOM);
    if (themeBase == null) {
        themeBase = base.createChildContainer(CourseLayoutHelper.CONFIG_KEY_CUSTOM);
    }
    VFSLeaf configTarget = (VFSLeaf) themeBase.resolve(CUSTOM_CONFIG_XML);
    if (configTarget == null) {
        configTarget = themeBase.createChildLeaf(CUSTOM_CONFIG_XML);
    }
    XStream xStream = XStreamHelper.createXStreamInstance();
    xStream.toXML(customConfig, configTarget.getOutputStream(false));
    // compile the css-files
    StringBuffer sbMain = new StringBuffer();
    StringBuffer sbIFrame = new StringBuffer();
    for (Entry<String, Map<String, Object>> iterator : customConfig.entrySet()) {
        String type = iterator.getKey();
        Map<String, Object> elementConfig = iterator.getValue();
        AbstractLayoutElement configuredLayEl = createLayoutElementByType(type, elementConfig);
        sbIFrame.append(configuredLayEl.getCSSForIFrame());
        sbMain.append(configuredLayEl.getCSSForMain());
    }
    // attach line for logo, if there is any to cssForMain:
    appendLogoPart(sbMain, themeBase);
    VFSLeaf mainFile = (VFSLeaf) themeBase.resolve(MAIN_CSS);
    if (mainFile == null)
        mainFile = themeBase.createChildLeaf(MAIN_CSS);
    VFSLeaf iFrameFile = (VFSLeaf) themeBase.resolve(IFRAME_CSS);
    if (iFrameFile == null)
        iFrameFile = themeBase.createChildLeaf(IFRAME_CSS);
    FileUtils.save(mainFile.getOutputStream(false), sbMain.toString(), "utf-8");
    FileUtils.save(iFrameFile.getOutputStream(false), sbIFrame.toString(), "utf-8");
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AbstractLayoutElement(org.olat.course.config.ui.courselayout.elements.AbstractLayoutElement) XStream(com.thoughtworks.xstream.XStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)4 Map (java.util.Map)4 AbstractLayoutElement (org.olat.course.config.ui.courselayout.elements.AbstractLayoutElement)4 XStream (com.thoughtworks.xstream.XStream)2 LinkedHashMap (java.util.LinkedHashMap)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 AbstractLayoutAttribute (org.olat.course.config.ui.courselayout.attribs.AbstractLayoutAttribute)2