Search in sources :

Example 16 with TableDataModel

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

the class WDataTableRenderer method paintRows.

/**
 * Paints the rows of the table.
 *
 * @param table the table to paint the rows for.
 * @param renderContext the RenderContext to paint to.
 */
private void paintRows(final WDataTable table, final WebXmlRenderContext renderContext) {
    XmlStringBuilder xml = renderContext.getWriter();
    TableDataModel model = table.getDataModel();
    xml.appendTagOpen("ui:tbody");
    xml.appendAttribute("id", table.getRepeater().getId());
    xml.appendClose();
    if (model.getRowCount() == 0) {
        xml.appendTag("ui:nodata");
        xml.appendEscaped(table.getNoDataMessage());
        xml.appendEndTag("ui:nodata");
    } else {
        // If has at least one visible col, paint the rows.
        final int columnCount = table.getColumnCount();
        for (int i = 0; i < columnCount; i++) {
            if (table.getColumn(i).isVisible()) {
                doPaintRows(table, renderContext);
                break;
            }
        }
    }
    xml.appendEndTag("ui:tbody");
}
Also used : TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 17 with TableDataModel

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

the class WDataTableRenderer_Test method testDoPaintWithInvisibleColumnAndNoColumnHeaders.

@Test
public void testDoPaintWithInvisibleColumnAndNoColumnHeaders() throws IOException, SAXException, XpathException {
    WDataTable component = new WDataTable();
    component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class));
    component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class));
    component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class));
    TableDataModel tableDataModel = createTableModel();
    component.setDataModel(tableDataModel);
    component.setVisible(true);
    final int testColIndex = 1;
    final boolean testShowColHeaders = false;
    component.getColumn(testColIndex).setVisible(false);
    component.setShowColumnHeaders(testShowColHeaders);
    // head hidden=true
    assertXpathEvaluatesTo(TRUE, "//ui:table/ui:thead/@hidden", component);
    // column headers - only COL1 and COL3 showing - in positions 1 and 2 respectively - only 2 cols
    assertXpathEvaluatesTo(COL1_HEADING_TEST, "//ui:table/ui:thead/ui:th[1]/ui:decoratedlabel/ui:labelbody", component);
    assertXpathEvaluatesTo(COL3_HEADING_TEST, "//ui:table/ui:thead/ui:th[2]/ui:decoratedlabel/ui:labelbody", component);
    assertXpathNotExists("//ui:table/ui:thead/ui:th[3]/ui:decoratedlabel/ui:labelbody", component);
    // first row - col1 and col3 from model in positions 1 and 2 respectively - only 2 cols showing
    String firstName = (String) tableDataModel.getValueAt(0, 0);
    String entryDate = (String) tableDataModel.getValueAt(0, 2);
    assertXpathEvaluatesTo(firstName, "//ui:table/ui:tbody/ui:tr[1]/ui:td[1]/ui:textfield", component);
    assertXpathEvaluatesTo(entryDate, "//ui:table/ui:tbody/ui:tr[1]/ui:td[2]/ui:textfield", component);
    assertXpathNotExists("//ui:table/ui:tbody/ui:tr[1]/ui:td[3]/ui:textfield", component);
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WDataTable(com.github.bordertech.wcomponents.WDataTable) SimpleTableDataModel(com.github.bordertech.wcomponents.SimpleTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) WTextField(com.github.bordertech.wcomponents.WTextField) ActionConstraint(com.github.bordertech.wcomponents.WDataTable.ActionConstraint) Test(org.junit.Test)

Example 18 with TableDataModel

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

the class WDataTableRenderer_Test method testDoPaintTableActionsInvisibleButton.

@Test
public void testDoPaintTableActionsInvisibleButton() throws IOException, SAXException, XpathException {
    WDataTable component = new WDataTable();
    component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class));
    component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class));
    component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class));
    TableDataModel tableModel = createTableModel();
    component.setDataModel(tableModel);
    component.setVisible(true);
    WButton button1 = new WButton(TEST_ACTION_ONE);
    component.addAction(button1);
    // Visible
    assertXpathExists("//ui:table/ui:actions", component);
    // Not Visible
    button1.setVisible(false);
    assertXpathNotExists("//ui:table/ui:actions", component);
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WDataTable(com.github.bordertech.wcomponents.WDataTable) SimpleTableDataModel(com.github.bordertech.wcomponents.SimpleTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 19 with TableDataModel

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

the class WDataTableRenderer_Test method testDoPaintPaginatedServer.

@Test
public void testDoPaintPaginatedServer() throws IOException, SAXException, XpathException {
    WDataTable component = new WDataTable();
    component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class));
    component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class));
    component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class));
    TableDataModel tableModel = createTableModel();
    component.setDataModel(tableModel);
    component.setVisible(true);
    component.setPaginationMode(PaginationMode.DYNAMIC);
    setActiveContext(createUIContext());
    assertXpathEvaluatesTo("dynamic", "//ui:table/ui:pagination/@mode", component);
    assertXpathEvaluatesTo((new Integer(component.getCurrentPage())).toString(), "//ui:table/ui:pagination/@currentPage", component);
    assertXpathEvaluatesTo((new Integer(component.getRowsPerPage())).toString(), "//ui:table/ui:pagination/@rowsPerPage", component);
    assertXpathEvaluatesTo((new Integer(tableModel.getRowCount())).toString(), "//ui:table/ui:pagination/@rows", component);
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WDataTable(com.github.bordertech.wcomponents.WDataTable) SimpleTableDataModel(com.github.bordertech.wcomponents.SimpleTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 20 with TableDataModel

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

the class WDataTableRenderer_Test method testDoPaintSortableSortModeServer.

// SERVER outputs "dynamic" see https://github.com/BorderTech/wcomponents/issues/701
@Test
public void testDoPaintSortableSortModeServer() throws IOException, SAXException, XpathException {
    WDataTable component = new WDataTable();
    component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class));
    component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class));
    component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class));
    // sortable data model
    TableDataModel tableModel = createTableModelSortable();
    component.setDataModel(tableModel);
    component.setVisible(true);
    component.setSortMode(SortMode.SERVER);
    assertXpathEvaluatesTo("dynamic", "//ui:table/ui:sort/@mode", component);
    assertXpathEvaluatesTo(TRUE, "//ui:table/ui:thead/ui:th[1]/@sortable", component);
    assertXpathNotExists("//ui:table/ui:thead/ui:th[2]/@sortable", component);
    assertXpathEvaluatesTo(TRUE, "//ui:table/ui:thead/ui:th[3]/@sortable", component);
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WDataTable(com.github.bordertech.wcomponents.WDataTable) SimpleTableDataModel(com.github.bordertech.wcomponents.SimpleTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Aggregations

TableDataModel (com.github.bordertech.wcomponents.TableDataModel)28 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)24 WDataTable (com.github.bordertech.wcomponents.WDataTable)23 SimpleTableDataModel (com.github.bordertech.wcomponents.SimpleTableDataModel)22 Test (org.junit.Test)22 WTextField (com.github.bordertech.wcomponents.WTextField)21 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)6 TableTreeNode (com.github.bordertech.wcomponents.TableTreeNode)4 WButton (com.github.bordertech.wcomponents.WButton)4 ActionConstraint (com.github.bordertech.wcomponents.WDataTable.ActionConstraint)4 UIContext (com.github.bordertech.wcomponents.UIContext)3 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)3 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 WDataTableRowRenderer (com.github.bordertech.wcomponents.WDataTableRowRenderer)1 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)1 WText (com.github.bordertech.wcomponents.WText)1