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.

ReloadWidgets.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.server.VaadinRequest;
  3. import com.vaadin.tests.components.AbstractReindeerTestUI;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.v7.data.util.BeanItemContainer;
  6. import com.vaadin.v7.ui.Table;
  7. @SuppressWarnings("serial")
  8. public class ReloadWidgets extends AbstractReindeerTestUI {
  9. int pressed = 0;
  10. @Override
  11. protected void setup(VaadinRequest request) {
  12. final Table table = new Table(null,
  13. new BeanItemContainer<>(Bean.class));
  14. table.setId("table");
  15. table.setSizeFull();
  16. table.setColumnHeader("col1", "Text");
  17. table.setColumnHeader("col2", "Button");
  18. fillTable(table);
  19. Button button = new Button("Refresh");
  20. button.setId("refresh");
  21. button.addClickListener(event -> {
  22. table.removeAllItems();
  23. fillTable(table);
  24. });
  25. getLayout().addComponent(button);
  26. getLayout().addComponent(table);
  27. getLayout().setExpandRatio(table, 1f);
  28. }
  29. @Override
  30. protected String getTestDescription() {
  31. return "Table should always populate button widgets to column 2";
  32. }
  33. @Override
  34. protected Integer getTicketNumber() {
  35. return 16611;
  36. }
  37. private void fillTable(Table table) {
  38. int i = 0;
  39. int size = pressed % 2 == 0 ? 500 : 499;
  40. pressed++;
  41. for (int step = 0; step < i + size; step++) {
  42. String caption = Integer.toString(step);
  43. Button button = new Button(caption);
  44. button.setId(caption);
  45. Bean itemId = new Bean(caption, button);
  46. table.addItem(itemId);
  47. }
  48. }
  49. public class Bean {
  50. private String col1;
  51. private Button col2;
  52. public Bean(String col1, Button col2) {
  53. this.col1 = col1;
  54. this.col2 = col2;
  55. }
  56. public String getCol1() {
  57. return col1;
  58. }
  59. public void setCol1(String col1) {
  60. this.col1 = col1;
  61. }
  62. public Button getCol2() {
  63. return col2;
  64. }
  65. public void setCol2(Button col2) {
  66. this.col2 = col2;
  67. }
  68. @Override
  69. public boolean equals(Object o) {
  70. if (this == o) {
  71. return true;
  72. }
  73. if (o == null || getClass() != o.getClass()) {
  74. return false;
  75. }
  76. Bean bean = (Bean) o;
  77. if (!col1.equals(bean.col1)) {
  78. return false;
  79. }
  80. if (!col2.equals(bean.col2)) {
  81. return false;
  82. }
  83. return true;
  84. }
  85. @Override
  86. public int hashCode() {
  87. int result = col1.hashCode();
  88. result = 31 * result + col2.hashCode();
  89. return result;
  90. }
  91. }
  92. }