use of com.github.bordertech.wcomponents.WTable.RowIdWrapper in project wcomponents by BorderTech.
the class WTable_Test method testHandleSortRequest.
@Test
public void testHandleSortRequest() {
SimpleTableModel model = new SimpleTableModel(new String[][] { { "1" }, { "3" }, { "2" } });
model.setComparator(0, SimpleTableModel.COMPARABLE_COMPARATOR);
WTable table = new WTable();
table.setSelectMode(WTable.SelectMode.SINGLE);
table.setTableModel(new AdapterBasicTableModel(model));
table.addColumn(new WTableColumn("dummy", WText.class));
table.setSortMode(SortMode.DYNAMIC);
table.setLocked(true);
setActiveContext(createUIContext());
MockRequest request = new MockRequest();
request.setParameter(table.getId() + "-h", "x");
request.setParameter(table.getId() + ".sort", "0");
table.handleRequest(request);
Assert.assertTrue("Incorrect selection after handleRequest", table.isSorted());
Assert.assertEquals("Incorrect sort column after handleRequest", 0, table.getSortColumnIndex());
Assert.assertTrue("Incorrect sort direction after handleRequest", table.isSortAscending());
List<RowIdWrapper> rowIndices = table.getRepeater().getBeanList();
Assert.assertEquals("Incorrect sort", 3, rowIndices.size());
Assert.assertEquals("Incorrect sort", Integer.valueOf(0), rowIndices.get(0).getRowIndex().get(0));
Assert.assertEquals("Incorrect sort", Integer.valueOf(1), rowIndices.get(1).getRowIndex().get(0));
Assert.assertEquals("Incorrect sort", Integer.valueOf(2), rowIndices.get(2).getRowIndex().get(0));
resetContext();
Assert.assertFalse("Incorrect default sort after handleRequest", table.isSorted());
setActiveContext(createUIContext());
request = new MockRequest();
request.setParameter(table.getId() + "-h", "x");
request.setParameter(table.getId() + ".sort", "0");
request.setParameter(table.getId() + ".sortDesc", "true");
table.handleRequest(request);
rowIndices = table.getRepeater().getBeanList();
Assert.assertEquals("Incorrect sort", 3, rowIndices.size());
Assert.assertEquals("Incorrect sort", Integer.valueOf(0), rowIndices.get(0).getRowIndex().get(0));
Assert.assertEquals("Incorrect sort", Integer.valueOf(1), rowIndices.get(1).getRowIndex().get(0));
Assert.assertEquals("Incorrect sort", Integer.valueOf(2), rowIndices.get(2).getRowIndex().get(0));
}
use of com.github.bordertech.wcomponents.WTable.RowIdWrapper in project wcomponents by BorderTech.
the class WTable_Test method calculateOtherSelectedRows.
// selectedRowsOtherPages is calculated and updated in WTableRenderer so this is a modification straight from there.
// Don't need the entire doPaintRows() method as we're not actually rendering anything.
private int calculateOtherSelectedRows(WTable table) {
WTable.TableRepeater repeater = table.getRepeater();
List<RowIdWrapper> wrappers = repeater.getBeanList();
Set<?> otherSelectedRows = new HashSet<>(table.getSelectedRows());
for (RowIdWrapper wrapper : wrappers) {
Object rowKey = wrapper.getRowKey();
if (table.getSelectedRows().contains(rowKey)) {
otherSelectedRows.remove(rowKey);
}
}
return otherSelectedRows.size();
}
Aggregations