Search in sources :

Example 31 with XmlStringBuilder

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

the class WTableRowRendererRenderer method renderChildren.

/**
 * @param renderer the WTableRowRenderer to paint.
 * @param renderContext the RenderContext to paint to.
 * @param children the children ids
 */
private void renderChildren(final WTableRowRenderer renderer, final WebXmlRenderContext renderContext, final List<RowIdWrapper> children) {
    XmlStringBuilder xml = renderContext.getWriter();
    WTable table = renderer.getTable();
    WRepeater repeater = table.getRepeater();
    TableModel dataModel = table.getTableModel();
    // If there is a renderer specified by any child, we only paint content that has a specified renderer
    boolean rendererPresent = false;
    for (RowIdWrapper child : children) {
        if (dataModel.getRendererClass(child.getRowIndex()) != null) {
            rendererPresent = true;
            break;
        }
    }
    // Paint immediate children only.
    if (rendererPresent) {
        xml.appendTagOpen("ui:content");
        // Always span all columns
        xml.appendAttribute("spanAllCols", "true");
        xml.appendClose();
        for (RowIdWrapper child : children) {
            UIContext nodeContext = repeater.getRowContext(child, child.getPosition());
            WComponent expandedRenderer = renderer.getExpandedTreeNodeRenderer(dataModel.getRendererClass(child.getRowIndex()));
            if (expandedRenderer != null) {
                UIContextHolder.pushContext(nodeContext);
                try {
                    expandedRenderer.paint(renderContext);
                } finally {
                    UIContextHolder.popContext();
                }
            }
        }
        xml.appendEndTag("ui:content");
    } else {
        for (RowIdWrapper child : children) {
            UIContext nodeContext = repeater.getRowContext(child, child.getPosition());
            UIContextHolder.pushContext(nodeContext);
            try {
                render(renderer, renderContext);
            } finally {
                UIContextHolder.popContext();
            }
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) WTable(com.github.bordertech.wcomponents.WTable) UIContext(com.github.bordertech.wcomponents.UIContext) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WRepeater(com.github.bordertech.wcomponents.WRepeater) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Example 32 with XmlStringBuilder

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

the class WTableRowRendererRenderer method doRender.

/**
 * Paints the given WTableRowRenderer.
 *
 * @param component the WTableRowRenderer to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTableRowRenderer renderer = (WTableRowRenderer) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WTable table = renderer.getTable();
    TableModel dataModel = table.getTableModel();
    int[] columnOrder = table.getColumnOrder();
    final int numCols = columnOrder == null ? table.getColumnCount() : columnOrder.length;
    // Get current row details
    RowIdWrapper wrapper = renderer.getCurrentRowIdWrapper();
    List<Integer> rowIndex = wrapper.getRowIndex();
    boolean tableSelectable = table.getSelectMode() != SelectMode.NONE;
    boolean rowSelectable = tableSelectable && dataModel.isSelectable(rowIndex);
    boolean rowSelected = rowSelectable && table.getSelectedRows().contains(wrapper.getRowKey());
    boolean tableExpandable = table.getExpandMode() != WTable.ExpandMode.NONE;
    boolean rowExpandable = tableExpandable && dataModel.isExpandable(rowIndex) && wrapper.hasChildren();
    boolean rowExpanded = rowExpandable && table.getExpandedRows().contains(wrapper.getRowKey());
    String rowIndexAsString = TableUtil.rowIndexListToString(rowIndex);
    xml.appendTagOpen("ui:tr");
    xml.appendAttribute("rowIndex", rowIndexAsString);
    xml.appendOptionalAttribute("unselectable", !rowSelectable, "true");
    xml.appendOptionalAttribute("selected", rowSelected, "true");
    xml.appendOptionalAttribute("expandable", rowExpandable && !rowExpanded, "true");
    xml.appendClose();
    // wrote the column cell.
    // need this before we get into the loop
    boolean isRowHeader = table.isRowHeaders();
    for (int i = 0; i < numCols; i++) {
        int colIndex = columnOrder == null ? i : columnOrder[i];
        WTableColumn col = table.getColumn(colIndex);
        String cellTag = "ui:td";
        if (col.isVisible()) {
            if (isRowHeader) {
                // The first rendered column will be the row header.
                cellTag = "ui:th";
                // only set one col as the row header.
                isRowHeader = false;
            }
            xml.appendTag(cellTag);
            renderer.getRenderer(colIndex).paint(renderContext);
            xml.appendEndTag(cellTag);
        }
    }
    if (rowExpandable) {
        xml.appendTagOpen("ui:subtr");
        xml.appendOptionalAttribute("open", rowExpanded, "true");
        xml.appendClose();
        if (rowExpanded || table.getExpandMode() == ExpandMode.CLIENT) {
            renderChildren(renderer, renderContext, wrapper.getChildren());
        }
        xml.appendEndTag("ui:subtr");
    }
    xml.appendEndTag("ui:tr");
}
Also used : RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) WTableRowRenderer(com.github.bordertech.wcomponents.WTableRowRenderer) WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Example 33 with XmlStringBuilder

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

the class WTimeoutWarningRenderer method doRender.

/**
 * Paints the given WTimeoutWarning if the component's timeout period is greater than 0.
 *
 * @param component the WTimeoutWarning to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTimeoutWarning warning = (WTimeoutWarning) component;
    XmlStringBuilder xml = renderContext.getWriter();
    final int timoutPeriod = warning.getTimeoutPeriod();
    if (timoutPeriod > 0) {
        xml.appendTagOpen("ui:session");
        xml.appendAttribute("timeout", String.valueOf(timoutPeriod));
        int warningPeriod = warning.getWarningPeriod();
        xml.appendOptionalAttribute("warn", warningPeriod > 0, warningPeriod);
        xml.appendEnd();
    }
}
Also used : WTimeoutWarning(com.github.bordertech.wcomponents.WTimeoutWarning) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 34 with XmlStringBuilder

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

the class WTreeRenderer method doRender.

/**
 * Paints the given WTree.
 *
 * @param component the WTree to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTree tree = (WTree) component;
    XmlStringBuilder xml = renderContext.getWriter();
    // Check if rendering an open item request
    String openId = tree.getOpenRequestItemId();
    if (openId != null) {
        handleOpenItemRequest(tree, xml, openId);
        return;
    }
    // Check the tree has tree items (WCAG requirement)
    TreeItemModel model = tree.getTreeModel();
    if (model == null || model.getRowCount() <= 0) {
        LOG.warn("Tree not rendered as it has no items.");
        return;
    }
    xml.appendTagOpen("ui:tree");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("htree", WTree.Type.HORIZONTAL == tree.getType(), "true");
    xml.appendOptionalAttribute("multiple", WTree.SelectMode.MULTIPLE == tree.getSelectMode(), "true");
    xml.appendOptionalAttribute("disabled", tree.isDisabled(), "true");
    xml.appendOptionalAttribute("hidden", tree.isHidden(), "true");
    xml.appendOptionalAttribute("required", tree.isMandatory(), "true");
    switch(tree.getExpandMode()) {
        case CLIENT:
            xml.appendAttribute("mode", "client");
            break;
        case DYNAMIC:
            xml.appendAttribute("mode", "dynamic");
            break;
        case LAZY:
            xml.appendAttribute("mode", "lazy");
            break;
        default:
            throw new IllegalStateException("Invalid expand mode: " + tree.getType());
    }
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(tree, renderContext);
    if (tree.getCustomTree() == null) {
        handlePaintItems(tree, xml);
    } else {
        handlePaintCustom(tree, xml);
    }
    DiagnosticRenderUtil.renderDiagnostics(tree, renderContext);
    xml.appendEndTag("ui:tree");
}
Also used : WTree(com.github.bordertech.wcomponents.WTree) TreeItemModel(com.github.bordertech.wcomponents.TreeItemModel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 35 with XmlStringBuilder

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

the class WValidationErrorsRenderer method doRender.

/**
 * Paints the given {@link WValidationErrors} component.
 *
 * @param component The {@link WValidationErrors} component to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WValidationErrors errors = (WValidationErrors) component;
    XmlStringBuilder xml = renderContext.getWriter();
    if (errors.hasErrors()) {
        xml.appendTagOpen("ui:validationerrors");
        xml.appendAttribute("id", component.getId());
        xml.appendOptionalAttribute("class", component.getHtmlClass());
        xml.appendOptionalAttribute("track", component.isTracking(), "true");
        xml.appendOptionalAttribute("title", errors.getTitleText());
        xml.appendClose();
        for (GroupedDiagnositcs nextGroup : errors.getGroupedErrors()) {
            // Render each diagnostic message in this group.
            for (Diagnostic nextMessage : nextGroup.getDiagnostics()) {
                xml.appendTagOpen("ui:error");
                WComponent forComponent = nextMessage.getComponent();
                if (forComponent != null) {
                    UIContextHolder.pushContext(nextMessage.getContext());
                    try {
                        xml.appendAttribute("for", forComponent.getId());
                    } finally {
                        UIContextHolder.popContext();
                    }
                }
                xml.appendClose();
                // of a WComponent as the message.
                if (nextMessage instanceof DiagnosticImpl) {
                    WComponent messageComponent = ((DiagnosticImpl) nextMessage).createDiagnosticErrorComponent();
                    // We add the component to a throw-away container so that it renders with the correct ID.
                    WContainer container = new WContainer() {

                        @Override
                        public String getId() {
                            return component.getId();
                        }
                    };
                    container.add(messageComponent);
                    messageComponent.paint(renderContext);
                    container.remove(messageComponent);
                    container.reset();
                } else {
                    xml.append(nextMessage.getDescription());
                }
                xml.appendEndTag("ui:error");
            }
        }
        xml.appendEndTag("ui:validationerrors");
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WContainer(com.github.bordertech.wcomponents.WContainer) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors) GroupedDiagnositcs(com.github.bordertech.wcomponents.validation.WValidationErrors.GroupedDiagnositcs) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) 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