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
|
package com.vaadin.tests.layouts.layouttester;
import java.lang.reflect.Method;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.tests.components.AbstractTestCase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Layout;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.Reindeer;
@SuppressWarnings("serial")
public class LayoutTesterApplication extends AbstractTestCase {
Button nextButton = new Button("Next");
private int layoutIndex = -1;
static final String[] layoutGetters = new String[] { "getCaptionsTests",
"getIconsTests", "getRequiredErrorIndicatorsTests",
"getAlignmentTests", "getExpandRatiosTests",
"getMarginSpacingTests", "getComponentAddReplaceMoveTests",
"getComponentSizingTests", "getLayoutSizingTests" };
public static final String NEXT_BUTTON_ID = "nextButton";
private static final String LAYOUT_SELECT_ID = "layoutSelect";
private LegacyWindow mainWindow;
private NativeSelect layoutSelector;
@Override
public void init() {
nextButton.setId(NEXT_BUTTON_ID);
mainWindow = new LegacyWindow("LayoutTesterApplication");
setMainWindow(mainWindow);
nextLayout();
nextButton.addListener(new Button.ClickListener() {
private static final long serialVersionUID = -1577298910202253538L;
@Override
public void buttonClick(ClickEvent event) {
nextLayout();
}
});
}
private void nextLayout() {
try {
mainWindow.removeAllComponents();
HorizontalLayout vlo = new HorizontalLayout();
vlo.setSpacing(true);
++layoutIndex;
if (layoutIndex >= layoutGetters.length) {
layoutIndex = 0;
}
mainWindow.addComponent(vlo);
vlo.addComponent(nextButton);
vlo.addComponent(getLayoutTypeSelect());
vlo.addComponent(new UndefWideLabel(getLayoutGetterMethod(
layoutGetters[layoutIndex]).getName()));
Layout lo = null;
if (layoutSelector.getValue() == VerticalLayout.class) {
lo = getVerticalTestLayout(layoutIndex);
} else if (layoutSelector.getValue() == HorizontalLayout.class) {
lo = getHorizontalTestLayout(layoutIndex);
} else if (layoutSelector.getValue() == GridLayout.class) {
lo = getGridTestLayout(layoutIndex);
}
if (lo != null) {
lo.addStyleName(Reindeer.LAYOUT_BLUE);
mainWindow.addComponent(lo);
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
private Method getLayoutGetterMethod(String method) {
try {
return AbstractLayoutTests.class.getDeclaredMethod(method);
} catch (SecurityException e) {
e.printStackTrace();
throw new RuntimeException(e);
} catch (NoSuchMethodException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public Layout getVerticalTestLayout(int index) throws Exception {
VerticalLayoutTests vlotest = new VerticalLayoutTests(this);
return (Layout) getLayoutGetterMethod(layoutGetters[index]).invoke(
vlotest, (Object[]) null);
}
public Layout getHorizontalTestLayout(int index) throws Exception {
HorizontalLayoutTests hlotest = new HorizontalLayoutTests(this);
return (Layout) getLayoutGetterMethod(layoutGetters[index]).invoke(
hlotest, (Object[]) null);
}
public Layout getGridTestLayout(int index) throws Exception {
GridLayoutTests hlotest = new GridLayoutTests(this);
return (Layout) getLayoutGetterMethod(layoutGetters[index]).invoke(
hlotest, (Object[]) null);
}
private NativeSelect getLayoutTypeSelect() {
if (layoutSelector == null) {
layoutSelector = new NativeSelect();
layoutSelector.setId(LAYOUT_SELECT);
layoutSelector.addItem(VerticalLayout.class);
layoutSelector.addItem(HorizontalLayout.class);
layoutSelector.addItem(GridLayout.class);
layoutSelector.setNullSelectionAllowed(false);
layoutSelector.setImmediate(true);
layoutSelector.select(VerticalLayout.class);
layoutSelector.addListener(new Property.ValueChangeListener() {
private static final long serialVersionUID = -605319614765838359L;
@Override
public void valueChange(ValueChangeEvent event) {
layoutIndex = -1;
nextLayout();
}
});
}
return layoutSelector;
}
@Override
protected String getDescription() {
return "Test application for VerticalLayout, HorizontalLayout, and GridLayout";
}
@Override
protected Integer getTicketNumber() {
return 5334;
}
}
|