Search in sources :

Example 1 with WTableColumn

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

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

the class WDataTableRowRendererRenderer method doRender.

/**
 * Paints the given WDataTableRowRenderer.
 *
 * @param component the WDataTableRowRenderer to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WDataTableRowRenderer renderer = (WDataTableRowRenderer) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WDataTable table = renderer.getTable();
    TableDataModel dataModel = table.getDataModel();
    UIContext uic = UIContextHolder.getCurrent();
    final int numCols = table.getColumnCount();
    int[] columnOrder = table.getColumnOrder();
    int rowIndex = getRowIndex(table, (SubUIContext) uic);
    boolean unselectable = table.getSelectMode() != SelectMode.NONE && !dataModel.isSelectable(rowIndex);
    xml.appendTagOpen("ui:tr");
    xml.appendAttribute("rowIndex", rowIndex);
    xml.appendOptionalAttribute("unselectable", unselectable, "true");
    xml.appendOptionalAttribute("selected", table.getSelectedRows().contains(rowIndex), "true");
    xml.appendOptionalAttribute("filterValues", getFilterValues(dataModel, rowIndex));
    if (table.getExpandMode() != WDataTable.ExpandMode.NONE && dataModel instanceof TreeTableDataModel) {
        TableTreeNode node = ((TreeTableDataModel) dataModel).getNodeAtLine(rowIndex);
        boolean expandable = !node.isLeaf() && !node.isExpanded();
        xml.appendOptionalAttribute("expandable", expandable, "true");
    }
    xml.appendClose();
    if (table.isShowRowHeaders()) {
        xml.appendTag("ui:th");
        renderer.getRowHeader().paint(renderContext);
        xml.appendEndTag("ui:th");
    }
    for (int i = 0; i < numCols; i++) {
        int colIndex = columnOrder == null ? i : columnOrder[i];
        WTableColumn col = table.getColumn(colIndex);
        if (col.isVisible()) {
            xml.appendTag("ui:td");
            renderer.getRenderer(colIndex).paint(renderContext);
            xml.appendEndTag("ui:td");
        }
    }
    if (table.getExpandMode() != WDataTable.ExpandMode.NONE && dataModel instanceof TreeTableDataModel) {
        TreeTableDataModel treeModel = (TreeTableDataModel) dataModel;
        TableTreeNode node = treeModel.getNodeAtLine(rowIndex);
        if (!node.isLeaf()) {
            xml.appendTagOpen("ui:subtr");
            xml.appendOptionalAttribute("open", node.isExpanded(), "true");
            xml.appendClose();
            if (node.isExpanded() || table.getExpandMode() == ExpandMode.CLIENT) {
                WRepeater repeater = table.getRepeater();
                // If there a renderer specified by any child, we only paint content that has a specified renderer
                boolean rendererPresent = false;
                for (Iterator<TreeNode> i = node.children(); !rendererPresent && i.hasNext(); ) {
                    TableTreeNode child = (TableTreeNode) i.next();
                    if (child.getRendererClass() != null) {
                        rendererPresent = true;
                    }
                }
                // Paint immediate children only.
                if (rendererPresent) {
                    xml.appendTagOpen("ui:content");
                    xml.appendOptionalAttribute("spanAllCols", node.isRendererSpansAllCols(), "true");
                    xml.appendClose();
                    for (Iterator<TreeNode> i = node.children(); i.hasNext(); ) {
                        TableTreeNode child = (TableTreeNode) i.next();
                        Integer rowId = child.getRowIndex() - 1;
                        UIContext nodeContext = repeater.getRowContext(rowId);
                        WComponent expandedRenderer = renderer.getExpandedTreeNodeRenderer(child.getRendererClass());
                        if (expandedRenderer != null) {
                            UIContextHolder.pushContext(nodeContext);
                            try {
                                expandedRenderer.paint(renderContext);
                            } finally {
                                UIContextHolder.popContext();
                            }
                        }
                    }
                    xml.appendEndTag("ui:content");
                } else {
                    for (Iterator<TreeNode> i = node.children(); i.hasNext(); ) {
                        TableTreeNode child = (TableTreeNode) i.next();
                        Integer rowId = child.getRowIndex() - 1;
                        UIContext nodeContext = repeater.getRowContext(rowId);
                        UIContextHolder.pushContext(nodeContext);
                        try {
                            render(component, renderContext);
                        } finally {
                            UIContextHolder.popContext();
                        }
                    }
                }
            }
            xml.appendEndTag("ui:subtr");
        }
    }
    xml.appendEndTag("ui:tr");
}
Also used : TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) UIContext(com.github.bordertech.wcomponents.UIContext) SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WRepeater(com.github.bordertech.wcomponents.WRepeater) WComponent(com.github.bordertech.wcomponents.WComponent) WDataTable(com.github.bordertech.wcomponents.WDataTable) TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) TreeNode(com.github.bordertech.wcomponents.util.TreeNode) WDataTableRowRenderer(com.github.bordertech.wcomponents.WDataTableRowRenderer) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 3 with WTableColumn

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

the class WDataTableRenderer 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 WDataTable table, final WebXmlRenderContext renderContext) {
    XmlStringBuilder xml = renderContext.getWriter();
    int[] columnOrder = table.getColumnOrder();
    TableDataModel model = table.getDataModel();
    final int columnCount = table.getColumnCount();
    xml.appendTagOpen("ui:thead");
    xml.appendOptionalAttribute("hidden", !table.isShowColumnHeaders(), "true");
    xml.appendClose();
    if (table.isShowRowHeaders()) {
        paintColumnHeading(table.getRowHeaderColumn(), false, renderContext);
    }
    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) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 4 with WTableColumn

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

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

the class WTableRenderer method paintColumnHeaderFooter.

/**
 * Paints the column headings for the given table.
 *
 * @param table the table to paint the headings for.
 * @param renderContext the RenderContext to paint to.
 * @param renderHeaders true if rendering headers otherwise render footers
 */
