]> source.dussan.org Git - vaadin-framework.git/blob
6cacd68b59e3e78c247fb64aa9893167a47efaef
[vaadin-framework.git] /
1 package com.vaadin.tests.components.abstractfield;
2
3 import java.util.HashSet;
4 import java.util.Set;
5
6 import com.vaadin.server.VaadinRequest;
7 import com.vaadin.tests.components.AbstractTestUI;
8 import com.vaadin.ui.AbsoluteLayout;
9 import com.vaadin.ui.CheckBox;
10 import com.vaadin.ui.Component;
11 import com.vaadin.ui.ComponentContainer;
12 import com.vaadin.ui.CssLayout;
13 import com.vaadin.ui.GridLayout;
14 import com.vaadin.ui.HorizontalLayout;
15 import com.vaadin.ui.Label;
16 import com.vaadin.ui.VerticalLayout;
17 import com.vaadin.v7.ui.Field;
18 import com.vaadin.v7.ui.TextField;
19
20 public class RequiredIndicatorForFieldsWithoutCaption extends AbstractTestUI {
21     private Set<Field> fields = new HashSet<Field>();
22
23     @Override
24     protected void setup(VaadinRequest request) {
25
26         CheckBox required = new CheckBox("Fields required", true);
27         required.setImmediate(true);
28         required.addValueChangeListener(event -> {
29             boolean newRequired = event.getValue();
30             for (Field f : fields) {
31                 f.setRequired(newRequired);
32             }
33         });
34         addComponent(required);
35         addComponent(createWrappedTextField(new GridLayout(2, 1)));
36         addComponent(createWrappedTextField(new VerticalLayout()));
37         addComponent(createWrappedTextField(new HorizontalLayout()));
38         AbsoluteLayout al = new AbsoluteLayout();
39         al.setWidth("400px");
40         al.setHeight("100px");
41         addComponent(createWrappedTextField(al));
42         addComponent(createWrappedTextField(new CssLayout()));
43     }
44
45     /**
46      * @since
47      * @param gridLayout
48      * @return
49      */
50     private Component createWrappedTextField(ComponentContainer container) {
51         TextField tf = new TextField();
52         tf.setRequired(true);
53         tf.setWidth(200, Unit.PIXELS);
54         fields.add(tf);
55         container.addComponent(new Label(container.getClass().getSimpleName()));
56         container.addComponent(tf);
57         if (container instanceof AbsoluteLayout) {
58             ((AbsoluteLayout) container).getPosition(tf).setLeft(100.0f,
59                     Unit.PIXELS);
60             ((AbsoluteLayout) container).getPosition(tf).setTop(50.0f,
61                     Unit.PIXELS);
62         }
63
64         return container;
65     }
66
67     /*
68      * (non-Javadoc)
69      *
70      * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
71      */
72     @Override
73     protected String getTestDescription() {
74         return "Test for ensuring that the required indicator is visible for fields even when they would not otherwise have a caption";
75     }
76
77     /*
78      * (non-Javadoc)
79      *
80      * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
81      */
82     @Override
83     protected Integer getTicketNumber() {
84         return 12077;
85     }
86 }