Search in sources :

Example 56 with XmlStringBuilder

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

the class DiagnosticRenderUtil method renderHelper.

/**
 * Render the diagnostics.
 * @param renderContext the current renderContext
 * @param diags the list of Diagnostic objects
 * @param severity the severity we are rendering
 */
private static void renderHelper(final WebXmlRenderContext renderContext, final List<Diagnostic> diags, final int severity) {
    if (diags.isEmpty()) {
        return;
    }
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen(TAG_NAME);
    xml.appendAttribute("type", getLevel(severity));
    xml.appendClose();
    for (Diagnostic diagnostic : diags) {
        xml.appendTag(MESSAGE_TAG_NAME);
        xml.appendEscaped(diagnostic.getDescription());
        xml.appendEndTag(MESSAGE_TAG_NAME);
    }
    xml.appendEndTag(TAG_NAME);
}
Also used : Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 57 with XmlStringBuilder

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

the class FlowLayoutRenderer method doRender.

/**
 * Paints the given WPanel's children.
 *
 * @param component the container to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPanel panel = (WPanel) component;
    XmlStringBuilder xml = renderContext.getWriter();
    FlowLayout layout = (FlowLayout) panel.getLayout();
    Size gap = layout.getSpace();
    String gapString = gap != null ? gap.toString() : null;
    FlowLayout.Alignment align = layout.getAlignment();
    xml.appendTagOpen("ui:flowlayout");
    switch(align) {
        case RIGHT:
            {
                xml.appendAttribute("align", "right");
                break;
            }
        case CENTER:
            {
                xml.appendAttribute("align", "center");
                break;
            }
        case LEFT:
            {
                xml.appendAttribute("align", "left");
                break;
            }
        case VERTICAL:
            xml.appendAttribute("align", "vertical");
            break;
        default:
            throw new IllegalStateException("Unknown layout type: " + layout.getAlignment());
    }
    if (layout.getContentAlignment() != null) {
        switch(layout.getContentAlignment()) {
            case TOP:
                {
                    xml.appendAttribute("valign", "top");
                    break;
                }
            case MIDDLE:
                {
                    xml.appendAttribute("valign", "middle");
                    break;
                }
            case BASELINE:
                {
                    xml.appendAttribute("valign", "baseline");
                    break;
                }
            case BOTTOM:
                xml.appendAttribute("valign", "bottom");
                break;
            default:
                throw new IllegalStateException("Unknown content alignment type: " + layout.getContentAlignment());
        }
    }
    xml.appendOptionalAttribute("gap", gapString);
    xml.appendClose();
    int size = panel.getChildCount();
    for (int i = 0; i < size; i++) {
        xml.appendTag("ui:cell");
        WComponent child = panel.getChildAt(i);
        child.paint(renderContext);
        xml.appendEndTag("ui:cell");
    }
    xml.appendEndTag("ui:flowlayout");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) Size(com.github.bordertech.wcomponents.Size) WPanel(com.github.bordertech.wcomponents.WPanel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 58 with XmlStringBuilder

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

the class GridLayoutRenderer method doRender.

/**
 * Paints the given WPanel's children.
 *
 * @param component the container to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPanel panel = (WPanel) component;
    XmlStringBuilder xml = renderContext.getWriter();
    GridLayout layout = (GridLayout) panel.getLayout();
    Size hgap = layout.getHorizontalGap();
    String hgapString = hgap == null ? null : hgap.toString();
    Size vgap = layout.getVerticalGap();
    String vgapString = vgap == null ? null : vgap.toString();
    int rows = layout.getRows();
    int cols = layout.getCols();
    xml.appendTagOpen("ui:gridlayout");
    xml.appendAttribute("rows", rows > 0 ? String.valueOf(rows) : "0");
    xml.appendAttribute("cols", cols > 0 ? String.valueOf(cols) : "0");
    xml.appendOptionalAttribute("hgap", hgapString);
    xml.appendOptionalAttribute("vgap", vgapString);
    xml.appendClose();
    int size = panel.getChildCount();
    for (int i = 0; i < size; i++) {
        xml.appendTag("ui:cell");
        WComponent child = panel.getChildAt(i);
        child.paint(renderContext);
        xml.appendEndTag("ui:cell");
    }
    xml.appendEndTag("ui:gridlayout");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) GridLayout(com.github.bordertech.wcomponents.layout.GridLayout) Size(com.github.bordertech.wcomponents.Size) WPanel(com.github.bordertech.wcomponents.WPanel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 59 with XmlStringBuilder

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

the class ListLayoutRenderer method doRender.

/**
 * Paints the given WPanel's children.
 *
 * @param component the container to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPanel panel = (WPanel) component;
    XmlStringBuilder xml = renderContext.getWriter();
    ListLayout layout = (ListLayout) panel.getLayout();
    int childCount = panel.getChildCount();
    Size gap = layout.getSpace();
    String gapString = gap != null ? gap.toString() : null;
    xml.appendTagOpen("ui:listlayout");
    switch(layout.getType()) {
        case FLAT:
            xml.appendAttribute("type", "flat");
            break;
        case STACKED:
            xml.appendAttribute("type", "stacked");
            break;
        case STRIPED:
            xml.appendAttribute("type", "striped");
            break;
        default:
            throw new IllegalArgumentException("Invalid type: " + layout.getType());
    }
    switch(layout.getAlignment()) {
        case LEFT:
            // left is assumed if omitted
            break;
        case RIGHT:
            xml.appendAttribute("align", "right");
            break;
        case CENTER:
            xml.appendAttribute("align", "center");
            break;
        default:
            throw new IllegalArgumentException("Invalid alignment: " + layout.getAlignment());
    }
    switch(layout.getSeparator()) {
        case NONE:
            // none is assumed if omitted
            break;
        case BAR:
            xml.appendAttribute("separator", "bar");
            break;
        case DOT:
            xml.appendAttribute("separator", "dot");
            break;
        default:
            throw new IllegalArgumentException("Invalid separator: " + layout.getSeparator());
    }
    xml.appendOptionalAttribute("ordered", layout.isOrdered(), "true");
    xml.appendOptionalAttribute("gap", gapString);
    xml.appendClose();
    // Paint children
    for (int i = 0; i < childCount; i++) {
        xml.appendTag("ui:cell");
        panel.getChildAt(i).paint(renderContext);
        xml.appendEndTag("ui:cell");
    }
    xml.appendEndTag("ui:listlayout");
}
Also used : ListLayout(com.github.bordertech.wcomponents.layout.ListLayout) Size(com.github.bordertech.wcomponents.Size) WPanel(com.github.bordertech.wcomponents.WPanel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 60 with XmlStringBuilder

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

the class MarginRendererUtil method renderMargin.

/**
 * @param component the marginable component to paint a margin
 * @param renderContext the RenderContext to paint to.
 */
