Search in sources :

Example 16 with ComponentRenderer

use of org.olat.core.gui.components.ComponentRenderer in project openolat by klemens.

the class InlineTranslationInterceptHandlerController method createInterceptComponentRenderer.

public ComponentRenderer createInterceptComponentRenderer(final ComponentRenderer originalRenderer) {
    return new ComponentRenderer() {

        @Override
        public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
            // ------------- show translator keys
            // we must let the original renderer do its work so that the
            // collecting translator is callbacked.
            // we save the result in a new var since it is too early to
            // append it
            // to the 'stream' right now.
            StringOutput sbOrig = new StringOutput();
            try {
                originalRenderer.render(renderer, sbOrig, source, ubu, translator, renderResult, args);
            } catch (Exception e) {
                String emsg = "exception while rendering component '" + source.getComponentName() + "' (" + source.getClass().getName() + ") " + source.getListenerInfo() + "<br />Message of exception: " + e.getMessage();
                sbOrig.append("<span style=\"color:red\">Exception</span><br /><pre>" + emsg + "</pre>");
            }
            String rendered = sbOrig.toString();
            String renderedWithHTMLMarkup = InlineTranslationInterceptHandlerController.replaceLocalizationMarkupWithHTML(rendered, inlineTranslationURLBuilder, getTranslator());
            sb.append(renderedWithHTMLMarkup);
        }

        /**
         * @see org.olat.core.gui.components.ComponentRenderer#renderHeaderIncludes(org.olat.core.gui.render.Renderer,
         *      org.olat.core.gui.render.StringOutput,
         *      org.olat.core.gui.components.Component,
         *      org.olat.core.gui.render.URLBuilder,
         *      org.olat.core.gui.translator.Translator,
         *      org.olat.core.gui.render.RenderingState)
         */
        @Override
        public void renderHeaderIncludes(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderingState rstate) {
            originalRenderer.renderHeaderIncludes(renderer, sb, source, ubu, translator, rstate);
        }

        /**
         * @see org.olat.core.gui.components.ComponentRenderer#renderBodyOnLoadJSFunctionCall(org.olat.core.gui.render.Renderer,
         *      org.olat.core.gui.render.StringOutput,
         *      org.olat.core.gui.components.Component,
         *      org.olat.core.gui.render.RenderingState)
         */
        @Override
        public void renderBodyOnLoadJSFunctionCall(Renderer renderer, StringOutput sb, Component source, RenderingState rstate) {
            originalRenderer.renderBodyOnLoadJSFunctionCall(renderer, sb, source, rstate);
        }
    };
}
Also used : ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) Translator(org.olat.core.gui.translator.Translator) Renderer(org.olat.core.gui.render.Renderer) ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) RenderResult(org.olat.core.gui.render.RenderResult) RenderingState(org.olat.core.gui.render.RenderingState) StringOutput(org.olat.core.gui.render.StringOutput) DelegatingComponent(org.olat.core.gui.components.delegating.DelegatingComponent) Component(org.olat.core.gui.components.Component) URLBuilder(org.olat.core.gui.render.URLBuilder)

Example 17 with ComponentRenderer

use of org.olat.core.gui.components.ComponentRenderer in project openolat by klemens.

the class DelegatingRenderer method renderBodyOnLoadJSFunctionCall.

/**
 * @see org.olat.core.gui.render.ui.ComponentRenderer#renderBodyOnLoadJSFunctionCall(org.olat.core.gui.render.Renderer,
 *      org.olat.core.gui.render.StringOutput, org.olat.core.gui.components.Component)
 */
public void renderBodyOnLoadJSFunctionCall(Renderer renderer, StringOutput sb, Component source, RenderingState rstate) {
    ComponentRenderer cr = ((DelegatingComponent) source).getDelegateRenderer();
    cr.renderBodyOnLoadJSFunctionCall(renderer, sb, source, rstate);
}
Also used : ComponentRenderer(org.olat.core.gui.components.ComponentRenderer)

Example 18 with ComponentRenderer

use of org.olat.core.gui.components.ComponentRenderer in project openolat by klemens.

the class TextElementImpl method initInlineEditing.

