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.label;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.components.AbstractComponentTest;
import com.vaadin.ui.Label;
public class LabelTest extends AbstractComponentTest<Label> implements
ValueChangeListener {
private Command<Label, Object> setValueCommand = new Command<Label, Object>() {
@Override
public void execute(Label c, Object value, Object data) {
c.setValue(value);
}
};
private Command<Label, Boolean> valueChangeListenerCommand = new Command<Label, Boolean>() {
@Override
public void execute(Label c, Boolean value, Object data) {
if (value) {
c.addListener(LabelTest.this);
} else {
c.removeListener(LabelTest.this);
}
}
};
private Command<Label, ContentMode> contentModeCommand = new Command<Label, ContentMode>() {
@Override
public void execute(Label c, ContentMode value, Object data) {
c.setContentMode(value);
}
};
@Override
protected Class<Label> getTestClass() {
return Label.class;
}
@Override
protected void createActions() {
super.createActions();
createContentModeSelect(CATEGORY_FEATURES);
createValueSelect(CATEGORY_FEATURES);
createValueChangeListener(CATEGORY_LISTENERS);
}
private void createValueSelect(String category) {
String subCategory = "Set text value";
createCategory(subCategory, category);
List<String> values = new ArrayList<String>();
values.add("Test");
values.add("A little longer value");
values.add("A very long value with very much text. All in all it is 74 characters long");
values.add("<b>Bold</b>");
values.add("<div style=\"height: 70px; width: 15px; border: 1px dashed red\">With border</div>");
createClickAction("(empty string)", subCategory, setValueCommand, "");
createClickAction("(null)", subCategory, setValueCommand, null);
for (String value : values) {
createClickAction(value, subCategory, setValueCommand, value);
}
}
@SuppressWarnings("deprecation")
private void createContentModeSelect(String category) {
LinkedHashMap<String, ContentMode> options = new LinkedHashMap<String, ContentMode>();
options.put("Text", ContentMode.TEXT);
options.put("Preformatted", ContentMode.PREFORMATTED);
options.put("Raw", ContentMode.RAW);
options.put("UIDL", ContentMode.XML); // Deprecated UIDL mode still used
// to avoid breaking old tests
options.put("XHTML", ContentMode.XHTML);
options.put("XML", ContentMode.XML);
createSelectAction("Content mode", category, options, "Text",
contentModeCommand);
}
private void createValueChangeListener(String category) {
createBooleanAction("Value change listener", category, false,
valueChangeListenerCommand);
}
@Override
public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
Object o = event.getProperty().getValue();
// Distinguish between null and 'null'
String value = "null";
if (o != null) {
value = "'" + o.toString() + "'";
}
log(event.getClass().getSimpleName() + ", new value: " + value);
};
}
|