Search in sources :

Example 36 with XmlStringBuilder

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

the class AjaxInterceptor method paintResponse.

/**
 * Paint the ajax response.
 *
 * @param renderContext the render context
 * @param operation the ajax operation
 */
private void paintResponse(final RenderContext renderContext, final AjaxOperation operation) {
    WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
    XmlStringBuilder xml = webRenderContext.getWriter();
    // Get trigger's context
    ComponentWithContext trigger = AjaxHelper.getCurrentTriggerAndContext();
    if (trigger == null) {
        throw new SystemException("No context available for trigger " + operation.getTriggerId());
    }
    for (String targetId : operation.getTargets()) {
        ComponentWithContext target;
        if (targetId.equals(operation.getTriggerId())) {
            target = trigger;
        } else {
            target = WebUtilities.getComponentById(targetId, true);
            if (target == null) {
                LOG.warn("Could not find ajax target to render [" + targetId + "]");
                continue;
            }
        }
        UIContextHolder.pushContext(target.getContext());
        try {
            xml.appendTagOpen("ui:ajaxtarget");
            xml.appendAttribute("id", targetId);
            xml.appendAttribute("action", operation.getAction().getDesc());
            xml.appendClose();
            target.getComponent().paint(renderContext);
            xml.appendEndTag("ui:ajaxtarget");
        } finally {
            UIContextHolder.popContext();
        }
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) SystemException(com.github.bordertech.wcomponents.util.SystemException) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 37 with XmlStringBuilder

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

the class DebugStructureInterceptor method paint.

/**
 * Override paint to render additional information for debugging purposes.
 *
 * @param renderContext the renderContext to send the output to.
 */
@Override
public void paint(final RenderContext renderContext) {
    super.paint(renderContext);
    if (!DebugUtil.isDebugFeaturesEnabled() || !(renderContext instanceof WebXmlRenderContext)) {
        return;
    }
    XmlStringBuilder xml = ((WebXmlRenderContext) renderContext).getWriter();
    xml.appendTag("ui:debug");
    writeDebugInfo(getUI(), xml);
    xml.appendEndTag("ui:debug");
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 38 with XmlStringBuilder

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

the class AbstractWFieldIndicatorRenderer method doRender.

/**
 * Paints the given AbstractWFieldIndicator.
 *
 * @param component the WFieldErrorIndicator to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    AbstractWFieldIndicator fieldIndicator = (AbstractWFieldIndicator) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WComponent validationTarget = fieldIndicator.getTargetComponent();
    // Diagnosables takes care of thieir own  messaging.
    if (validationTarget == null || (validationTarget instanceof Diagnosable && !(validationTarget instanceof Input))) {
        return;
    }
    if (validationTarget instanceof Input && !((Input) validationTarget).isReadOnly()) {
        return;
    }
    List<Diagnostic> diags = fieldIndicator.getDiagnostics();
    if (diags != null && !diags.isEmpty()) {
        xml.appendTagOpen("ui:fieldindicator");
        xml.appendAttribute("id", component.getId());
        xml.appendOptionalAttribute("track", component.isTracking(), "true");
        switch(fieldIndicator.getFieldIndicatorType()) {
            case INFO:
                xml.appendAttribute("type", "info");
                break;
            case WARN:
                xml.appendAttribute("type", "warn");
                break;
            case ERROR:
                xml.appendAttribute("type", "error");
                break;
            default:
                throw new SystemException("Cannot paint field indicator due to an invalid field indicator type: " + fieldIndicator.getFieldIndicatorType());
        }
        xml.appendAttribute("for", fieldIndicator.getRelatedFieldId());
        xml.appendClose();
        for (Diagnostic diag : diags) {
            xml.appendTag("ui:message");
            xml.appendEscaped(diag.getDescription());
            xml.appendEndTag("ui:message");
        }
        xml.appendEndTag("ui:fieldindicator");
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) AbstractWFieldIndicator(com.github.bordertech.wcomponents.validation.AbstractWFieldIndicator) Input(com.github.bordertech.wcomponents.Input) SystemException(com.github.bordertech.wcomponents.util.SystemException) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) Diagnosable(com.github.bordertech.wcomponents.Diagnosable)

Example 39 with XmlStringBuilder

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

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

the class WAbbrTextRenderer method doRender.

/**
 * Paints the given WAbbrText.
 *
 * @param component the WAbbrText to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WAbbrText abbrText = (WAbbrText) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("abbr");
    xml.appendOptionalAttribute("title", abbrText.getToolTip());
    xml.appendOptionalAttribute("class", abbrText.getHtmlClass());
    xml.appendClose();
    xml.append(abbrText.getText(), abbrText.isEncodeText());
    xml.appendEndTag("abbr");
}
Also used : WAbbrText(com.github.bordertech.wcomponents.WAbbrText) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

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