private void paintColumnHeaderFooter(final WTable table, final WebXmlRenderContext renderContext, final boolean renderHeaders) {
    XmlStringBuilder xml = renderContext.getWriter();
    int[] columnOrder = table.getColumnOrder();
    TableModel model = table.getTableModel();
    final int columnCount = columnOrder == null ? table.getColumnCount() : columnOrder.length;
    if (renderHeaders) {
        // Headers
        xml.appendTagOpen("ui:thead");
        xml.appendOptionalAttribute("hidden", !table.isShowColumnHeaders(), "true");
        xml.appendClose();
    } else {
        // Footers
        xml.appendTag("tfoot");
        xml.appendTag("tr");
        // Allow for expandable column
        if (table.getExpandMode() != ExpandMode.NONE) {
            xml.appendTag("td");
            xml.appendEndTag("td");
        }
        // Allow for selectable column
        if (table.getSelectMode() != SelectMode.NONE) {
            xml.appendTag("td");
            xml.appendEndTag("td");
        }
    }
    for (int i = 0; i < columnCount; i++) {
        int colIndex = columnOrder == null ? i : columnOrder[i];
        WTableColumn col = table.getColumn(colIndex);
        if (col.isVisible()) {
            if (renderHeaders) {
                // Header
                boolean sortable = model.isSortable(colIndex);
                paintColumnHeading(col, sortable, renderContext);
            } else {
                // Footer
                paintColumnFooting(col, renderContext);
            }
        }
    }
    if (renderHeaders) {
        xml.appendEndTag("ui:thead");
    } else {
        xml.appendEndTag("tr");
        xml.appendEndTag("tfoot");
    }
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Aggregations

WTableColumn (com.github.bordertech.wcomponents.WTableColumn)76 WTextField (com.github.bordertech.wcomponents.WTextField)62 Test (org.junit.Test)57 WDataTable (com.github.bordertech.wcomponents.WDataTable)38 WTable (com.github.bordertech.wcomponents.WTable)32 TableModel (com.github.bordertech.wcomponents.WTable.TableModel)27 AdapterBasicTableModel (com.github.bordertech.wcomponents.AdapterBasicTableModel)24 SimpleTableModel (com.github.bordertech.wcomponents.SimpleTableModel)24 TableDataModel (com.github.bordertech.wcomponents.TableDataModel)24 SimpleTableDataModel (com.github.bordertech.wcomponents.SimpleTableDataModel)23 WText (com.github.bordertech.wcomponents.WText)11 WButton (com.github.bordertech.wcomponents.WButton)8 WDateField (com.github.bordertech.wcomponents.WDateField)7 TableTreeNode (com.github.bordertech.wcomponents.TableTreeNode)5 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)5 ActionConstraint (com.github.bordertech.wcomponents.WDataTable.ActionConstraint)4 ActionConstraint (com.github.bordertech.wcomponents.WTable.ActionConstraint)4 UIContext (com.github.bordertech.wcomponents.UIContext)3 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2