@Test public void testExpandedRowsAccessors() { WTable table = new WTable(); table.setTableModel(createModel(new String[10][1])); Set<Object> rows1 = new HashSet<Object>(Arrays.asList(Arrays.asList(0), Arrays.asList(1), Arrays.asList(2))); Set<Object> rows2 = new HashSet<Object>(Arrays.asList(Arrays.asList(3), Arrays.asList(4), Arrays.asList(5))); assertAccessorsCorrect(table, "expandedRows", Collections.EMPTY_SET, rows1, rows2); }
@Test public void testSelectedRowsAccessors() { WTable table = new WTable(); table.setTableModel(createModel(new String[10][1])); Set<Object> rows1 = new HashSet<Object>(Arrays.asList(Arrays.asList(0), Arrays.asList(1), Arrays.asList(2))); Set<Object> rows2 = new HashSet<Object>(Arrays.asList(Arrays.asList(3), Arrays.asList(4), Arrays.asList(5))); assertAccessorsCorrect(table, "selectedRows", Collections.EMPTY_SET, rows1, rows2); }
/** * Override preparePaintComponent in order to set up the example data the first time that the example is accessed by * each user. * * @param request the request being responded to. */ @Override protected void preparePaintComponent(final Request request) { super.preparePaintComponent(request); if (!isInitialised()) { table.setTableModel(createTableModel()); setInitialised(true); } }
@Test public void testRowsPerPageOptionsChangeRowsPerPage() { WTable table = new WTable(); table.setTableModel(createModel(new String[100][1])); table.setPaginationMode(PaginationMode.CLIENT); table.setRowsPerPage(40); Assert.assertEquals("Rows per page should be 40", 40, table.getRowsPerPage()); table.setRowsPerPageOptions(Arrays.asList(1, 2, 3)); Assert.assertEquals("Rows per page should be the first option as it was not a valid option", 1, table.getRowsPerPage()); }
@Test public void testCurrentPageLogicWithNoPagination() { WTable table = new WTable(); table.setPaginationMode(PaginationMode.NONE); table.setTableModel(createModel(new String[100][1])); table.setRowsPerPage(10); table.setCurrentPage(50); Assert.assertEquals("Current page should alway be zero for a table with no pagination", 0, table.getCurrentPage()); }
@Test public void testCurrentPageLogic() { WTable table = new WTable(); table.setPaginationMode(PaginationMode.CLIENT); table.setTableModel(createModel(new String[100][1])); table.setRowsPerPage(10); // Page is greater than number of pages table.setCurrentPage(90); Assert.assertEquals("Current page should be equal to the max page of 9", 9, table. getCurrentPage()); }
@Test public void testRowsPerPageWithOptionsZeroValue() { WTable table = new WTable(); table.setTableModel(createModel(new String[100][1])); table.setPaginationMode(PaginationMode.CLIENT); table.setRowsPerPageOptions(Arrays.asList(0, 1, 2)); table.setRowsPerPage(0); assertAccessorsCorrect(table, "rowsPerPage", 0, 1, 2); }
@Test public void testCurrentPageAccessors() { WTable table = new WTable(); table.setTableModel(createModel(new String[100][1])); table.setPaginationMode(PaginationMode.CLIENT); table.setRowsPerPage(10); assertAccessorsCorrect(table, "currentPage", 0, 5, 7); }
/** * Create example. */ public SimplePaginationTableExample() { add(table); // Columns table.addColumn(new WTableColumn("First name", new WText())); table.addColumn(new WTableColumn("Last name", new WText())); table.addColumn(new WTableColumn("DOB", new WDateField())); // Pagination Mode table.setPaginationMode(PaginationMode.DYNAMIC); table.setRowsPerPage(3); // Setup model SimpleBeanBoundTableModel model = new SimpleBeanBoundTableModel( new String[]{"firstName", "lastName", "dateOfBirth"}); table.setTableModel(model); }
@Test public void testDoPaintOfRowHeaderWithNoRowHeaderColumn() throws IOException, SAXException, XpathException { WTable table = new WTable(); table.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class)); table.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class)); table.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class)); // no row headers set TableModel tableModel = createTableModel(); table.setTableModel(tableModel); assertXpathNotExists("//ui:table/ui:tbody/ui:tr/ui:th", table); }
/** * Creates a simple table with a data model set. * * @return a new table with content. */ private static WTable createWTable() { WTable table = new WTable(); table.addColumn(new WTableColumn("Column 1", WText.class)); table.addColumn(new WTableColumn("Column 2", new WTextField())); table.setTableModel(new AdapterBasicTableModel(new MyModel())); return table; }
@Test public void testDoPaintExpandModeDynamic() 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.setExpandMode(ExpandMode.DYNAMIC); assertXpathEvaluatesTo("dynamic", "//ui:table/ui:rowexpansion/@mode", component); }
@Test public void testDoPaintExpandModeClient() 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.setExpandMode(ExpandMode.CLIENT); assertXpathEvaluatesTo("client", "//ui:table/ui:rowexpansion/@mode", component); }
@Test public void testDoPaintExpandModeLazy() 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.setExpandMode(ExpandMode.LAZY); assertXpathEvaluatesTo("lazy", "//ui:table/ui:rowexpansion/@mode", component); }
@Test public void testDoPaintSelectModeSingle() 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.SINGLE); assertXpathExists("//ui:table/ui:rowselection", component); }
@Test public void testDoPainWithRowHeaderColumn() throws IOException, SAXException, XpathException { WTable table = new WTable(); table.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class)); table.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class)); table.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class)); // set the first column as the row headers table.setRowHeaders(true); TableModel tableModel = createTableModel(); table.setTableModel(tableModel); assertXpathExists("//ui:table/ui:tbody/ui:tr/ui:th", table); assertXpathNotExists("//ui:table/ui:tbody/ui:tr/ui:th[2]", table); }
@Test public void testDoPaintMissingAttributesColumnStripingSeparatorsBoth() 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)); component.setTableModel(createTableModel()); component.setVisible(true); component.setStripingType(WTable.StripingType.COLUMNS); component.setSeparatorType(WTable.SeparatorType.BOTH); assertXpathNotExists("//ui:table/@caption", component); assertXpathEvaluatesTo("table", "//ui:table/@type", component); assertXpathEvaluatesTo("cols", "//ui:table/@striping", component); assertXpathEvaluatesTo("both", "//ui:table/@separators", component); }
@Test public void testDoPaintMissingAttributesColumnStriping() 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)); component.setTableModel(createTableModel()); component.setVisible(true); component.setStripingType(WTable.StripingType.COLUMNS); component.setSeparatorType(WTable.SeparatorType.VERTICAL); assertXpathNotExists("//ui:table/@caption", component); assertXpathEvaluatesTo("table", "//ui:table/@type", component); assertXpathEvaluatesTo("cols", "//ui:table/@striping", component); assertXpathEvaluatesTo("vertical", "//ui:table/@separators", component); }
@Test public void testDoPaintWithColAlignment() throws IOException, SAXException, XpathException { WTable table = new WTable(); table.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class)); table.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class)); table.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class)); table.getColumn(0).setAlign(WTableColumn.Alignment.LEFT); table.getColumn(1).setAlign(WTableColumn.Alignment.CENTER); table.getColumn(2).setAlign(WTableColumn.Alignment.RIGHT); TableModel tableModel = createTableModel(); table.setTableModel(tableModel); assertXpathNotExists("//ui:table/ui:thead/ui:th[1]/@align", table); assertXpathEvaluatesTo("center", "//ui:table/ui:thead/ui:th[2]/@align", table); assertXpathEvaluatesTo("right", "//ui:table/ui:thead/ui:th[3]/@align", table); }
@Test public void testDoPaintWithColWidth() throws IOException, SAXException, XpathException { WTable table = new WTable(); table.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class)); table.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class)); table.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class)); table.getColumn(0).setWidth(0); table.getColumn(1).setWidth(1); table.getColumn(2).setWidth(100); TableModel tableModel = createTableModel(); table.setTableModel(tableModel); assertXpathNotExists("//ui:table/ui:thead/ui:th[1]/@width", table); assertXpathEvaluatesTo("1", "//ui:table/ui:thead/ui:th[2]/@width", table); assertXpathEvaluatesTo("100", "//ui:table/ui:thead/ui:th[3]/@width", table); }