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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
package com.vaadin.tests.tickets;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.data.util.BeanItem;
import com.vaadin.server.LegacyApplication;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.Form;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
public class Ticket677 extends LegacyApplication {
private static final Label info = new Label(
"<li> keep debug window open to see variable changes"
+ "<li> disable root panel w/ toggle button"
+ "<li> toggle one of the subpanels"
+ "<li> we attempt to focus the subpanels first textfield"
+ "<li> focusing should fail (try tabbing as well) [worked previousy]"
+ "<li> no variable changes should be sent from disabled fields [changed sent previously]"
+ "<li> try further toggling and tabbing around",
ContentMode.RAW);
Panel root = new Panel("Enabled");
Panel one = new Panel("Enabled");
Panel two = new Panel("Enabled");
Form form;
Table table;
@Override
public void init() {
LegacyWindow main = new LegacyWindow();
setMainWindow(main);
main.addComponent(info);
HorizontalLayout l = new HorizontalLayout();
main.addComponent(l);
l.addComponent(new Button("Toggle root panel",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
toggle(root);
}
}));
l.addComponent(new Button("Toggle panel one",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
toggle(one);
}
}));
l.addComponent(new Button("Toggle panel two",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
toggle(two);
}
}));
l.addComponent(new Button("Toggle form", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
toggle(form);
}
}));
l.addComponent(new Button("Toggle table", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
toggle(table);
}
}));
GridLayout content = new GridLayout(2, 3);
root.setContent(content);
main.addComponent(root);
TextField tf = new TextField("Enabled");
tf.setImmediate(true);
content.addComponent(tf);
tf = new TextField("Disabled");
tf.setImmediate(true);
tf.setEnabled(false);
content.addComponent(tf);
VerticalLayout oneLayout = new VerticalLayout();
oneLayout.setMargin(true);
one.setContent(oneLayout);
content.addComponent(one);
tf = new TextField("Enabled");
tf.setImmediate(true);
oneLayout.addComponent(tf);
tf = new TextField("Disabled");
tf.setImmediate(true);
tf.setEnabled(false);
oneLayout.addComponent(tf);
VerticalLayout twoLayout = new VerticalLayout();
twoLayout.setMargin(true);
two.setContent(twoLayout);
content.addComponent(two);
tf = new TextField("Enabled");
tf.setImmediate(true);
twoLayout.addComponent(tf);
tf = new TextField("Disabled");
tf.setImmediate(true);
tf.setEnabled(false);
twoLayout.addComponent(tf);
form = new Form();
form.setCaption("Enabled");
form.setFormFieldFactory(new DefaultFieldFactory() {
@Override
public Field<?> createField(Item item, Object propertyId,
Component uiContext) {
Field<?> f = super.createField(item, propertyId, uiContext);
f.setEnabled(!"disabled".equals(propertyId));
return f;
}
});
form.setItemDataSource(new BeanItem<MyBean>(new MyBean()));
content.addComponent(form);
table = new Table("Enabled");
table.setPageLength(7);
table.addContainerProperty("Text", String.class, null);
for (int i = 0; i < 150; i++) {
Item item = table.addItem("Item" + i);
Property<String> p = item.getItemProperty("Text");
p.setValue(i % 5 == 0 ? "enabled" : "disabled");
}
table.setTableFieldFactory(new DefaultFieldFactory() {
@Override
public Field<?> createField(Container container, Object itemId,
Object propertyId, Component uiContext) {
Field<?> f = super.createField(container, itemId, propertyId,
uiContext);
Item item = container.getItem(itemId);
Property<?> p = item.getItemProperty(propertyId);
if ("disabled".equals(p.getValue())) {
f.setEnabled(false);
}
return f;
}
});
table.setEditable(true);
content.addComponent(table);
}
private void toggle(Component c) {
boolean enable = "Disabled".equals(c.getCaption());
c.setEnabled(enable);
c.setCaption((enable ? "Enabled" : "Disabled"));
if (c instanceof ComponentContainer) {
TextField tf = (TextField) ((ComponentContainer) c)
.getComponentIterator().next();
tf.focus();
}
}
class MyBean {
boolean on = false;
int number = 1;
String rw = "read/write";
String r = "read";
String disabled = "disabled";
public boolean isOn() {
return on;
}
public void setOn(boolean on) {
this.on = on;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getRw() {
return rw;
}
public void setRw(String rw) {
this.rw = rw;
}
public String getDisabled() {
return disabled;
}
public void setDisabled(String disabled) {
this.disabled = disabled;
}
public String getR() {
return r;
}
}
}
|