new DefaultKeyboardSelectionHandler<String>(table);
table.setKeyboardSelectionHandler(keyHandler);
HasDataPresenter<String> presenter = table.getPresenter();
table.setRowCount(300, true);
table.setVisibleRange(new Range(pageStart, pageSize));
populateData(table);
presenter.flush();
table.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE);
// keyboardPrev in middle.
table.setKeyboardSelectedRow(1);
presenter.flush();
assertEquals(1, table.getKeyboardSelectedRow());
keyHandler.prevRow();
presenter.flush();
assertEquals(0, table.getKeyboardSelectedRow());
// keyboardPrev at beginning.
keyHandler.prevRow();
populateData(table);
presenter.flush();
pageStart -= increment;
pageSize += increment;
assertEquals(increment - 1, table.getKeyboardSelectedRow());
assertEquals(new Range(pageStart, pageSize), table.getVisibleRange());
// keyboardNext in middle.
table.setKeyboardSelectedRow(pageSize - 2);
presenter.flush();
assertEquals(pageSize - 2, table.getKeyboardSelectedRow());
keyHandler.nextRow();
presenter.flush();
assertEquals(pageSize - 1, table.getKeyboardSelectedRow());
// keyboardNext at end.
keyHandler.nextRow();
populateData(table);
presenter.flush();
pageSize += increment;
assertEquals(pageSize - increment, table.getKeyboardSelectedRow());
assertEquals(new Range(pageStart, pageSize), table.getVisibleRange());
// keyboardPrevPage within range.
table.setKeyboardSelectedRow(increment);
presenter.flush();
assertEquals(increment, table.getKeyboardSelectedRow());
keyHandler.prevPage();
presenter.flush();
assertEquals(0, table.getKeyboardSelectedRow());
assertEquals(new Range(pageStart, pageSize), table.getVisibleRange());
// keyboardPrevPage outside range.
keyHandler.prevPage();
populateData(table);
presenter.flush();
assertEquals(0, table.getKeyboardSelectedRow());
pageStart -= increment;
pageSize += increment;
assertEquals(new Range(pageStart, pageSize), table.getVisibleRange());
// keyboardNextPage inside range.
keyHandler.nextPage();
presenter.flush();
assertEquals(increment, table.getKeyboardSelectedRow());
assertEquals(new Range(pageStart, pageSize), table.getVisibleRange());
// keyboardNextPage outside range.
table.setKeyboardSelectedRow(pageSize - 1);
presenter.flush();
assertEquals(pageSize - 1, table.getKeyboardSelectedRow());
keyHandler.nextPage();
populateData(table);
presenter.flush();
pageSize += increment;
assertEquals(pageSize - 1, table.getKeyboardSelectedRow());
assertEquals(new Range(pageStart, pageSize), table.getVisibleRange());
// keyboardHome.
keyHandler.home();
populateData(table);
presenter.flush();
pageSize += pageStart;
pageStart = 0;
assertEquals(0, table.getKeyboardSelectedRow());
assertEquals(new Range(pageStart, pageSize), table.getVisibleRange());
// keyboardPrev at first row.
keyHandler.prevRow();
presenter.flush();
assertEquals(0, table.getKeyboardSelectedRow());
assertEquals(new Range(pageStart, pageSize), table.getVisibleRange());
// keyboardEnd.
keyHandler.end();
pageSize = 300;
populateData(table);
presenter.flush();
assertEquals(pageSize - 1, table.getKeyboardSelectedRow());
assertEquals(new Range(0, pageSize), table.getVisibleRange());
// keyboardNext at last row.
keyHandler.nextRow();
presenter.flush();
assertEquals(pageSize - 1, table.getKeyboardSelectedRow());
assertEquals(new Range(pageStart, pageSize), table.getVisibleRange());
}