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