Search in sources :

Example 1 with TreeTableDataModel

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

the class WDataTableRenderer method paintPaginationElement.

/**
 * Paint the pagination aspects of the WDataTable.
 * @param table the WDataTable being rendered
 * @param xml the string builder in use
 */
private void paintPaginationElement(final WDataTable table, final XmlStringBuilder xml) {
    TableDataModel model = table.getDataModel();
    xml.appendTagOpen("ui:pagination");
    if (model instanceof TreeTableDataModel) {
        // For tree tables, we only include top-level nodes for pagination.
        TreeNode firstNode = ((TreeTableDataModel) model).getNodeAtLine(0);
        xml.appendAttribute("rows", firstNode == null ? 0 : firstNode.getParent().getChildCount());
    } else {
        xml.appendAttribute("rows", model.getRowCount());
    }
    xml.appendAttribute("rowsPerPage", table.getRowsPerPage());
    xml.appendAttribute("currentPage", table.getCurrentPage());
    switch(table.getPaginationMode()) {
        case CLIENT:
            xml.appendAttribute("mode", "client");
            break;
        case DYNAMIC:
        case SERVER:
            xml.appendAttribute("mode", "dynamic");
            break;
        case NONE:
            break;
        default:
            throw new SystemException("Unknown pagination mode: " + table.getPaginationMode());
    }
    xml.appendEnd();
}
Also used : TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) SystemException(com.github.bordertech.wcomponents.util.SystemException) TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) TreeNode(com.github.bordertech.wcomponents.util.TreeNode) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel)

Example 2 with TreeTableDataModel

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

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

the class DataTableOptionsExample method copySelection.

/**
 * @param table the table with selected items
 * @param selected the text field that will contain a copy of the selected item details
 */
private void copySelection(final WDataTable table, final WText selected) {
    List<Integer> rows = table.getSelectedRows();
    if (rows.isEmpty()) {
        selected.setText("No Rows Selected");
    } else {
        StringBuffer out = new StringBuffer("Selected: ");
        TableDataModel data = table.getDataModel();
        boolean firstRow = true;
        for (Integer rowIdx : rows) {
            if (firstRow) {
                firstRow = false;
            } else {
                out.append(", ");
            }
            ExampleBean bean;
            if (data instanceof TreeTableDataModel) {
                TableTreeNode node = ((TreeTableDataModel) data).getNodeAtLine(rowIdx.intValue());
                bean = (ExampleBean) node.getData();
            } else {
                ExampleDataModel node = (ExampleDataModel) data;
                bean = node.getData().get(rowIdx.intValue());
            }
            out.append(bean.getColumn1());
        }
        selected.setText(out.toString());
    }
}
Also used : TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) AbstractTreeTableDataModel(com.github.bordertech.wcomponents.AbstractTreeTableDataModel) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) AbstractTableDataModel(com.github.bordertech.wcomponents.AbstractTableDataModel) AbstractTreeTableDataModel(com.github.bordertech.wcomponents.AbstractTreeTableDataModel) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel)

Example 4 with TreeTableDataModel

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

the class WDataTableRenderer method doPaintRows.

/**
 * Override paintRow so that we only paint the first-level nodes for tree-tables.
 *
 * @param table the table to paint the rows for.
 * @param renderContext the RenderContext to paint to.
 */
private void doPaintRows(final WDataTable table, final WebXmlRenderContext renderContext) {
    TableDataModel model = table.getDataModel();
    WRepeater repeater = table.getRepeater();
    List<?> beanList = repeater.getBeanList();
    final int rowCount = beanList.size();
    WComponent row = repeater.getRepeatedComponent();
    for (int i = 0; i < rowCount; i++) {
        if (model instanceof TreeTableDataModel) {
            Integer nodeIdx = (Integer) beanList.get(i);
            TableTreeNode node = ((TreeTableDataModel) model).getNodeAtLine(nodeIdx);
            if (node.getLevel() != 1) {
                // Handled by the layout, so don't paint the row.
                continue;
            }
        }
        // Each row has its own context. This is why we can reuse the same
        // WComponent instance for each row.
        UIContext rowContext = repeater.getRowContext(beanList.get(i), i);
        UIContextHolder.pushContext(rowContext);
        try {
            row.paint(renderContext);
        } finally {
            UIContextHolder.popContext();
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) UIContext(com.github.bordertech.wcomponents.UIContext) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) WRepeater(com.github.bordertech.wcomponents.WRepeater)

Aggregations

TableDataModel (com.github.bordertech.wcomponents.TableDataModel)4 TableTreeNode (com.github.bordertech.wcomponents.TableTreeNode)4 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)4 UIContext (com.github.bordertech.wcomponents.UIContext)2 WComponent (com.github.bordertech.wcomponents.WComponent)2 WRepeater (com.github.bordertech.wcomponents.WRepeater)2 TreeNode (com.github.bordertech.wcomponents.util.TreeNode)2 AbstractTableDataModel (com.github.bordertech.wcomponents.AbstractTableDataModel)1 AbstractTreeTableDataModel (com.github.bordertech.wcomponents.AbstractTreeTableDataModel)1 WDataTable (com.github.bordertech.wcomponents.WDataTable)1 WDataTableRowRenderer (com.github.bordertech.wcomponents.WDataTableRowRenderer)1 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)1 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1