new DefaultKeyboardSelectionHandler<String>(table);
table.setKeyboardSelectionHandler(keyHandler);
HasDataPresenter<String> presenter = table.getPresenter();
table.setRowCount(100, true);
table.setVisibleRange(new Range(50, 10));
populateData(table);
presenter.flush();
table.setKeyboardPagingPolicy(KeyboardPagingPolicy.CHANGE_PAGE);
// keyboardPrev in middle.
table.setKeyboardSelectedRow(1);
presenter.flush();
assertEquals(1, table.getKeyboardSelectedRow());
keyHandler.prevRow();
presenter.flush();
assertEquals(0, table.getKeyboardSelectedRow());
// keyboardPrev at beginning goes to previous page.
keyHandler.prevRow();
populateData(table);
presenter.flush();
assertEquals(9, table.getKeyboardSelectedRow());
assertEquals(new Range(40, 10), table.getVisibleRange());
// keyboardNext in middle.
table.setKeyboardSelectedRow(8);
presenter.flush();
assertEquals(8, table.getKeyboardSelectedRow());
keyHandler.nextRow();
presenter.flush();
assertEquals(9, table.getKeyboardSelectedRow());
// keyboardNext at end.
keyHandler.nextRow();
populateData(table);
presenter.flush();
assertEquals(0, table.getKeyboardSelectedRow());
assertEquals(new Range(50, 10), table.getVisibleRange());
// keyboardPrevPage.
table.setKeyboardSelectedRow(5);
presenter.flush();
assertEquals(5, table.getKeyboardSelectedRow());
keyHandler.prevPage();
populateData(table);
presenter.flush();
assertEquals(0, table.getKeyboardSelectedRow());
assertEquals(new Range(40, 10), table.getVisibleRange());
// keyboardNextPage.
table.setKeyboardSelectedRow(5);
presenter.flush();
assertEquals(5, table.getKeyboardSelectedRow());
keyHandler.nextPage();
populateData(table);
presenter.flush();
assertEquals(0, table.getKeyboardSelectedRow());
assertEquals(new Range(50, 10), table.getVisibleRange());
// keyboardHome.
keyHandler.home();
populateData(table);
presenter.flush();
assertEquals(0, table.getKeyboardSelectedRow());
assertEquals(new Range(0, 10), table.getVisibleRange());
// keyboardPrev at first row.
keyHandler.prevRow();
presenter.flush();
assertEquals(0, table.getKeyboardSelectedRow());
// keyboardEnd.
keyHandler.end();
populateData(table);
presenter.flush();
assertEquals(9, table.getKeyboardSelectedRow());
assertEquals(new Range(90, 10), table.getVisibleRange());
// keyboardNext at last row.
keyHandler.nextRow();
presenter.flush();
}