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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
package com.vaadin.tests.components.abstractfield;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.ui.AbstractTextField;
import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
public abstract class AbstractTextFieldTest<T extends AbstractTextField>
extends AbstractFieldTest<T> implements TextChangeListener {
private Command<T, Integer> maxlengthCommand = new Command<T, Integer>() {
@Override
public void execute(T c, Integer value, Object data) {
c.setMaxLength(value);
}
};
private Command<T, Boolean> nullSelectionAllowedCommand = new Command<T, Boolean>() {
@Override
public void execute(T c, Boolean value, Object data) {
c.setNullSettingAllowed(value);
}
};
private Command<T, String> nullRepresentationCommand = new Command<T, String>() {
@Override
public void execute(T c, String value, Object data) {
c.setNullRepresentation(value);
}
};
private Command<T, String> inputPromptCommand = new Command<T, String>() {
@Override
public void execute(T c, String value, Object data) {
c.setInputPrompt(value);
}
};
private Command<T, Boolean> textChangeListenerCommand = new Command<T, Boolean>() {
@Override
public void execute(T c, Boolean value, Object data) {
if (value) {
c.addListener((TextChangeListener) AbstractTextFieldTest.this);
} else {
c.removeListener((TextChangeListener) AbstractTextFieldTest.this);
}
}
};
private Command<T, Integer> colsCommand = new Command<T, Integer>() {
@Override
public void execute(T c, Integer value, Object data) {
c.setColumns(value);
}
};
private Command<T, TextChangeEventMode> textChangeEventModeCommand = new Command<T, TextChangeEventMode>() {
@Override
public void execute(T c, TextChangeEventMode value, Object data) {
c.setTextChangeEventMode(value);
}
};
private Command<T, Integer> textChangeTimeoutCommand = new Command<T, Integer>() {
@Override
public void execute(T c, Integer value, Object data) {
c.setTextChangeTimeout(value);
}
};
private Command<T, Range> selectionRangeCommand = new Command<T, Range>() {
@Override
public void execute(T c, Range value, Object data) {
c.setSelectionRange(value.getStart(),
value.getEnd() - value.getStart());
}
};
private Command<T, Object> selectAllCommand = new Command<T, Object>() {
@Override
public void execute(T c, Object value, Object data) {
c.selectAll();
}
};
private Command<T, Integer> setCursorPositionCommand = new Command<T, Integer>() {
@Override
public void execute(T c, Integer value, Object data) {
c.setCursorPosition(value);
}
};
@Override
protected void createActions() {
super.createActions();
createSetTextValueAction(CATEGORY_ACTIONS);
createNullSettingAllowedAction(CATEGORY_FEATURES);
createNullRepresentationAction(CATEGORY_FEATURES);
createMaxLengthAction(CATEGORY_FEATURES);
createInputPromptAction(CATEGORY_FEATURES);
createColsAction(CATEGORY_STATE);
createTextChangeListener(CATEGORY_LISTENERS);
createTextChangeEventModeAction(CATEGORY_FEATURES);
createTextChangeEventTimeoutAction(CATEGORY_FEATURES);
createSetTextValueAction(CATEGORY_ACTIONS);
createCursorPositionAction(CATEGORY_ACTIONS);
createSelectionRangeAction(CATEGORY_ACTIONS);
}
private void createNullSettingAllowedAction(String category) {
createBooleanAction("Null selection allowed", category, true,
nullSelectionAllowedCommand);
}
private void createNullRepresentationAction(String category) {
LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
options.put("-", null);
options.put("null", "null");
options.put("This is empty", "This is empty");
options.put("- Nothing -", "- Nothing -");
createSelectAction("Null representation", category, options, "null",
nullRepresentationCommand);
}
private void createMaxLengthAction(String category) {
LinkedHashMap<String, Integer> options = createIntegerOptions(100);
options.put("-", -1);
createSelectAction("Max length", category, options, "-",
maxlengthCommand);
}
public class Range {
private int start;
private int end;
public Range(int start, int end) {
this.start = start;
this.end = end;
}
public int getStart() {
return start;
}
public int getEnd() {
return end;
}
@Override
public String toString() {
return start + "-" + end;
}
}
private void createSelectionRangeAction(String category) {
List<Range> options = new ArrayList<Range>();
options.add(new Range(0, 10));
options.add(new Range(0, 1));
options.add(new Range(0, 2));
options.add(new Range(1, 2));
options.add(new Range(2, 5));
options.add(new Range(5, 10));
createCategory("Select range", category);
createClickAction("All", "Select range", selectAllCommand, null);
for (Range range : options) {
createClickAction(range.toString(), "Select range",
selectionRangeCommand, range);
}
}
private void createCursorPositionAction(String category) {
String subCategory = "Set cursor position";
createCategory(subCategory, category);
for (int i = 0; i < 20; i++) {
createClickAction(String.valueOf(i), subCategory,
setCursorPositionCommand, Integer.valueOf(i));
}
}
private void createTextChangeEventTimeoutAction(String category) {
LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
options.put("0", 0);
options.put("100ms", 100);
options.put("500ms", 500);
options.put("1s", 1000);
options.put("2s", 2000);
options.put("5s", 5000);
createSelectAction("TextChange timeout", category, options, "0",
textChangeTimeoutCommand);
}
private void createTextChangeEventModeAction(String category) {
LinkedHashMap<String, TextChangeEventMode> options = new LinkedHashMap<String, AbstractTextField.TextChangeEventMode>();
for (TextChangeEventMode m : TextChangeEventMode.values()) {
options.put(m.toString(), m);
}
createSelectAction("TextChange event mode", category, options,
TextChangeEventMode.EAGER.toString(),
textChangeEventModeCommand);
}
private void createTextChangeListener(String category) {
createBooleanAction("Text change listener", category, false,
textChangeListenerCommand);
}
private void createColsAction(String category) {
LinkedHashMap<String, Integer> options = createIntegerOptions(20);
createSelectAction("Columns", category, options, "0", colsCommand);
}
private void createInputPromptAction(String category) {
LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
options.put("-", null);
options.put("Enter a value", "Enter a value");
options.put("- Click here -", "- Click here -");
createSelectAction("Input prompt", category, options, "-",
inputPromptCommand);
}
@Override
public void textChange(TextChangeEvent event) {
AbstractTextField tf = (AbstractTextField) event.getComponent();
log("TextChangeEvent: text='" + event.getText() + "', cursor position="
+ event.getCursorPosition() + " (field cursor pos: "
+ tf.getCursorPosition() + ")");
}
}
|