Search in sources :

Example 26 with XmlStringBuilder

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

the class WTabSetRenderer method doRender.

/**
 * Paints the given WTabSet.
 *
 * @param component the WTabSet to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTabSet tabSet = (WTabSet) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:tabset");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendAttribute("type", getTypeAsString(tabSet.getType()));
    xml.appendOptionalAttribute("disabled", tabSet.isDisabled(), "true");
    xml.appendOptionalAttribute("hidden", tabSet.isHidden(), "true");
    xml.appendOptionalAttribute("contentHeight", tabSet.getContentHeight());
    xml.appendOptionalAttribute("showHeadOnly", tabSet.isShowHeadOnly(), "true");
    xml.appendOptionalAttribute("single", TabSetType.ACCORDION.equals(tabSet.getType()) && tabSet.isSingle(), "true");
    if (WTabSet.TabSetType.ACCORDION.equals(tabSet.getType())) {
        xml.appendOptionalAttribute("groupName", tabSet.getGroupName());
    }
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(tabSet, renderContext);
    paintChildren(tabSet, renderContext);
    xml.appendEndTag("ui:tabset");
}
Also used : XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WTabSet(com.github.bordertech.wcomponents.WTabSet)

Example 27 with XmlStringBuilder

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

the class WTableRenderer method paintColumnHeadings.

/**
 * Paints the column headings for the given table.
 *
 * @param table the table to paint the headings for.
 * @param renderContext the RenderContext to paint to.
 */
private void paintColumnHeadings(final WTable table, final WebXmlRenderContext renderContext) {
    XmlStringBuilder xml = renderContext.getWriter();
    int[] columnOrder = table.getColumnOrder();
    TableModel model = table.getTableModel();
    final int columnCount = columnOrder == null ? table.getColumnCount() : columnOrder.length;
    xml.appendTagOpen("ui:thead");
    xml.appendOptionalAttribute("hidden", !table.isShowColumnHeaders(), "true");
    xml.appendClose();
    for (int i = 0; i < columnCount; i++) {
        int colIndex = columnOrder == null ? i : columnOrder[i];
        WTableColumn col = table.getColumn(colIndex);
        if (col.isVisible()) {
            boolean sortable = model.isSortable(colIndex);
            paintColumnHeading(col, sortable, renderContext);
        }
    }
    xml.appendEndTag("ui:thead");
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Example 28 with XmlStringBuilder

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

the class WTableRenderer method doRender.

@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTable table = (WTable) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:table");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", table.isHidden(), "true");
    xml.appendOptionalAttribute("caption", table.getCaption());
    switch(table.getType()) {
        case TABLE:
            xml.appendAttribute("type", "table");
            break;
        case HIERARCHIC:
            xml.appendAttribute("type", "hierarchic");
            break;
        default:
            throw new SystemException("Unknown table type: " + table.getType());
    }
    switch(table.getStripingType()) {
        case ROWS:
            xml.appendAttribute("striping", "rows");
            break;
        case COLUMNS:
            xml.appendAttribute("striping", "cols");
            break;
        case NONE:
            break;
        default:
            throw new SystemException("Unknown striping type: " + table.getStripingType());
    }
    switch(table.getSeparatorType()) {
        case HORIZONTAL:
            xml.appendAttribute("separators", "horizontal");
            break;
        case VERTICAL:
            xml.appendAttribute("separators", "vertical");
            break;
        case BOTH:
            xml.appendAttribute("separators", "both");
            break;
        case NONE:
            break;
        default:
            throw new SystemException("Unknown separator type: " + table.getSeparatorType());
    }
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(table, renderContext);
    if (table.getPaginationMode() != PaginationMode.NONE) {
        paintPaginationDetails(table, xml);
    }
    if (table.getSelectMode() != SelectMode.NONE) {
        paintSelectionDetails(table, xml);
    }
    if (table.getExpandMode() != ExpandMode.NONE) {
        paintExpansionDetails(table, xml);
    }
    if (table.isSortable()) {
        paintSortDetails(table, xml);
    }
    paintColumnHeadings(table, renderContext);
    paintRows(table, renderContext);
    paintTableActions(table, renderContext);
    xml.appendEndTag("ui:table");
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) WTable(com.github.bordertech.wcomponents.WTable) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 29 with XmlStringBuilder

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

the class WTableRenderer method paintColumnHeading.

/**
 * Paints a single column heading.
 *
 * @param col the column to paint.
 * @param sortable true if the column is sortable, false otherwise
 * @param renderContext the RenderContext to paint to.
 */
private void paintColumnHeading(final WTableColumn col, final boolean sortable, final WebXmlRenderContext renderContext) {
    XmlStringBuilder xml = renderContext.getWriter();
    int width = col.getWidth();
    Alignment align = col.getAlign();
    xml.appendTagOpen("ui:th");
    xml.appendOptionalAttribute("width", width > 0, width);
    xml.appendOptionalAttribute("sortable", sortable, "true");
    if (Alignment.RIGHT.equals(align)) {
        xml.appendAttribute("align", "right");
    } else if (Alignment.CENTER.equals(align)) {
        xml.appendAttribute("align", "center");
    }
    xml.appendClose();
    col.paint(renderContext);
    xml.appendEndTag("ui:th");
}
Also used : Alignment(com.github.bordertech.wcomponents.WTableColumn.Alignment) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 30 with XmlStringBuilder

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

the class WTableRenderer method paintTableActions.

/**
 * Paints the table actions of the table.
 *
 * @param table the table to paint the table actions for.
 * @param renderContext the RenderContext to paint to.
 */
private void paintTableActions(final WTable table, final WebXmlRenderContext renderContext) {
    XmlStringBuilder xml = renderContext.getWriter();
    List<WButton> tableActions = table.getActions();
    if (!tableActions.isEmpty()) {
        boolean hasActions = false;
        for (WButton button : tableActions) {
            if (!button.isVisible()) {
                continue;
            }
            if (!hasActions) {
                hasActions = true;
                xml.appendTag("ui:actions");
            }
            xml.appendTag("ui:action");
            List<WTable.ActionConstraint> constraints = table.getActionConstraints(button);
            if (constraints != null) {
                for (WTable.ActionConstraint constraint : constraints) {
                    int minRows = constraint.getMinSelectedRowCount();
                    int maxRows = constraint.getMaxSelectedRowCount();
                    String message = constraint.getMessage();
                    String type = constraint.isError() ? "error" : "warning";
                    xml.appendTagOpen("ui:condition");
                    xml.appendOptionalAttribute("minSelectedRows", minRows > 0, minRows);
                    xml.appendOptionalAttribute("maxSelectedRows", maxRows > 0, maxRows);
                    xml.appendAttribute("selectedOnOther", this.selectedOnOther);
                    xml.appendAttribute("type", type);
                    xml.appendAttribute("message", I18nUtilities.format(null, message));
                    xml.appendEnd();
                }
            }
            button.paint(renderContext);
            xml.appendEndTag("ui:action");
        }
        if (hasActions) {
            xml.appendEndTag("ui:actions");
        }
    }
}
Also used : WTable(com.github.bordertech.wcomponents.WTable) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WButton(com.github.bordertech.wcomponents.WButton)

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