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.

ContainerSizeChange.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.tests.components.TestBase;
  3. import com.vaadin.ui.Button;
  4. import com.vaadin.v7.data.Item;
  5. import com.vaadin.v7.data.util.IndexedContainer;
  6. import com.vaadin.v7.ui.Table;
  7. public class ContainerSizeChange extends TestBase {
  8. private Table table;
  9. private MyDataSource ds;
  10. @Override
  11. protected String getDescription() {
  12. return "A table should be able to handle a decrease in the size of the container. The original container here contains 50 items and the decrease button removes 10 of these. To reproduce the problem: Click 'Decrease size' two times to reduce size to 30 and scroll to the end (50). What should happen is the table should notice the container size has decreased and show the last items which now exists in the new container.";
  13. }
  14. @Override
  15. protected Integer getTicketNumber() {
  16. return 2862;
  17. }
  18. @Override
  19. protected void setup() {
  20. table = new Table("A table");
  21. ds = new MyDataSource();
  22. table.setContainerDataSource(ds);
  23. table.setPageLength(5);
  24. addComponent(table);
  25. Button b = new Button("Decrease size", event -> ds.decreaseSize());
  26. addComponent(b);
  27. b = new Button("Increase size", event -> ds.increaseSize());
  28. addComponent(b);
  29. }
  30. }
  31. class MyDataSource extends IndexedContainer {
  32. private int size = 0;
  33. public MyDataSource() {
  34. addContainerProperty("a", String.class, "");
  35. addContainerProperty("b", String.class, "");
  36. addContainerProperty("c", String.class, "");
  37. for (int i = 0; i < 100; i++) {
  38. Item item = addItem(String.valueOf(i));
  39. item.getItemProperty("a").setValue("a " + i);
  40. item.getItemProperty("b").setValue("b " + i);
  41. item.getItemProperty("c").setValue("c " + i);
  42. }
  43. size = 50;
  44. }
  45. public void increaseSize() {
  46. size += 10;
  47. }
  48. public void decreaseSize() {
  49. if (size > 10) {
  50. size -= 10;
  51. }
  52. }
  53. @Override
  54. public int size() {
  55. return size;
  56. }
  57. }