private void initInlineEditing(String predefinedValue) {
    // init the inline editing element component.
    transientValue = predefinedValue;
    AbstractInlineElementComponent aiec = new AbstractInlineElementComponent(this, new ComponentRenderer() {

        public void renderHeaderIncludes(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderingState rstate) {
        // nothing to do here
        }

        public void renderBodyOnLoadJSFunctionCall(Renderer renderer, StringOutput sb, Component source, RenderingState rstate) {
        // nothing to do here
        }

        public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
            AbstractInlineElementComponent aiec = (AbstractInlineElementComponent) source;
            InlineTextElement itei = (InlineTextElement) aiec.getInlineElement();
            StringBuilder htmlVal = new StringBuilder();
            /**
             * in case of an error show the test which caused the error which must be stored by the textelement in the transientValue.
             * the last valid value is always set over setValue(..) by the textelement, and thus can be retrieved as such here.
             */
            String tmpVal;
            String emptyVal = (itei.isInlineEditingOn() ? "" : itei.getEmptyDisplayText());
            if (itei.hasError()) {
                tmpVal = StringHelper.containsNonWhitespace(transientValue) ? transientValue : emptyVal;
            } else {
                tmpVal = StringHelper.containsNonWhitespace(getValue()) ? getValue() : emptyVal;
            }
            // append the html safe value
            htmlVal.append(StringEscapeUtils.escapeHtml(tmpVal));
            if (!itei.isEnabled()) {
                // RO view and not clickable
                String id = aiec.getFormDispatchId();
                sb.append("<div class='form-control-static' id=\"").append(id).append("\" ").append(" >").append(htmlVal).append("</div>");
            } else {
                // .......presssing ESC -> restore previous value and submit this one.
                if (itei.isInlineEditingOn()) {
                    String id = aiec.getFormDispatchId();
                    // read write view
                    sb.append("<input type=\"").append("input").append("\" class=\"form-control\" id=\"");
                    sb.append(id);
                    sb.append("\" name=\"");
                    sb.append(id);
                    sb.append("\" size=\"");
                    sb.append("30");
                    // if(itei.maxlength > -1){
                    // sb.append("\" maxlength=\"");
                    // sb.append(itei.maxlength);
                    // }
                    sb.append("\" value=\"");
                    sb.append(htmlVal);
                    sb.append("\" ");
                    sb.append(" />");
                    // Javascript
                    sb.append(FormJSHelper.getJSStart());
                    // clicking outside or pressing enter -> OK, pressing ESC -> Cancel
                    FormJSHelper.getInlineEditOkCancelJS(sb, id, StringEscapeUtils.escapeHtml(getValue()), itei.getRootForm());
                    sb.append(FormJSHelper.getJSEnd());
                } else {
                    // RO<->RW view which can be clicked
                    Translator trans = Util.createPackageTranslator(TextElementImpl.class, translator.getLocale(), translator);
                    String id = aiec.getFormDispatchId();
                    sb.append("<div id='").append(id).append("' class='form-control-static' title=\"").append(StringEscapeUtils.escapeHtml(trans.translate("inline.edit.help"))).append("\" ").append(FormJSHelper.getRawJSFor(itei.getRootForm(), id, itei.getAction())).append("> ").append(htmlVal).append(" <i class='o_icon o_icon_inline_editable'> </i></div>");
                }
            }
        // endif
        }
    });
    setInlineEditingComponent(aiec);
}
Also used : RenderingState(org.olat.core.gui.render.RenderingState) RenderResult(org.olat.core.gui.render.RenderResult) StringOutput(org.olat.core.gui.render.StringOutput) URLBuilder(org.olat.core.gui.render.URLBuilder) InlineTextElement(org.olat.core.gui.components.form.flexible.elements.InlineTextElement) ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) Translator(org.olat.core.gui.translator.Translator) ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) Renderer(org.olat.core.gui.render.Renderer) Component(org.olat.core.gui.components.Component)

Example 19 with ComponentRenderer

use of org.olat.core.gui.components.ComponentRenderer in project openolat by klemens.

the class Renderer method render.

/**
 * used by the renderer, and also by the panel and tabbedpane renderer to delegate rendering
 * @param sb
 * @param source
 * @param args
 */
