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");
}
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");
}
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);
}
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);
}
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);
}
Aggregations