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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
package com.vaadin.tests.layouts.layouttester;
import com.vaadin.server.Resource;
import com.vaadin.server.ThemeResource;
import com.vaadin.server.UserError;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.AbstractLayout;
import com.vaadin.ui.AbstractOrderedLayout;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.ui.Table;
import com.vaadin.v7.ui.TextField;
/**
*
* Base class for Layout tests.
*/
public abstract class BaseLayoutTestUI extends AbstractReindeerTestUI {
protected static final String FOLDER_16_PNG = "../icons/runo/16/folder.png";
protected static final String CALENDAR_32_PNG = "../runo/icons/16/calendar.png";
protected static final String LOCK_16_PNG = "../runo/icons/16/lock.png";
protected static final String GLOBE_16_PNG = "../runo/icons/16/globe.png";
public Alignment[] alignments = new Alignment[] { Alignment.TOP_LEFT,
Alignment.TOP_CENTER, Alignment.TOP_RIGHT, Alignment.MIDDLE_LEFT,
Alignment.MIDDLE_CENTER, Alignment.MIDDLE_RIGHT,
Alignment.BOTTOM_LEFT, Alignment.BOTTOM_CENTER,
Alignment.BOTTOM_RIGHT };
public final String[] CAPTIONS = { "", "VeryLongOneWordCaption",
"Very long caption of 50 approximately symbols aaaaaaaaaaaa aaaaaa aaa " };
Resource[] ICONS = { new ThemeResource(CALENDAR_32_PNG),
new ThemeResource(LOCK_16_PNG), new ThemeResource(GLOBE_16_PNG) };
public AbstractComponent[] components = new AbstractComponent[alignments.length];
protected AbstractOrderedLayout l1;
protected AbstractOrderedLayout l2;
protected Class<? extends AbstractLayout> layoutClass;
protected VerticalLayout mainLayout = new VerticalLayout();
public BaseLayoutTestUI(Class<? extends AbstractLayout> layoutClass) {
super();
fillComponents();
this.layoutClass = layoutClass;
}
protected void init() {
try {
l1 = (AbstractOrderedLayout) layoutClass.newInstance();
l2 = (AbstractOrderedLayout) layoutClass.newInstance();
l1.setMargin(false);
l1.setSpacing(false);
l2.setMargin(false);
l2.setSpacing(false);
} catch (InstantiationException | IllegalAccessException e1) {
e1.printStackTrace();
}
if (layoutClass.equals(HorizontalLayout.class)) {
setLayoutMeasures(l1, l2, "600px", "400px");
} else if (layoutClass.equals(VerticalLayout.class)) {
setLayoutMeasures(l1, l2, "400px", "400px");
} else {
setDefaultForVertical(l1, l2);
}
}
private void fillComponents() {
for (int i = 0; i < components.length; i++) {
String name = "Field" + i;
TextField field = new TextField(alignments[i].getVerticalAlignment()
+ " " + alignments[i].getHorizontalAlignment());
field.setValue(name);
components[i] = field;
}
}
protected AbstractLayout createLabelsFields(
Class<? extends AbstractComponent> compType) {
return createLabelsFields(compType, false, null);
}
protected void getLayoutForLayoutSizing(final String compType) {
l2.setSpacing(false);
l2.setMargin(false);
final AbstractComponent c1 = getTestTable();
final AbstractComponent c2 = getTestTable();
class SetSizeButton extends Button {
SetSizeButton(final String size) {
super();
setCaption("Set size " + size);
addClickListener(event -> {
if (compType == "layout") {
l2.setHeight(size);
l2.setWidth(size);
} else if (compType == "component") {
c2.setHeight(size);
c2.setWidth(size);
c2.setCaption("Configured width");
}
});
}
}
Button btn1 = new SetSizeButton("350px");
Button btn2 = new SetSizeButton("-1px");
Button btn3 = new SetSizeButton("75%");
Button btn4 = new SetSizeButton("100%");
Label spacer = new Label(
"<div style='height: 1px'></div><hr /><div style='height: 1px'></div>",
ContentMode.HTML);
spacer.setWidth("100%");
l1.addComponent(btn1);
l1.addComponent(btn2);
l1.addComponent(btn3);
l1.addComponent(btn4);
l2.addComponent(c1);
l2.addComponent(spacer);
l2.addComponent(c2);
l2.setExpandRatio(c1, 0.5f);
l2.setExpandRatio(c2, 0.5f);
btn2.addClickListener(event -> {
Label newLabel = new Label("--- NEW LABEL ---");
newLabel.setSizeUndefined();
l2.addComponent(newLabel);
});
btn2.setCaption(btn2.getCaption() + " + add Label");
}
protected Table getTestTable() {
Table t = new Table();
t.setSizeFull();
t.setCaption("100% default width");
t.addContainerProperty("test", String.class, null);
t.addItem(new Object[] { "qwertyuiop asdfghjköäxccvbnm,m,." }, 1);
t.addItem(new Object[] { "YGVYTCTCTRXRXRXRX" }, 2);
return t;
}
protected AbstractLayout createLabelsFields(
Class<? extends AbstractComponent> compType, boolean useIcon,
String ErrorMessage) {
AbstractOrderedLayout mainLayout = new VerticalLayout();
mainLayout.setSpacing(false);
mainLayout.setMargin(false);
AbstractLayout curLayout = null;
try {
curLayout = layoutClass.newInstance();
if (curLayout instanceof AbstractOrderedLayout) {
((AbstractOrderedLayout) curLayout).setMargin(false);
((AbstractOrderedLayout) curLayout).setSpacing(false);
}
} catch (InstantiationException | IllegalAccessException e1) {
e1.printStackTrace();
}
final Component[] components = new Component[CAPTIONS.length];
for (int i = 0; i < components.length; i++) {
AbstractComponent comp = null;
try {
comp = compType.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
components[i] = comp;
comp.setCaption(CAPTIONS[i]);
if (useIcon) {
comp.setIcon(ICONS[i]);
}
if (ErrorMessage != null) {
if (ErrorMessage.isEmpty()) {
comp.setComponentError(new UserError(null));
} else {
comp.setComponentError(new UserError(ErrorMessage));
}
}
// if component is a tab sheet add two tabs for it
if (comp instanceof TabSheet) {
comp.setSizeUndefined();
TabSheet tab = (TabSheet) comp;
tab.addTab(new UndefWideLabel("TAB1"), "TAB1",
new ThemeResource(GLOBE_16_PNG));
tab.addTab(new UndefWideLabel("TAB2"), "TAB2", null);
}
curLayout.addComponent(comp);
mainLayout.addComponent(curLayout);
}
return mainLayout;
}
/*
* (non-Javadoc)
*
* @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
* VaadinRequest)
*/
@Override
protected void setup(VaadinRequest request) {
mainLayout.setMargin(false);
mainLayout.setSpacing(false);
mainLayout.setSizeUndefined();
getLayout().setSizeUndefined();
if (getLayout().getParent() instanceof VerticalLayout) {
((VerticalLayout) getLayout().getParent()).setSizeUndefined();
}
mainLayout.addComponent(l1);
mainLayout.addComponent(l2);
addComponent(mainLayout);
}
/*
* (non-Javadoc)
*
* @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
*/
@Override
protected String getTestDescription() {
return null;
}
protected void setLayoutMeasures(AbstractOrderedLayout l1,
AbstractOrderedLayout l2, String w, String h) {
l1.setWidth(w);
l1.setHeight(h);
l2.setWidth(w);
l2.setHeight(h);
}
protected void setDefaultForVertical(AbstractOrderedLayout l1,
AbstractOrderedLayout l2) {
l1.setWidth("800px");
l1.setHeight("600px");
l2.setWidth("800px");
l2.setHeight("600px");
}
protected void setDefaultForHorizontal(AbstractOrderedLayout l1,
AbstractOrderedLayout l2) {
l1.setWidth("600px");
l1.setHeight("600px");
l2.setWidth("600px");
l2.setHeight("600px");
}
/*
* (non-Javadoc)
*
* @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
*/
@Override
protected Integer getTicketNumber() {
// TODO Auto-generated method stub
return null;
}
}
|