blob: abeaf50e5a93f9253b22a95b2344a12d0a47f66b (
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
|
package com.vaadin.tests.components.table;
import com.vaadin.server.LegacyApplication;
import com.vaadin.ui.Label;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.data.Container;
import com.vaadin.v7.data.util.IndexedContainer;
import com.vaadin.v7.ui.ProgressIndicator;
import com.vaadin.v7.ui.Table;
public class TableFirstRowFlicker extends LegacyApplication {
Table t;
@Override
public void init() {
LegacyWindow mainWindow = new LegacyWindow(getClass().getName());
setMainWindow(mainWindow);
mainWindow.getContent().setSizeFull();
t = new Table();
t.setSizeFull();
t.setSelectable(true);
t.setContainerDataSource(buildContainer());
mainWindow.addComponent(t);
((VerticalLayout) mainWindow.getContent()).setExpandRatio(t, 1);
// Button button = new Button("Refresh");
// button.addListener(event -> t.refreshRowCache());
// mainWindow.addComponent(button);
ProgressIndicator pi = new ProgressIndicator();
pi.setPollingInterval(1000);
pi.setIndeterminate(true);
mainWindow.addComponent(pi);
Thread r = new Thread() {
@Override
public void run() {
while (t != null) {
t.getUI().getSession().lock();
try {
int firstId = t.getCurrentPageFirstItemIndex();
Object selected = t.getValue();
t.setContainerDataSource(buildContainer());
t.setValue(selected);
t.setCurrentPageFirstItemIndex(firstId);
// lighter alternative for all of above
// t.refreshRowCache();
} finally {
t.getUI().getSession().unlock();
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("Table update thread stopped");
}
};
r.start();
}
@Override
public void close() {
t = null;
super.close();
}
private Container buildContainer() {
IndexedContainer cont = new IndexedContainer();
cont.addContainerProperty("name", Label.class, null);
for (int i = 0; i < 10000; i++) {
cont.addItem(i);
Label l = new Label("Item " + i);
l.setHeight("50px");
cont.getContainerProperty(i, "name").setValue(l);
}
return cont;
}
}
|