blob: 2f81c08ae6b679524ea05b00d30805358ffc5987 (
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
package com.vaadin.tests.appengine;
import com.google.apphosting.api.DeadlineExceededException;
import com.vaadin.Application;
import com.vaadin.Application.LegacyApplication;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.server.ClassResource;
import com.vaadin.server.DownloadStream;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI.LegacyWindow;
public class GAESyncTest extends Application.LegacyApplication {
/**
*
*/
private static final long serialVersionUID = -3724319151122707926l;
@Override
public void init() {
setMainWindow(new IntrWindow(this));
}
@Override
public void terminalError(com.vaadin.server.Terminal.ErrorEvent event) {
Throwable t = event.getThrowable();
// Was this caused by a GAE timeout?
while (t != null) {
if (t instanceof DeadlineExceededException) {
getMainWindow().showNotification("Bugger!",
"Deadline Exceeded", Notification.TYPE_ERROR_MESSAGE);
return;
}
t = t.getCause();
}
super.terminalError(event);
}
private class IntrWindow extends LegacyWindow {
private int n = 0;
private static final long serialVersionUID = -6521351715072191625l;
TextField tf;
Label l;
LegacyApplication app;
GridLayout gl;
private IntrWindow(LegacyApplication app) {
this.app = app;
tf = new TextField("Echo thingie");
tf.setImmediate(true);
tf.addListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
IntrWindow.this.showNotification((String) event
.getProperty().getValue());
}
});
addComponent(tf);
l = new Label("" + n);
addComponent(l);
{
Button b = new Button("Slow", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
addComponent(b);
}
{
Button b = new Button("Add", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
if (getUI() == getMainWindow()) {
getUI().getPage().showNotification(
new Notification("main"));
try {
Thread.sleep((5000));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
addImage();
}
});
addComponent(b);
}
gl = new GridLayout(30, 50);
addComponent(gl);
}
private void addImage() {
ClassResource res = new ClassResource("img1.png") {
private static final long serialVersionUID = 1L;
@Override
public DownloadStream getStream() {
try {
Thread.sleep((long) (Math.random() * 5000));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return super.getStream();
}
};
res.setCacheTime(0);
Embedded emb = new Embedded("" + n, res);
emb.setWidth("30px");
emb.setHeight("5px");
gl.addComponent(emb);
l.setValue("" + n++);
}
}
@Override
public LegacyWindow getWindow(String name) {
LegacyWindow w = super.getWindow(name);
if (w == null) {
w = new IntrWindow(this);
addWindow(w);
}
return w;
}
}
|