Search in sources :

Example 16 with TableModel

use of com.github.bordertech.wcomponents.WTable.TableModel in project wcomponents by BorderTech.

the class WTableRenderer method paintPaginationDetails.

/**
 * Paint the pagination aspects of the table.
 * @param table the WDataTable being rendered
 * @param xml the string builder in use
 */
private void paintPaginationDetails(final WTable table, final XmlStringBuilder xml) {
    TableModel model = table.getTableModel();
    xml.appendTagOpen("ui:pagination");
    xml.appendAttribute("rows", model.getRowCount());
    xml.appendOptionalAttribute("rowsPerPage", table.getRowsPerPage() > 0, table.getRowsPerPage());
    xml.appendAttribute("currentPage", table.getCurrentPage());
    switch(table.getPaginationMode()) {
        case CLIENT:
            xml.appendAttribute("mode", "client");
            break;
        case DYNAMIC:
            xml.appendAttribute("mode", "dynamic");
            break;
        case NONE:
            break;
        default:
            throw new SystemException("Unknown pagination mode: " + table.getPaginationMode());
    }
    if (table.getPaginationLocation() != WTable.PaginationLocation.AUTO) {
        switch(table.getPaginationLocation()) {
            case TOP:
                xml.appendAttribute("controls", "top");
                break;
            case BOTTOM:
                xml.appendAttribute("controls", "bottom");
                break;
            case BOTH:
                xml.appendAttribute("controls", "both");
                break;
            default:
                throw new SystemException("Unknown pagination control location: " + table.getPaginationLocation());
        }
    }
    xml.appendClose();
    // Rows per page options
    if (table.getRowsPerPageOptions() != null) {
        xml.appendTag("ui:rowsselect");
        for (Integer option : table.getRowsPerPageOptions()) {
            xml.appendTagOpen("ui:option");
            xml.appendAttribute("value", option);
            xml.appendEnd();
        }
        xml.appendEndTag("ui:rowsselect");
    }
    xml.appendEndTag("ui:pagination");
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Example 17 with TableModel

use of com.github.bordertech.wcomponents.WTable.TableModel in project wcomponents by BorderTech.

the class WTableRenderer 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 WTable table, final WebXmlRenderContext renderContext) {
    XmlStringBuilder xml = renderContext.getWriter();
    TableModel model = table.getTableModel();
    xml.appendTagOpen("ui:tbody");
    xml.appendAttribute("id", table.getId() + ".body");
    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 : XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Example 18 with TableModel

use of com.github.bordertech.wcomponents.WTable.TableModel in project wcomponents by BorderTech.

the class WTableRenderer_Test method testDoPaintPaginatedDynamic.

@Test
public void testDoPaintPaginatedDynamic() throws IOException, SAXException, XpathException {
    WTable component = new WTable();
    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));
    TableModel tableModel = createTableModel();
    component.setTableModel(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 : WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WTextField(com.github.bordertech.wcomponents.WTextField) TableModel(com.github.bordertech.wcomponents.WTable.TableModel) AdapterBasicTableModel(com.github.bordertech.wcomponents.AdapterBasicTableModel) SimpleTableModel(com.github.bordertech.wcomponents.SimpleTableModel) Test(org.junit.Test)

Example 19 with TableModel

use of com.github.bordertech.wcomponents.WTable.TableModel in project wcomponents by BorderTech.

the class WTableRenderer_Test method testDoPaintSelectModeMultipleSelectAllControl.

@Test
public void testDoPaintSelectModeMultipleSelectAllControl() throws IOException, SAXException, XpathException {
    WTable component = new WTable();
    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));
    TableModel tableModel = createTableModel();
    component.setTableModel(tableModel);
    component.setVisible(true);
    component.setSelectMode(WTable.SelectMode.MULTIPLE);
    component.setSelectAllMode(WTable.SelectAllType.CONTROL);
    assertXpathExists("//ui:table/ui:rowselection", component);
    assertXpathEvaluatesTo(TRUE, "//ui:table/ui:rowselection/@multiple", component);
    assertXpathEvaluatesTo("control", "//ui:table/ui:rowselection/@selectAll", component);
    // toggle not available by default
    assertXpathNotExists("//ui:table/ui:rowselection/@toggle", component);
}
Also used : WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WTextField(com.github.bordertech.wcomponents.WTextField) TableModel(com.github.bordertech.wcomponents.WTable.TableModel) AdapterBasicTableModel(com.github.bordertech.wcomponents.AdapterBasicTableModel) SimpleTableModel(com.github.bordertech.wcomponents.SimpleTableModel) Test(org.junit.Test)

Example 20 with TableModel

use of com.github.bordertech.wcomponents.WTable.TableModel in project wcomponents by BorderTech.

the class WTableRenderer_Test method testDoPaintTableActionsInvisibleButton.

@Test
public void testDoPaintTableActionsInvisibleButton() throws IOException, SAXException, XpathException {
    WTable component = new WTable();
    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));
    TableModel tableModel = createTableModel();
    component.setTableModel(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 : WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) TableModel(com.github.bordertech.wcomponents.WTable.TableModel) AdapterBasicTableModel(com.github.bordertech.wcomponents.AdapterBasicTableModel) SimpleTableModel(com.github.bordertech.wcomponents.SimpleTableModel) Test(org.junit.Test)

Aggregations

TableModel (com.github.bordertech.wcomponents.WTable.TableModel)29 WTable (com.github.bordertech.wcomponents.WTable)25 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)25 Test (org.junit.Test)24 AdapterBasicTableModel (com.github.bordertech.wcomponents.AdapterBasicTableModel)23 SimpleTableModel (com.github.bordertech.wcomponents.SimpleTableModel)23 WTextField (com.github.bordertech.wcomponents.WTextField)22 WButton (com.github.bordertech.wcomponents.WButton)4 ActionConstraint (com.github.bordertech.wcomponents.WTable.ActionConstraint)4 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)4 UIContext (com.github.bordertech.wcomponents.UIContext)2 RowIdWrapper (com.github.bordertech.wcomponents.WTable.RowIdWrapper)2 ArrayList (java.util.ArrayList)2 WComponent (com.github.bordertech.wcomponents.WComponent)1 WRepeater (com.github.bordertech.wcomponents.WRepeater)1 WTableRowRenderer (com.github.bordertech.wcomponents.WTableRowRenderer)1 WText (com.github.bordertech.wcomponents.WText)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)1