public static void renderMargin(final Marginable component, final WebXmlRenderContext renderContext) {
    Margin margin = component.getMargin();
    if (margin == null) {
        return;
    }
    XmlStringBuilder xml = renderContext.getWriter();
    if (margin.getMargin() != null) {
        xml.appendTagOpen("ui:margin");
        xml.appendAttribute("all", margin.getMargin().toString());
        xml.appendEnd();
    } else if (margin.getTop() != null || margin.getRight() != null || margin.getBottom() != null || margin.getLeft() != null) {
        xml.appendTagOpen("ui:margin");
        Size size = margin.getTop();
        if (size != null) {
            xml.appendAttribute("north", size.toString());
        }
        size = margin.getRight();
        if (size != null) {
            xml.appendAttribute("east", size.toString());
        }
        size = margin.getBottom();
        if (size != null) {
            xml.appendAttribute("south", size.toString());
        }
        size = margin.getLeft();
        if (size != null) {
            xml.appendAttribute("west", size.toString());
        }
        xml.appendEnd();
    }
}
Also used : Size(com.github.bordertech.wcomponents.Size) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) Margin(com.github.bordertech.wcomponents.Margin)

Aggregations

XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)102 WComponent (com.github.bordertech.wcomponents.WComponent)30 SystemException (com.github.bordertech.wcomponents.util.SystemException)17 Size (com.github.bordertech.wcomponents.Size)8 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)7 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)6 UIContext (com.github.bordertech.wcomponents.UIContext)5 WPanel (com.github.bordertech.wcomponents.WPanel)5 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 WButton (com.github.bordertech.wcomponents.WButton)4 WSuggestions (com.github.bordertech.wcomponents.WSuggestions)4 WTable (com.github.bordertech.wcomponents.WTable)4 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)4 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)3 TableDataModel (com.github.bordertech.wcomponents.TableDataModel)3 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)3 WDataTable (com.github.bordertech.wcomponents.WDataTable)3 WRepeater (com.github.bordertech.wcomponents.WRepeater)3 TableModel (com.github.bordertech.wcomponents.WTable.TableModel)3 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)2