Search in sources :

Example 1 with WTableRowRenderer

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

Aggregations

WTable (com.github.bordertech.wcomponents.WTable)1 RowIdWrapper (com.github.bordertech.wcomponents.WTable.RowIdWrapper)1 TableModel (com.github.bordertech.wcomponents.WTable.TableModel)1 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)1 WTableRowRenderer (com.github.bordertech.wcomponents.WTableRowRenderer)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1