]> source.dussan.org Git - vaadin-framework.git/blob
bb88411fcdfc267179092ba11c567e0d5d5b601d
[vaadin-framework.git] /
1 /*
2  * Copyright 2000-2016 Vaadin Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.vaadin.tests.components.gridlayout;
17
18 import com.vaadin.server.VaadinRequest;
19 import com.vaadin.tests.components.AbstractReindeerTestUI;
20 import com.vaadin.ui.Alignment;
21 import com.vaadin.ui.GridLayout;
22 import com.vaadin.ui.Label;
23 import com.vaadin.ui.VerticalLayout;
24 import com.vaadin.v7.ui.TextField;
25
26 /**
27  * Test for grid required indicator location within slots.
28  */
29 public class GridLayoutRequiredIndicatorLocation extends AbstractReindeerTestUI {
30
31     @Override
32     protected void setup(VaadinRequest request) {
33         getPage().getCurrent().getStyles()
34                 .add(".allow-overflow { overflow: visible; }");
35         getPage().getCurrent().getStyles()
36                 .add(".colored { background: lime; overflow: visible; }");
37         getPage().getCurrent().getStyles()
38                 .add(".pink { background: pink; overflow: visible; }");
39         getPage().getCurrent().getStyles()
40                 .add(".v-gridlayout-slot { border: 1px solid red; }");
41
42         GridLayout rootLayout = new GridLayout(2, 2);
43         rootLayout.addStyleName("allow-overflow");
44         rootLayout.setSpacing(true);
45         addComponent(rootLayout);
46
47         GridLayout gridLayout = createGridLayout(false);
48         gridLayout.addStyleName("allow-overflow");
49         gridLayout.addStyleName("colored");
50         rootLayout.addComponent(gridLayout);
51
52         // for reference, VerticalLayout does it right
53         VerticalLayout vl = createVerticalLayout(false);
54         vl.addStyleName("allow-overflow");
55         vl.addStyleName("colored");
56         rootLayout.addComponent(vl);
57
58         GridLayout gridLayout2 = createGridLayout(true);
59         gridLayout2.addStyleName("allow-overflow");
60         gridLayout2.addStyleName("colored");
61         rootLayout.addComponent(gridLayout2);
62
63         VerticalLayout vl2 = createVerticalLayout(true);
64         vl2.addStyleName("allow-overflow");
65         vl2.addStyleName("colored");
66         rootLayout.addComponent(vl2);
67     }
68
69     private VerticalLayout createVerticalLayout(boolean useCaption) {
70         VerticalLayout vl = new VerticalLayout();
71         vl.setWidth("320px");
72
73         addLabel(vl, "200px", Alignment.MIDDLE_LEFT, useCaption);
74         addLabel(vl, "40%", Alignment.MIDDLE_LEFT, useCaption);
75         addLabel(vl, "100%", Alignment.MIDDLE_LEFT, useCaption);
76         addLabel(vl, "200px", Alignment.MIDDLE_CENTER, useCaption);
77         addLabel(vl, "30%", Alignment.MIDDLE_CENTER, useCaption);
78         addLabel(vl, "100%", Alignment.MIDDLE_CENTER, useCaption);
79         addLabel(vl, "200px", Alignment.MIDDLE_RIGHT, useCaption);
80         addLabel(vl, "50%", Alignment.MIDDLE_RIGHT, useCaption);
81         addLabel(vl, "100%", Alignment.MIDDLE_RIGHT, useCaption);
82         return vl;
83     }
84
85     private GridLayout createGridLayout(boolean useCaption) {
86         GridLayout gridLayout = new GridLayout();
87         gridLayout.setColumns(2);
88         gridLayout.setWidth("500px");
89         gridLayout.setColumnExpandRatio(0, 0);
90         gridLayout.setColumnExpandRatio(1, 1);
91
92         addLabel(gridLayout, "200px", Alignment.MIDDLE_LEFT, useCaption);
93         addLabel(gridLayout, "40%", Alignment.MIDDLE_LEFT, useCaption);
94         addLabel(gridLayout, "100%", Alignment.MIDDLE_LEFT, useCaption);
95         addLabel(gridLayout, "200px", Alignment.MIDDLE_CENTER, useCaption);
96         addLabel(gridLayout, "30%", Alignment.MIDDLE_CENTER, useCaption);
97         addLabel(gridLayout, "100%", Alignment.MIDDLE_CENTER, useCaption);
98         addLabel(gridLayout, "200px", Alignment.MIDDLE_RIGHT, useCaption);
99         addLabel(gridLayout, "50%", Alignment.MIDDLE_RIGHT, useCaption);
100         addLabel(gridLayout, "100%", Alignment.MIDDLE_RIGHT, useCaption);
101         return gridLayout;
102     }
103
104     private void addLabel(GridLayout layout, String width, Alignment alignment,
105             boolean useCaption) {
106         Label label = new Label("Align " + alignment.getHorizontalAlignment()
107                 + " width " + width);
108         label.setWidth("180px");
109         label.addStyleName("pink");
110         layout.addComponent(label);
111
112         // TODO also test with captions
113         TextField field = new TextField(useCaption ? "caption" : null);
114         field.setRequired(true);
115         field.setWidth(width);
116         layout.addComponent(field);
117         layout.setComponentAlignment(field, alignment);
118     }
119
120     private void addLabel(VerticalLayout layout, String width,
121             Alignment alignment, boolean useCaption) {
122         TextField field = new TextField(useCaption ? "caption" : null);
123         field.setRequired(true);
124         field.setWidth(width);
125         layout.addComponent(field);
126         layout.setComponentAlignment(field, alignment);
127     }
128
129     @Override
130     protected Integer getTicketNumber() {
131         return 18418;
132     }
133
134     @Override
135     protected String getTestDescription() {
136         return "If a GridLayout slot has a size smaller than 100%, the required indicators should be at the end of each field";
137     }
138
139 }