You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TableScrollsOnRefresh.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.vaadin.tests.components.table;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import com.vaadin.server.VaadinRequest;
  5. import com.vaadin.tests.components.AbstractTestUI;
  6. import com.vaadin.ui.Button;
  7. import com.vaadin.ui.VerticalLayout;
  8. import com.vaadin.v7.data.util.BeanItemContainer;
  9. import com.vaadin.v7.ui.Table;
  10. public class TableScrollsOnRefresh extends AbstractTestUI {
  11. private Table table = new Table(
  12. "scroll down table, so it loads next page, and then click 'refresh' button");
  13. private Button refresh = new Button("refresh");
  14. private BeanItemContainer<TableItem> container = new BeanItemContainer<TableItem>(
  15. TableItem.class);
  16. @Override
  17. protected void setup(VaadinRequest request) {
  18. refresh.addClickListener(new Button.ClickListener() {
  19. @Override
  20. public void buttonClick(Button.ClickEvent event) {
  21. table.refreshRowCache();
  22. }
  23. });
  24. table.setSizeFull();
  25. addComponents(refresh, table);
  26. VerticalLayout vl = getLayout();
  27. vl.setExpandRatio(table, 1f);
  28. vl.setSizeFull();
  29. vl.getParent().setSizeFull();
  30. table.setContainerDataSource(container);
  31. populateContainer();
  32. }
  33. private void populateContainer() {
  34. List<TableItem> items = new ArrayList<TableItem>();
  35. for (int i = 0; i < 1000; i++) {
  36. items.add(new TableItem("Item " + Integer.toString(i),
  37. "Item description " + Integer.toString(i)));
  38. }
  39. container.addAll(items);
  40. }
  41. @Override
  42. protected String getTestDescription() {
  43. return "Refreshing row cache shouldn't change scroll position.";
  44. }
  45. @Override
  46. protected Integer getTicketNumber() {
  47. return 8707;
  48. }
  49. public class TableItem {
  50. private String name;
  51. private String description;
  52. public TableItem(String name, String description) {
  53. this.name = name;
  54. this.description = description;
  55. }
  56. public String getName() {
  57. return name;
  58. }
  59. public void setName(String name) {
  60. this.name = name;
  61. }
  62. public String getDescription() {
  63. return description;
  64. }
  65. public void setDescription(String description) {
  66. this.description = description;
  67. }
  68. }
  69. }