Search in sources :

Example 6 with ComponentRenderer

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

the class GuiDebugDispatcherController method createInterceptComponentRenderer.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.olat.core.gui.render.debug.DebugHandler#createDebugComponentRenderer(org.olat.core.gui.components.ComponentRenderer)
	 */
@Override
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) {
            if (debugURLBuilder != null && !DebugHelper.isProtected(source)) {
                // remember source for later debug info access
                String did = source.getDispatchID();
                String didS = String.valueOf(did);
                idToComponent.put(didS, source);
                int lev = renderResult.getNestedLevel();
                String cname = source.getClass().getName();
                String cnameShort = cname.substring(cname.lastIndexOf('.') + 1);
                // header before component
                sb.append("<div class='o_dev_w'>");
                sb.append("<div class='o_dev_h'><span id='o_guidebugst").append(did).append("' onmouseover=\"o_debu_show(this.parentNode.parentNode, jQuery('#o_guidebugtt").append(did).append("'))\">");
                sb.append(source.getComponentName()).append(" (").append(cnameShort).append(")");
                sb.append("</span></div>");
                sb.append("<div class='o_dev_c'><div id='o_guidebugtt").append(did).append("' class='o_dev_i'>");
                sb.append("Info: <b>").append(source.getComponentName()).append("</b> (" + cnameShort + ") id:");
                sb.append(String.valueOf(source.getDispatchID())).append("&nbsp; level:").append(lev);
                Controller listC = Util.getListeningControllerFor(source);
                if (listC != null) {
                    sb.append("<br /><b>controller:</b> <a  target=\"_blank\" href=\"");
                    String controllerClassName = listC.getClass().getName();
                    debugURLBuilder.buildURI(sb, new String[] { "cid", "com", "class" }, new String[] { String.valueOf(did), "ojava", controllerClassName });
                    sb.append("\">");
                    sb.append(controllerClassName);
                    sb.append("</a>");
                }
                sb.append("<br /><i>listeners</i>: ");
                if (!source.isEnabled()) {
                    sb.append(" NOT ENABLED");
                }
                String listeners = source.getListenerInfo();
                sb.append(listeners);
                if (!source.isVisible()) {
                    sb.append("<br />INVISIBLE");
                }
                sb.append("<br />");
                // 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>");
                }
                sb.append("</div>");
                // add original component
                sb.append(sbOrig);
                sb.append("</div></div>");
            } else {
                // e.g. when the render process take place before the delegating
                // component of this controller here was rendered.
                // the delegating component should be placed near the <html> tag in
                // order to be rendered first.
                // the contentpane of the window and the first implementing container
                // will not be provided with debug info, which is on purpose,
                // since those are contents from the chiefcontroller which control the
                // window.
                // render original component
                originalRenderer.render(renderer, sb, source, ubu, translator, renderResult, args);
            }
        }

        @Override
        public void renderHeaderIncludes(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderingState rstate) {
            originalRenderer.renderHeaderIncludes(renderer, sb, source, ubu, translator, rstate);
        }

        @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) ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) Renderer(org.olat.core.gui.render.Renderer) RenderResult(org.olat.core.gui.render.RenderResult) RenderingState(org.olat.core.gui.render.RenderingState) StringOutput(org.olat.core.gui.render.StringOutput) Component(org.olat.core.gui.components.Component) DelegatingComponent(org.olat.core.gui.components.delegating.DelegatingComponent) Controller(org.olat.core.gui.control.Controller) BasicController(org.olat.core.gui.control.controller.BasicController) PlainTextEditorController(org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController) SourceViewController(org.olat.core.gui.dev.controller.SourceViewController) IOException(java.io.IOException) URLBuilder(org.olat.core.gui.render.URLBuilder)

Example 7 with ComponentRenderer

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

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 8 with ComponentRenderer

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

the class DelegatingRenderer method render.

/**
 * @see org.olat.core.gui.render.ui.ComponentRenderer#render(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.RenderResult, java.lang.String[])
 */
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    ComponentRenderer cr = ((DelegatingComponent) source).getDelegateRenderer();
    cr.render(renderer, sb, source, ubu, translator, renderResult, args);
}
Also used : ComponentRenderer(org.olat.core.gui.components.ComponentRenderer)

Example 9 with ComponentRenderer

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

the class DelegatingRenderer method renderHeaderIncludes.

/**
 * @see org.olat.core.gui.render.ui.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)
 */
public void renderHeaderIncludes(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderingState rstate) {
    ComponentRenderer cr = ((DelegatingComponent) source).getDelegateRenderer();
    cr.renderHeaderIncludes(renderer, sb, source, ubu, translator, rstate);
}
Also used : ComponentRenderer(org.olat.core.gui.components.ComponentRenderer)

Example 10 with ComponentRenderer

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

the class Renderer method renderBodyOnLoadJSFunctionCall.

/**
 * renders the HTMLHeader-Part which this component comp needs. e.g. the
 * richtext component needs some css and javascript libraries an
 * velocity-container is a special case: it should collect the information
 * from all the children that are visible since all could be renderer. since
 * the actual rendering of a component depends on the page and is not know
 * beforehand, we could include some css/js which turns out not to be needed
 * in this request, but it is cached by the browser anyway, so it should not
 * matter to much. a little advice if you want to do it perfectly : program
 * the controller in such a way that they make a component invisible if not
 * needed
 *
 * @param sb
 * @param source
 * @see org.olat.core.gui.render.ui.ComponentRenderer
 */
public void renderBodyOnLoadJSFunctionCall(StringOutput sb, Component source, RenderingState rstate) {
    if (source != null && source.isVisible()) {
        ComponentRenderer cr = findComponentRenderer(source);
        cr.renderBodyOnLoadJSFunctionCall(this, sb, source, 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