blob: 040e2793d4c3bf9c3a23dda3aafff912c6504aa9 (
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
|
package com.vaadin.tests.push;
import com.vaadin.annotations.Push;
import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@Push
@Widgetset("com.vaadin.DefaultWidgetSet")
public class PushToggleComponentVisibility extends UI {
@Override
protected void init(VaadinRequest request) {
VerticalLayout mainLayout = new VerticalLayout();
setContent(mainLayout);
Label label = new Label("Please wait");
label.setId("label");
label.setVisible(false);
mainLayout.addComponent(label);
Button button = new Button("Hide me for 3 seconds");
button.setId("hide");
button.addClickListener(event1 -> {
button.setVisible(false);
label.setVisible(true);
new Thread(() -> {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
button.getUI().access(() -> {
button.setVisible(true);
label.setVisible(false);
button.getUI().push();
});
}).start();
});
mainLayout.addComponent(button);
}
}
|