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
|
package com.vaadin.tests.components.select;
import java.util.Iterator;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.tests.components.ComponentTestCase;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.ListSelect;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.TwinColSelect;
public class OptionGroupBaseSelects extends ComponentTestCase<HorizontalLayout> {
private HorizontalLayout layout;
@Override
protected Class<HorizontalLayout> getTestClass() {
return HorizontalLayout.class;
}
@Override
protected void initializeComponents() {
CheckBox cb = new CheckBox("Switch Selects ReadOnly", false);
cb.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
for (Iterator<Component> it = layout.getComponentIterator(); it
.hasNext();) {
Component c = it.next();
if (c instanceof AbstractSelect) {
c.setReadOnly(!c.isReadOnly());
}
}
}
});
CheckBox cb2 = new CheckBox("Switch Selects Enabled", true);
cb2.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
for (Iterator<Component> it = layout.getComponentIterator(); it
.hasNext();) {
Component c = it.next();
if (c instanceof AbstractSelect) {
boolean enabled = !c.isEnabled();
c.setEnabled(enabled);
c.setCaption(c.getCaption().replace(
(enabled ? "disabled" : "enabled"),
(enabled ? "enabled" : "disabled")));
}
}
}
});
HorizontalLayout cbs = new HorizontalLayout();
cbs.setSpacing(true);
cbs.addComponent(cb);
cbs.addComponent(cb2);
addComponent(cbs);
layout = new HorizontalLayout();
layout.setSpacing(true);
layout.addComponent(createSelect(
new ListSelect("List Select, enabled"), true));
layout.addComponent(createSelect(
new ListSelect("List Select, disabled"), false));
layout.addComponent(createSelect(new NativeSelect(
"Native Select, enabled"), true));
layout.addComponent(createSelect(new NativeSelect(
"Native Select, disabled"), false));
layout.addComponent(createSelect(new OptionGroup(
"Option Group, enabled"), true));
layout.addComponent(createSelect(new OptionGroup(
"Option Group, disabled"), false));
layout.addComponent(createSelect(new TwinColSelect(
"Twin Column Select, enabled"), true));
layout.addComponent(createSelect(new TwinColSelect(
"Twin Column Select, disabled"), false));
addTestComponent(layout);
}
private AbstractSelect createSelect(AbstractSelect select, boolean enabled) {
select.addContainerProperty(CAPTION, String.class, null);
for (int i = 0; i < 10; i++) {
select.addItem("" + i).getItemProperty(CAPTION)
.setValue("Item " + i);
if (select instanceof OptionGroup && i % 2 == 1) {
((OptionGroup) select).setItemEnabled("" + i, false);
}
}
select.setEnabled(enabled);
select.setImmediate(true);
return select;
}
}
|