Search in sources :

Example 26 with WComponent

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

the class AbstractWebXmlRenderer method paintChildren.

/**
 * Paints the children of the given component.
 *
 * @param container the component whose children will be painted.
 * @param renderContext the context for rendering.
 */
protected final void paintChildren(final Container container, final WebXmlRenderContext renderContext) {
    final int size = container.getChildCount();
    for (int i = 0; i < size; i++) {
        WComponent child = container.getChildAt(i);
        child.paint(renderContext);
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent)

Example 27 with WComponent

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

the class ColumnLayoutRenderer 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();
    ColumnLayout layout = (ColumnLayout) panel.getLayout();
    int childCount = panel.getChildCount();
    Size hgap = layout.getHorizontalGap();
    String hgapString = hgap == null ? null : hgap.toString();
    Size vgap = layout.getVerticalGap();
    String vgapString = vgap == null ? null : vgap.toString();
    int cols = layout.getColumnCount();
    xml.appendTagOpen("ui:columnlayout");
    xml.appendOptionalAttribute("hgap", hgapString);
    xml.appendOptionalAttribute("vgap", vgapString);
    xml.appendClose();
    // Column Definitions
    for (int col = 0; col < cols; col++) {
        xml.appendTagOpen("ui:column");
        int width = layout.getColumnWidth(col);
        xml.appendOptionalAttribute("width", width > 0, width);
        switch(layout.getColumnAlignment(col)) {
            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.getColumnAlignment(col));
        }
        xml.appendEnd();
    }
    for (int i = 0; i < childCount; i++) {
        xml.appendTag("ui:cell");
        WComponent child = panel.getChildAt(i);
        child.paint(renderContext);
        xml.appendEndTag("ui:cell");
    }
    xml.appendEndTag("ui:columnlayout");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Size(com.github.bordertech.wcomponents.Size) WPanel(com.github.bordertech.wcomponents.WPanel) ColumnLayout(com.github.bordertech.wcomponents.layout.ColumnLayout) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 28 with WComponent

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

the class VelocityRenderer method fillContext.

/**
 * Fills the given velocity context with data from the component which is being rendered. A map of components is
 * also built up, in order to support deferred rendering.
 *
 * @param component the current component being rendered.
 * @param context the velocity context to modify.
 * @param componentsByKey a map to store components for deferred rendering.
 */
private void fillContext(final WComponent component, final VelocityContext context, final Map<String, WComponent> componentsByKey) {
    // Also make the component available under the "this" key.
    context.put("this", component);
    // Make the UIContext available under the "uicontext" key.
    UIContext uic = UIContextHolder.getCurrent();
    context.put("uicontext", uic);
    context.put("uic", uic);
    if (component instanceof VelocityProperties) {
        Map<?, ?> map = ((VelocityProperties) component).getVelocityMap();
        for (Map.Entry<?, ?> entry : map.entrySet()) {
            String key = (String) entry.getKey();
            Object value = entry.getValue();
            context.put(key, value);
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Handling children");
    }
    // As well as going into their own named slots, visible children are also
    // placed into a list called children
    ArrayList<String> children = new ArrayList<>();
    if (component instanceof Container) {
        Container container = (Container) component;
        for (int i = 0; i < container.getChildCount(); i++) {
            WComponent child = container.getChildAt(i);
            String tag = child.getTag();
            if (tag != null || child.isVisible()) {
                // The key needs to be something which would never be output by a Velocity template.
                String key = "<VelocityLayout" + child.getId() + "/>";
                componentsByKey.put(key, child);
                if (tag != null) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Adding child " + tag + " to context");
                    }
                    addToContext(context, tag, key);
                }
                if (child.isVisible()) {
                    children.add(key);
                }
            }
        }
        context.put("children", children);
    }
    // Put the context in the context
    context.put("context", context);
}
Also used : AbstractWComponent(com.github.bordertech.wcomponents.AbstractWComponent) WComponent(com.github.bordertech.wcomponents.WComponent) Container(com.github.bordertech.wcomponents.Container) UIContext(com.github.bordertech.wcomponents.UIContext) ArrayList(java.util.ArrayList) VelocityProperties(com.github.bordertech.wcomponents.velocity.VelocityProperties) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with WComponent

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

the class WCheckBoxRenderer method doRender.

/**
 * Paints the given WCheckBox.
 *
 * @param component the WCheckBox to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WCheckBox checkBox = (WCheckBox) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = checkBox.isReadOnly();
    xml.appendTagOpen(TAG_NAME);
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", checkBox.isHidden(), "true");
    xml.appendOptionalAttribute("selected", checkBox.isSelected(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
        xml.appendEnd();
        return;
    }
    WComponent submitControl = checkBox.getDefaultSubmitButton();
    String submitControlId = submitControl == null ? null : submitControl.getId();
    WComponentGroup<WCheckBox> group = checkBox.getGroup();
    String groupName = group == null ? null : group.getId();
    xml.appendOptionalAttribute("groupName", groupName);
    xml.appendOptionalAttribute("disabled", checkBox.isDisabled(), "true");
    xml.appendOptionalAttribute("required", checkBox.isMandatory(), "true");
    xml.appendOptionalAttribute("submitOnChange", checkBox.isSubmitOnChange(), "true");
    xml.appendOptionalAttribute("toolTip", checkBox.getToolTip());
    xml.appendOptionalAttribute("accessibleText", checkBox.getAccessibleText());
    xml.appendOptionalAttribute("buttonId", submitControlId);
    List<Diagnostic> diags = checkBox.getDiagnostics(Diagnostic.ERROR);
    if (diags == null || diags.isEmpty()) {
        xml.appendEnd();
        return;
    }
    xml.appendClose();
    DiagnosticRenderUtil.renderDiagnostics(checkBox, renderContext);
    xml.appendEndTag(TAG_NAME);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 30 with WComponent

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

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