Search in sources :

Example 11 with TableTreeNode

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

the class TreeTableExample method createTree.

/**
 * @return a tree containing the data for this example.
 */
private TableTreeNode createTree() {
    TableTreeNode root = new TableTreeNode(null);
    SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy");
    try {
        TableTreeNode joe = new TableTreeNode(new PersonBean("Joe", "Bloggs", sdf.parse("01/02/1973")));
        TableTreeNode jane = new TableTreeNode(new PersonBean("Jane", "Bloggs", sdf.parse("04/05/1976")));
        TableTreeNode kid = new TableTreeNode(new PersonBean("Kid", "Bloggs", sdf.parse("31/12/1999")));
        TableTreeNode doc1 = new TravelDocNode(new TravelDoc("12345", "Canada", "Ottawa", sdf.parse("01/01/1990"), sdf.parse("01/01/1983")));
        TableTreeNode doc2 = new TravelDocNode(new TravelDoc("23456", "New Zealand", "Wellington", sdf.parse("01/01/1999"), sdf.parse("01/01/2009")));
        TableTreeNode doc3 = new TravelDocNode(new TravelDoc("78901", "New Zealand", "Wellington", sdf.parse("01/01/2005"), sdf.parse("01/01/2015")));
        root.add(joe);
        root.add(jane);
        root.add(kid);
        joe.add(doc1);
        joe.add(doc2);
        jane.add(doc3);
    } catch (ParseException e) {
        LogFactory.getLog(getClass()).error("Failed to create test data", e);
    }
    return root;
}
Also used : TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 12 with TableTreeNode

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

the class TreeTableHierarchyExample method createTable.

/**
 * Creates and configures the table to be used by the example. The table is configured with global rather than user
 * data. Although this is not a realistic scenario, it will suffice for this example.
 *
 * @return a new configured table.
 */
private WDataTable createTable() {
    WDataTable tbl = new WDataTable();
    tbl.setType(WDataTable.Type.HIERARCHIC);
    tbl.addColumn(new WTableColumn("First name", new WText()));
    tbl.addColumn(new WTableColumn("Last name", new WText()));
    tbl.addColumn(new WTableColumn("DOB", new WDateField()));
    tbl.setExpandMode(ExpandMode.CLIENT);
    tbl.setStripingType(WDataTable.StripingType.ROWS);
    TableTreeNode root = createTree();
    tbl.setDataModel(new ExampleTreeTableModel(root));
    return tbl;
}
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) WDateField(com.github.bordertech.wcomponents.WDateField)

Example 13 with TableTreeNode

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

the class TreeTableHierarchyExample 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)

Example 14 with TableTreeNode

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

the class TableLoadPerformance method startLoad.

/**
 * Start load.
 */
private void startLoad() {
    tableLayout.setVisible(true);
    List<PersonBean> beans = ExampleDataUtil.createExampleData(numRows.getNumber().intValue(), numDocs.getNumber().intValue());
    if (isLoadWTable()) {
        table.setBean(beans);
    }
    if (isLoadWDataTable()) {
        TableTreeNode tree = createTree(beans);
        datatable.setDataModel(new SimpleBeanTreeTableDataModel(new String[] { "firstName", "lastName", "dateOfBirth" }, tree));
    }
    if (isLoadWTable()) {
        ajax2.setVisible(true);
        tableShim.setVisible(isLoadWTable());
    } else {
        ajax4.setVisible(true);
        dataShim.setVisible(isLoadWDataTable());
    }
}
Also used : SimpleBeanTreeTableDataModel(com.github.bordertech.wcomponents.SimpleBeanTreeTableDataModel) TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode)

Example 15 with TableTreeNode

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

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