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.

ComboPushTiming.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package com.vaadin.tests.components.combobox;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.concurrent.SynchronousQueue;
  5. import java.util.concurrent.ThreadPoolExecutor;
  6. import java.util.concurrent.TimeUnit;
  7. import com.vaadin.server.VaadinSession;
  8. import com.vaadin.tests.components.TestBase;
  9. import com.vaadin.v7.data.util.ObjectProperty;
  10. import com.vaadin.v7.shared.ui.label.ContentMode;
  11. import com.vaadin.v7.ui.ComboBox;
  12. import com.vaadin.v7.ui.Label;
  13. import com.vaadin.v7.ui.ProgressIndicator;
  14. import com.vaadin.v7.ui.TextField;
  15. public class ComboPushTiming extends TestBase {
  16. private int counter = 0;
  17. private final MyExecutor executor = new MyExecutor();
  18. @Override
  19. protected void setup() {
  20. List<String> list = new ArrayList<>();
  21. for (int i = 0; i < 100; i++) {
  22. list.add("Item " + i);
  23. }
  24. final ComboBox cb = new ComboBox("Combobox", list);
  25. cb.setImmediate(true);
  26. cb.setInputPrompt("Enter text");
  27. cb.setDescription("Some Combobox");
  28. addComponent(cb);
  29. final ObjectProperty<String> log = new ObjectProperty<>("");
  30. cb.addFocusListener(event -> {
  31. log.setValue(log.getValue() + "<br>" + counter + ": Focus event!");
  32. counter++;
  33. changeValue(cb);
  34. });
  35. cb.addBlurListener(event -> {
  36. log.setValue(log.getValue() + "<br>" + counter + ": Blur event!");
  37. counter++;
  38. });
  39. TextField field = new TextField("Some textfield");
  40. field.setImmediate(true);
  41. addComponent(field);
  42. Label output = new Label(log);
  43. output.setCaption("Events:");
  44. output.setContentMode(ContentMode.HTML);
  45. addComponent(output);
  46. ProgressIndicator progressIndicator = new ProgressIndicator();
  47. addComponent(progressIndicator);
  48. progressIndicator.setPollingInterval(3000);
  49. }
  50. private void changeValue(final ComboBox cb) {
  51. executor.execute(() -> {
  52. VaadinSession.getCurrent().lock();
  53. try {
  54. cb.setEnabled(true);
  55. cb.setValue("B");
  56. cb.setEnabled(true);
  57. // If this isn't sent by push or poll in the background, the
  58. // problem will go away
  59. } finally {
  60. VaadinSession.getCurrent().unlock();
  61. }
  62. });
  63. }
  64. class MyExecutor extends ThreadPoolExecutor {
  65. public MyExecutor() {
  66. super(5, 20, 20, TimeUnit.SECONDS,
  67. new SynchronousQueue<Runnable>());
  68. }
  69. }
  70. @Override
  71. protected String getDescription() {
  72. return "When an update is received while the popup is open, the suggestion popup blurs away";
  73. }
  74. @Override
  75. protected Integer getTicketNumber() {
  76. return 10924;
  77. }
  78. }