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.

AsyncPushUpdates.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.table;
  17. import com.vaadin.annotations.Push;
  18. import com.vaadin.server.VaadinRequest;
  19. import com.vaadin.tests.components.AbstractReindeerTestUI;
  20. import com.vaadin.ui.Button;
  21. import com.vaadin.v7.data.util.IndexedContainer;
  22. import com.vaadin.v7.ui.Table;
  23. /**
  24. * Test to see if VScrollTable handles Push updates correctly.
  25. *
  26. * @author Vaadin Ltd
  27. */
  28. @Push
  29. public class AsyncPushUpdates extends AbstractReindeerTestUI {
  30. public int clickCount = 0;
  31. public static final String VALUE_PROPERTY_ID = "value";
  32. private final IndexedContainer container = createContainer();
  33. private final Table table = new Table();
  34. @Override
  35. public void setup(VaadinRequest request) {
  36. table.setWidth("100%");
  37. table.setContainerDataSource(container);
  38. Button button = new Button("START");
  39. button.addClickListener(event -> {
  40. ++clickCount;
  41. container.removeAllItems();
  42. for (int i = 0; i < 100; i++) {
  43. container.getContainerProperty(container.addItem(),
  44. VALUE_PROPERTY_ID).setValue("A" + i);
  45. }
  46. Runnable generateNewRows = new Runnable() {
  47. public int id = 0;
  48. @Override
  49. public void run() {
  50. getSession().lock();
  51. try {
  52. Thread.sleep(500);
  53. ++id;
  54. container.removeAllItems();
  55. for (int i = 0; i < 11; i++) {
  56. container.getContainerProperty(
  57. container.addItem(), VALUE_PROPERTY_ID)
  58. .setValue(clickCount + " - " + id
  59. + " - " + i);
  60. }
  61. } catch (InterruptedException e) {
  62. // NOOP
  63. } finally {
  64. getSession().unlock();
  65. }
  66. }
  67. };
  68. new Thread(generateNewRows).start();
  69. });
  70. addComponent(table);
  71. addComponent(button);
  72. }
  73. private static IndexedContainer createContainer() {
  74. IndexedContainer container = new IndexedContainer();
  75. container.addContainerProperty(VALUE_PROPERTY_ID, String.class, "");
  76. return container;
  77. }
  78. /*
  79. * (non-Javadoc)
  80. *
  81. * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
  82. */
  83. @Override
  84. protected String getTestDescription() {
  85. return "Make sure there are no duplicates on the table.";
  86. }
  87. /*
  88. * (non-Javadoc)
  89. *
  90. * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
  91. */
  92. @Override
  93. protected Integer getTicketNumber() {
  94. return 13562;
  95. }
  96. }