public void render(StringOutput sb, Component source, String[] args) {
    GlobalSettings gset = getGlobalSettings();
    boolean ajaxon = gset.getAjaxFlags().isIframePostEnabled();
    // wrap with div's so javascript can replace this component by doing a document.getElementById(cid).innerHTML and so on.
    boolean domReplaceable = source.isDomReplaceable();
    boolean useSpan = source.getSpanAsDomReplaceable();
    boolean domReplacementWrapperRequired = source.isDomReplacementWrapperRequired();
    boolean forceDebugDivs = gset.isIdDivsForced();
    if (source.isVisible()) {
        int lev = renderResult.getNestedLevel();
        if (lev > 60)
            throw new AssertException("components were nested more than 60 times, assuming endless loop bug: latest comp name: " + source.getComponentName());
        Translator componentTranslator = source.getTranslator();
        // identifier for dom replacement
        if (domReplaceable && domReplacementWrapperRequired && (ajaxon || forceDebugDivs)) {
            if (useSpan) {
                sb.append("<span id='o_c").append(source.getDispatchID());
            } else {
                sb.append("<div id='o_c").append(source.getDispatchID());
            }
            if (Settings.isDebuging()) {
            // sb.append("' title='").append(source.getComponentName());
            }
            sb.append("'>");
        }
        ComponentRenderer cr = findComponentRenderer(source);
        URLBuilder cubu = urlBuilder.createCopyFor(source);
        renderResult.incNestedLevel();
        // ---- for gui debug mode, direct the rendering to a special componentrenderer
        InterceptHandlerInstance dhi = renderResult.getInterceptHandlerInstance();
        if (dhi != null) {
            cr = dhi.createInterceptComponentRenderer(cr);
        }
        try {
            int preRenderLength = sb.length();
            cr.render(this, sb, source, cubu, componentTranslator, renderResult, args);
            if (preRenderLength == sb.length()) {
                // Add bugfix for IE min-height on empty div problem: min-height does
                // not get applied when div contains an empty comment.
                // Affects IE6, IE7
                sb.append("<!-- empty -->");
            }
            source.setDirty(false);
        } catch (Exception e) {
            // in order to produce a decent error msg, we need to postpone the
            // exception
            renderResult.setRenderExceptionInfo("exception while rendering component '" + source.getComponentName() + "' (" + source.getClass().getName() + ") " + source.getListenerInfo() + "<br />Message of exception: " + e.getMessage(), e);
        }
        renderResult.decNestedLevel();
        if (ajaxon && domReplaceable && domReplacementWrapperRequired) {
            if (useSpan) {
                sb.append("</span>");
            } else {
                sb.append("</div>");
            }
        }
    } else {
        // not visible
        if (domReplaceable && (ajaxon || forceDebugDivs)) {
            // browser dom tree
            if (useSpan) {
                sb.append("<span id=\"o_c").append(source.getDispatchID()).append("\"></span>");
            } else {
                // Add bugfix for IE min-height on empty div problem: min-height does
                // not get applied when div contains an empty comment.
                // Affects IE6, IE7
                sb.append("<div id=\"o_c").append(source.getDispatchID()).append("\"><!-- empty --></div>");
            }
        }
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) Translator(org.olat.core.gui.translator.Translator) GlobalSettings(org.olat.core.gui.GlobalSettings) InterceptHandlerInstance(org.olat.core.gui.render.intercept.InterceptHandlerInstance) AssertException(org.olat.core.logging.AssertException)

Example 20 with ComponentRenderer

use of org.olat.core.gui.components.ComponentRenderer in project openolat by klemens.

the class Renderer method renderHeaderIncludes.

/**
 * @param sb
 * @param source
 */
public void renderHeaderIncludes(StringOutput sb, Component source, RenderingState rstate) {
    if (source != null && source.isVisible()) {
        ComponentRenderer cr = findComponentRenderer(source);
        URLBuilder cubu = urlBuilder.createCopyFor(source);
        cr.renderHeaderIncludes(this, sb, source, cubu, translator, rstate);
    }
}
Also used : ComponentRenderer(org.olat.core.gui.components.ComponentRenderer)

Aggregations

ComponentRenderer (org.olat.core.gui.components.ComponentRenderer)20 Translator (org.olat.core.gui.translator.Translator)10 Component (org.olat.core.gui.components.Component)8 RenderResult (org.olat.core.gui.render.RenderResult)6 Renderer (org.olat.core.gui.render.Renderer)6 RenderingState (org.olat.core.gui.render.RenderingState)6 StringOutput (org.olat.core.gui.render.StringOutput)6 URLBuilder (org.olat.core.gui.render.URLBuilder)6 DelegatingComponent (org.olat.core.gui.components.delegating.DelegatingComponent)4 IOException (java.io.IOException)2 PlainTextEditorController (org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController)2 GlobalSettings (org.olat.core.gui.GlobalSettings)2 DefaultComponentRenderer (org.olat.core.gui.components.DefaultComponentRenderer)2 InlineTextElement (org.olat.core.gui.components.form.flexible.elements.InlineTextElement)2 Controller (org.olat.core.gui.control.Controller)2 BasicController (org.olat.core.gui.control.controller.BasicController)2 SourceViewController (org.olat.core.gui.dev.controller.SourceViewController)2 InterceptHandlerInstance (org.olat.core.gui.render.intercept.InterceptHandlerInstance)2 AssertException (org.olat.core.logging.AssertException)2