Search in sources :

Example 6 with TableTreeNode

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

the class DataTableOptionsExample method createHierarchicDataTable.

/**
 * @return a hierarchic table
 */
private WDataTable createHierarchicDataTable() {
    WDataTable table = new WDataTable();
    table.setType(WDataTable.Type.HIERARCHIC);
    table.addColumn(new WTableColumn("Column1", WText.class));
    table.addColumn(new WTableColumn("Column2", WText.class));
    table.addColumn(new WTableColumn("Column3", WText.class));
    table.setRowsPerPage(DEFAULT_ROWS_PER_PAGE);
    table.setSummary("Hierarchic table summary");
    table.setCaption("Hierarchic table caption");
    TableTreeNode root = createHierarchicTree();
    table.setDataModel(new ExampleTreeTableModel(root));
    return table;
}
Also used : TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WText(com.github.bordertech.wcomponents.WText) WDataTable(com.github.bordertech.wcomponents.WDataTable)

Example 7 with TableTreeNode

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

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

the class DataTableOptionsExample method createHierarchicTree.

/**
 * @return a tableTreeNode to be used by a hierachic table
 */
private TableTreeNode createHierarchicTree() {
    TableTreeNode root = new TableTreeNode(null);
    TableTreeNode row1 = new TableTreeNode(new ExampleBean("A1", "H2", "G3"));
    TableTreeNode row2 = new TableTreeNode(new ExampleBean("B1", "G2", "E3"));
    TableTreeNode row3 = new TableTreeNode(new ExampleBean("C1", "F2", "C3"));
    TableTreeNode row4 = new TableTreeNode(new ExampleBean("D1", "E2", "A3"));
    TableTreeNode row5 = new TableTreeNode(new ExampleBean("E1", "D2", "B3"));
    TableTreeNode row6 = new TableTreeNode(new ExampleBean("F1", "C2", "D3"));
    TableTreeNode row7 = new TableTreeNode(new ExampleBean("G1", "B2", "F3"));
    TableTreeNode row8 = new TableTreeNode(new ExampleBean("H1", "A2", "H3"));
    TableTreeNode child1 = new TableTreeNode(new ExampleBean("A1-A", "A1-B", "A1-C"));
    TableTreeNode child2 = new TableTreeNode(new ExampleBean("C1-A", "C1-B", "C1-C"));
    TableTreeNode child3 = new TableTreeNode(new ExampleBean("C2-A", "C2-B", "C2-C"));
    TableTreeNode child4 = new TableTreeNode(new ExampleBean("G1-A", "G1-B", "G1-C"));
    root.add(row1);
    root.add(row2);
    root.add(row3);
    root.add(row4);
    root.add(row5);
    root.add(row6);
    root.add(row7);
    root.add(row8);
    row1.add(child1);
    row3.add(child2);
    row3.add(child3);
    row7.add(child4);
    return root;
}
Also used : TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode)

Example 9 with TableTreeNode

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

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

the class TreeTableExample method preparePaintComponent.

/**
 * {@inheritDoc}
 */
@Override
protected void preparePaintComponent(final Request request) {
    super.preparePaintComponent(request);
    if (!isInitialised()) {
        TableTreeNode root = createTree();
        table.setDataModel(new ExampleTreeTableModel(root));
        setInitialised(true);
    }
}
Also used : TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode)

Aggregations

TableTreeNode (com.github.bordertech.wcomponents.TableTreeNode)15 WDataTable (com.github.bordertech.wcomponents.WDataTable)5 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)5 TableDataModel (com.github.bordertech.wcomponents.TableDataModel)3 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)3 WText (com.github.bordertech.wcomponents.WText)3 UIContext (com.github.bordertech.wcomponents.UIContext)2 WComponent (com.github.bordertech.wcomponents.WComponent)2 WDateField (com.github.bordertech.wcomponents.WDateField)2 WRepeater (com.github.bordertech.wcomponents.WRepeater)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 AbstractTableDataModel (com.github.bordertech.wcomponents.AbstractTableDataModel)1 AbstractTreeTableDataModel (com.github.bordertech.wcomponents.AbstractTreeTableDataModel)1 SimpleBeanTreeTableDataModel (com.github.bordertech.wcomponents.SimpleBeanTreeTableDataModel)1 WDataTableRowRenderer (com.github.bordertech.wcomponents.WDataTableRowRenderer)1 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)1 WTextField (com.github.bordertech.wcomponents.WTextField)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 TravelDoc (com.github.bordertech.wcomponents.examples.table.PersonBean.TravelDoc)1