Search in sources :

Example 1 with WFigure

use of com.github.bordertech.wcomponents.WFigure in project wcomponents by BorderTech.

the class WFigureRenderer method doRender.

/**
 * Paints the given WFigure.
 *
 * @param component the WFigure to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WFigure figure = (WFigure) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean renderChildren = isRenderContent(figure);
    xml.appendTagOpen("ui:figure");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    if (FigureMode.LAZY.equals(figure.getMode())) {
        xml.appendOptionalAttribute("hidden", !renderChildren, "true");
    } else {
        xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
    }
    FigureMode mode = figure.getMode();
    if (mode != null) {
        switch(mode) {
            case LAZY:
                xml.appendAttribute("mode", "lazy");
                break;
            case EAGER:
                xml.appendAttribute("mode", "eager");
                break;
            default:
                throw new SystemException("Unknown figure mode: " + figure.getMode());
        }
    }
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(figure, renderContext);
    if (renderChildren) {
        // Label
        figure.getDecoratedLabel().paint(renderContext);
        // Content
        xml.appendTagOpen("ui:content");
        xml.appendAttribute("id", component.getId() + "-content");
        xml.appendClose();
        figure.getContent().paint(renderContext);
        xml.appendEndTag("ui:content");
    }
    xml.appendEndTag("ui:figure");
}
Also used : WFigure(com.github.bordertech.wcomponents.WFigure) FigureMode(com.github.bordertech.wcomponents.WFigure.FigureMode) SystemException(com.github.bordertech.wcomponents.util.SystemException) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 2 with WFigure

use of com.github.bordertech.wcomponents.WFigure in project wcomponents by BorderTech.

the class WFigureRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WFigure figure = new WFigure(new WText(), "");
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(figure) instanceof WFigureRenderer);
}
Also used : WFigure(com.github.bordertech.wcomponents.WFigure) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Example 3 with WFigure

use of com.github.bordertech.wcomponents.WFigure in project wcomponents by BorderTech.

the class WFigureRenderer_Test method testRenderedWithMargins.

@Test
public void testRenderedWithMargins() throws IOException, SAXException, XpathException {
    WFigure figure = new WFigure(new WText(FIGURE_CONTENT), FIGURE_HEADING);
    assertXpathNotExists("//ui:figure/ui:margin", figure);
    Margin margin = new Margin(0);
    figure.setMargin(margin);
    assertXpathNotExists("//ui:figure/ui:margin", figure);
    margin = new Margin(Size.SMALL);
    figure.setMargin(margin);
    assertSchemaMatch(figure);
    assertXpathEvaluatesTo("sm", "//ui:figure/ui:margin/@all", figure);
    assertXpathEvaluatesTo("", "//ui:figure/ui:margin/@north", figure);
    assertXpathEvaluatesTo("", "//ui:figure/ui:margin/@east", figure);
    assertXpathEvaluatesTo("", "//ui:figure/ui:margin/@south", figure);
    assertXpathEvaluatesTo("", "//ui:figure/ui:margin/@west", figure);
    margin = new Margin(Size.SMALL, Size.MEDIUM, Size.LARGE, Size.XL);
    figure.setMargin(margin);
    assertSchemaMatch(figure);
    assertXpathEvaluatesTo("", "//ui:figure/ui:margin/@all", figure);
    assertXpathEvaluatesTo("sm", "//ui:figure/ui:margin/@north", figure);
    assertXpathEvaluatesTo("med", "//ui:figure/ui:margin/@east", figure);
    assertXpathEvaluatesTo("lg", "//ui:figure/ui:margin/@south", figure);
    assertXpathEvaluatesTo("xl", "//ui:figure/ui:margin/@west", figure);
}
Also used : WFigure(com.github.bordertech.wcomponents.WFigure) WText(com.github.bordertech.wcomponents.WText) Margin(com.github.bordertech.wcomponents.Margin) Test(org.junit.Test)

Example 4 with WFigure

use of com.github.bordertech.wcomponents.WFigure in project wcomponents by BorderTech.

the class WFigureRenderer_Test method testRenderedEagerMode.

@Test
public void testRenderedEagerMode() throws IOException, SAXException, XpathException {
    WFigure figure = new WFigure(new WText(FIGURE_CONTENT), FIGURE_HEADING);
    figure.setMode(FigureMode.EAGER);
    UIContext uic = createUIContext();
    uic.setUI(new DefaultWComponent());
    setActiveContext(uic);
    // The figure's content should NOT be rendered
    assertSchemaMatch(figure);
    assertXpathEvaluatesTo("", "//ui:figure/@type", figure);
    assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure);
    assertXpathEvaluatesTo("eager", "//ui:figure/@mode", figure);
    assertXpathEvaluatesTo("", "//ui:figure/ui:content", figure);
    try {
        // Figure is the AJAX Trigger, content should be rendered
        AjaxOperation operation = new AjaxOperation(figure.getId(), figure.getId());
        AjaxHelper.setCurrentOperationDetails(operation, null);
        assertSchemaMatch(figure);
        assertXpathEvaluatesTo("", "//ui:figure/@type", figure);
        assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure);
        assertXpathEvaluatesTo("eager", "//ui:figure/@mode", figure);
        assertXpathEvaluatesTo(FIGURE_CONTENT, "//ui:figure/ui:content", figure);
    } finally {
        AjaxHelper.clearCurrentOperationDetails();
    }
}
Also used : WFigure(com.github.bordertech.wcomponents.WFigure) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 5 with WFigure

use of com.github.bordertech.wcomponents.WFigure in project wcomponents by BorderTech.

the class WFigureRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WFigure figure = new WFigure(new WText(getMaliciousContent()), getMaliciousContent());
    assertSafeContent(figure);
}
Also used : WFigure(com.github.bordertech.wcomponents.WFigure) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Aggregations

WFigure (com.github.bordertech.wcomponents.WFigure)6 WText (com.github.bordertech.wcomponents.WText)5 Test (org.junit.Test)5 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)2 UIContext (com.github.bordertech.wcomponents.UIContext)2 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)1 Margin (com.github.bordertech.wcomponents.Margin)1 FigureMode (com.github.bordertech.wcomponents.WFigure.FigureMode)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1