blob: ac5f990915ae8e2b860de62bca8ed20a97f082ff (
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
|
package com.vaadin.tests.tickets;
import java.io.IOException;
import java.util.Map;
import com.vaadin.Application;
import com.vaadin.server.RequestHandler;
import com.vaadin.server.WrappedRequest;
import com.vaadin.server.WrappedResponse;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.VerticalLayout;
public class Ticket1921 extends Application.LegacyApplication implements
RequestHandler {
int state = -1;
int round = 1;
Button button;
VerticalLayout outer, inner;
@Override
public void init() {
outer = new VerticalLayout();
setMainWindow(new LegacyWindow("#1921", outer));
setTheme("tests-tickets");
inner = new VerticalLayout();
outer.addComponent(inner);
button = new Button("foo", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
newState();
}
});
inner.addComponent(button);
outer.setStyleName("red");
inner.setStyleName("blue");
newState();
addRequestHandler(this);
}
public void newState() {
if (state >= 6) {
state = 0;
round++;
} else {
state++;
}
button.setCaption("state " + round + "." + state);
switch (state) {
case 0:
outer.setMargin(true);
inner.setMargin(true);
inner.setSizeFull();
outer.setSizeFull();
button.setSizeFull();
break;
case 1:
button.setSizeUndefined();
break;
case 2:
inner.setMargin(false);
break;
case 3:
outer.setMargin(false);
break;
case 4:
inner.setMargin(true);
break;
case 5:
inner.addComponent(new Label("Added at " + button.getCaption()));
break;
case 6:
outer.addComponent(new Label("Added at " + button.getCaption()));
break;
}
}
@Override
public boolean handleRequest(Application application,
WrappedRequest request, WrappedResponse response)
throws IOException {
Map<String, String[]> parameters = request.getParameterMap();
String[] s = parameters.get("state");
if (s == null || s.length != 1) {
return false;
}
String v[] = s[0].split("\\.");
if (v == null || v.length != 2) {
return false;
}
try {
int rr = Integer.parseInt(v[0]);
int rs = Integer.parseInt(v[1]);
if (rr < round || (rr == round && rs < state)) {
getMainWindow().showNotification(
"Already past requested " + s[0]);
return false;
}
while (round < rr || state < rs) {
newState();
}
} catch (NumberFormatException ignored) {
}
return false;
}
}
|