Search in sources :

Example 6 with RowIdWrapper

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));
}
Also used : RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 7 with RowIdWrapper

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();
}
Also used : RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) HashSet(java.util.HashSet)

Aggregations

RowIdWrapper (com.github.bordertech.wcomponents.WTable.RowIdWrapper)7 UIContext (com.github.bordertech.wcomponents.UIContext)3 WTable (com.github.bordertech.wcomponents.WTable)3 WComponent (com.github.bordertech.wcomponents.WComponent)2 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)2 TableModel (com.github.bordertech.wcomponents.WTable.TableModel)2 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)2 HashSet (java.util.HashSet)2 WRepeater (com.github.bordertech.wcomponents.WRepeater)1 TableRepeater (com.github.bordertech.wcomponents.WTable.TableRepeater)1 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)1 WTableRowRenderer (com.github.bordertech.wcomponents.WTableRowRenderer)1 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)1 Test (org.junit.Test)1