Search in sources :

Example 66 with WComponent

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

the class UIRegistryAmicableImpl method getUI.

/**
 * Retrieves the user interface that was registered with the given key. If the UI has not been registered, this
 * attempts to load the UI using the key as a class name.
 *
 * @param key The registration key.
 * @return the UI for the given key. The UI may be newly created.
 */
@Override
public synchronized WComponent getUI(final String key) {
    WComponent ui = registry.get(key);
    if (ui == null) {
        // Looks like we haven't tried loading this UI yet, so do it now.
        ui = loadUI(key);
        ui.setLocked(true);
        // Cache the result only if the UI was successfully loaded.
        if (ui instanceof ErrorPage) {
            LOG.debug("Returning non-cached ErrorPage WComponent. Key=" + key);
        } else {
            register(key, ui);
            LOG.debug("Returning cached WComponent. Key=" + key);
        }
    } else {
        LOG.debug("Returning cached WComponent. Key=" + key);
    }
    return ui;
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) ErrorPage(com.github.bordertech.wcomponents.ErrorPage)

Example 67 with WComponent

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

the class BorderLayoutRenderer method paintChildrenWithConstraint.

/**
 * Paints all the child components with the given constraint.
 *
 * @param children the list of potential children to paint.
 * @param renderContext the RenderContext to paint to.
 * @param constraint the target constraint.
 */
private void paintChildrenWithConstraint(final List<Duplet<WComponent, BorderLayoutConstraint>> children, final WebXmlRenderContext renderContext, final BorderLayoutConstraint constraint) {
    String containingTag = null;
    XmlStringBuilder xml = renderContext.getWriter();
    final int size = children.size();
    for (int i = 0; i < size; i++) {
        Duplet<WComponent, BorderLayoutConstraint> child = children.get(i);
        if (constraint.equals(child.getSecond())) {
            if (containingTag == null) {
                containingTag = getTag(constraint);
                xml.appendTag(containingTag);
            }
            child.getFirst().paint(renderContext);
        }
    }
    if (containingTag != null) {
        xml.appendEndTag(containingTag);
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) BorderLayoutConstraint(com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint) BorderLayoutConstraint(com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint)

Example 68 with WComponent

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

the class BorderLayoutRenderer 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();
    BorderLayout layout = (BorderLayout) panel.getLayout();
    Size hgap = layout.getHorizontalGap();
    String hgapString = hgap == null ? null : hgap.toString();
    Size vgap = layout.getVerticalGap();
    String vgapString = vgap == null ? null : vgap.toString();
    xml.appendTagOpen("ui:borderlayout");
    xml.appendOptionalAttribute("hgap", hgapString);
    xml.appendOptionalAttribute("vgap", vgapString);
    xml.appendClose();
    // Fetch the children and their constraints.
    final int childCount = panel.getChildCount();
    List<Duplet<WComponent, BorderLayoutConstraint>> children = new ArrayList<>(childCount);
    for (int i = 0; i < childCount; i++) {
        WComponent child = panel.getChildAt(i);
        children.add(new Duplet<>(child, getConstraints(panel, child)));
    }
    // Now paint them
    paintChildrenWithConstraint(children, renderContext, BorderLayout.NORTH);
    paintChildrenWithConstraint(children, renderContext, BorderLayout.EAST);
    paintChildrenWithConstraint(children, renderContext, BorderLayout.SOUTH);
    paintChildrenWithConstraint(children, renderContext, BorderLayout.WEST);
    paintChildrenWithConstraint(children, renderContext, BorderLayout.CENTER);
    xml.appendEndTag("ui:borderlayout");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Duplet(com.github.bordertech.wcomponents.util.Duplet) BorderLayout(com.github.bordertech.wcomponents.layout.BorderLayout) Size(com.github.bordertech.wcomponents.Size) WPanel(com.github.bordertech.wcomponents.WPanel) ArrayList(java.util.ArrayList) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) BorderLayoutConstraint(com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint)

Example 69 with WComponent

use of com.github.bordertech.wcomponents.WComponent 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 70 with WComponent

use of com.github.bordertech.wcomponents.WComponent 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)

Aggregations

WComponent (com.github.bordertech.wcomponents.WComponent)107 Test (org.junit.Test)35 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)30 UIContext (com.github.bordertech.wcomponents.UIContext)20 SystemException (com.github.bordertech.wcomponents.util.SystemException)16 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)14 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)8 WApplication (com.github.bordertech.wcomponents.WApplication)8 WLabel (com.github.bordertech.wcomponents.WLabel)8 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)7 IOException (java.io.IOException)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)5 PrintWriter (java.io.PrintWriter)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Size (com.github.bordertech.wcomponents.Size)4 WRepeater (com.github.bordertech.wcomponents.WRepeater)4 WText (com.github.bordertech.wcomponents.WText)4 WTextField (com.github.bordertech.wcomponents.WTextField)4