Search in sources :

Example 6 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class WWindowInterceptor method paint.

/**
 * Temporarily replaces the environment while the UI is being rendered.
 *
 * @param renderContext the context to render to.
 */
@Override
public void paint(final RenderContext renderContext) {
    if (windowId == null) {
        super.paint(renderContext);
    } else {
        // Get the window component
        ComponentWithContext target = WebUtilities.getComponentById(windowId, true);
        if (target == null) {
            throw new SystemException("No window component for id " + windowId);
        }
        UIContext uic = UIContextHolder.getCurrentPrimaryUIContext();
        Environment originalEnvironment = uic.getEnvironment();
        uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target));
        UIContextHolder.pushContext(target.getContext());
        try {
            super.paint(renderContext);
        } finally {
            uic.setEnvironment(originalEnvironment);
            UIContextHolder.popContext();
        }
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContext(com.github.bordertech.wcomponents.UIContext) Environment(com.github.bordertech.wcomponents.Environment) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 7 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class VelocityRenderer method addToContext.

/**
 * Adds a name/value pair to the Velocity context. If the name parameter ends with {@link #LIST_SUFFIX}
 *
 * @param context the context to add to.
 * @param name the name
 * @param value the value
 */
private void addToContext(final VelocityContext context, final String name, final Object value) {
    if (name.endsWith(LIST_SUFFIX)) {
        // We want to use lists
        Object already = context.get(name);
        if (already != null && !(already instanceof List)) {
            throw new SystemException("VelocityContext contained " + already + " instead of List under " + name);
        }
        List list = (List) context.get(name);
        if (list == null) {
            list = new ArrayList();
            context.put(name, list);
        }
        list.add(value);
    } else {
        context.put(name, value);
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class WCollapsibleRenderer method doRender.

/**
 * Paints the given WCollapsible.
 *
 * @param component the WCollapsible to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WCollapsible collapsible = (WCollapsible) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WComponent content = collapsible.getContent();
    boolean collapsed = collapsible.isCollapsed();
    xml.appendTagOpen("ui:collapsible");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendAttribute("groupName", collapsible.getGroupName());
    xml.appendOptionalAttribute("collapsed", collapsed, "true");
    xml.appendOptionalAttribute("hidden", collapsible.isHidden(), "true");
    switch(collapsible.getMode()) {
        case CLIENT:
            xml.appendAttribute("mode", "client");
            break;
        case LAZY:
            xml.appendAttribute("mode", "lazy");
            break;
        case EAGER:
            xml.appendAttribute("mode", "eager");
            break;
        case DYNAMIC:
            xml.appendAttribute("mode", "dynamic");
            break;
        case SERVER:
            xml.appendAttribute("mode", "server");
            break;
        default:
            throw new SystemException("Unknown collapsible mode: " + collapsible.getMode());
    }
    HeadingLevel level = collapsible.getHeadingLevel();
    if (level != null) {
        xml.appendAttribute("level", level.getLevel());
    }
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(collapsible, renderContext);
    // Label
    collapsible.getDecoratedLabel().paint(renderContext);
    // Content
    xml.appendTagOpen("ui:content");
    xml.appendAttribute("id", component.getId() + "-content");
    xml.appendClose();
    // Render content if not EAGER Mode or is EAGER and is the current AJAX trigger
    if (CollapsibleMode.EAGER != collapsible.getMode() || AjaxHelper.isCurrentAjaxTrigger(collapsible)) {
        // Visibility of content set in prepare paint
        content.paint(renderContext);
    }
    xml.appendEndTag("ui:content");
    xml.appendEndTag("ui:collapsible");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WCollapsible(com.github.bordertech.wcomponents.WCollapsible) SystemException(com.github.bordertech.wcomponents.util.SystemException) HeadingLevel(com.github.bordertech.wcomponents.HeadingLevel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 9 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class UIManager method findRendererFactory.

/**
 * Finds the renderer factory for the given package.
 *
 * @param packageName the package name to find the renderer factory for.
 * @return the RendererFactory for the given package, or null if not found.
 */
private synchronized RendererFactory findRendererFactory(final String packageName) {
    RendererFactory factory = factoriesByPackage.get(packageName);
    if (factory == null) {
        try {
            factory = (RendererFactory) Class.forName(packageName + ".RendererFactoryImpl").newInstance();
            factoriesByPackage.put(packageName, factory);
        } catch (Exception e) {
            throw new SystemException("Failed to create layout manager factory for " + packageName, e);
        }
    }
    return factory;
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) RendererFactory(com.github.bordertech.wcomponents.RendererFactory) SystemException(com.github.bordertech.wcomponents.util.SystemException)

Example 10 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class UIManager method createRenderer.

/**
 * Attempts to create a Renderer with the given name.
 *
 * @param rendererName the name of the Renderer
 * @return a Renderer of the given type, or null if the class was not found.
 */
private static Renderer createRenderer(final String rendererName) {
    if (rendererName.endsWith(".vm")) {
        // This is a velocity template, so use a VelocityLayout
        return new VelocityRenderer(rendererName);
    }
    try {
        Class<?> managerClass = Class.forName(rendererName);
        Object manager = managerClass.newInstance();
        if (!(manager instanceof Renderer)) {
            throw new SystemException(rendererName + " is not a Renderer");
        }
        return (Renderer) manager;
    } catch (ClassNotFoundException e) {
        // Legal - there might not a manager implementation in a given theme
        return null;
    } catch (InstantiationException e) {
        throw new SystemException("Failed to instantiate " + rendererName, e);
    } catch (IllegalAccessException e) {
        throw new SystemException("Failed to access " + rendererName, e);
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) Renderer(com.github.bordertech.wcomponents.Renderer) VelocityRenderer(com.github.bordertech.wcomponents.render.webxml.VelocityRenderer) VelocityRenderer(com.github.bordertech.wcomponents.render.webxml.VelocityRenderer)

Aggregations

SystemException (com.github.bordertech.wcomponents.util.SystemException)94 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)17 WComponent (com.github.bordertech.wcomponents.WComponent)15 UIContext (com.github.bordertech.wcomponents.UIContext)13 Test (org.junit.Test)12 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 WebElement (org.openqa.selenium.WebElement)9 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)6 IOException (java.io.IOException)5 Select (org.openqa.selenium.support.ui.Select)5 ErrorCodeEscape (com.github.bordertech.wcomponents.ErrorCodeEscape)4 Request (com.github.bordertech.wcomponents.Request)4 InputStream (java.io.InputStream)4 PrintWriter (java.io.PrintWriter)4 ArrayList (java.util.ArrayList)4 Environment (com.github.bordertech.wcomponents.Environment)3 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Date (java.util.Date)3 List (java.util.List)3