aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/orderedlayout/VerticalLayoutWithEmptyLabel.java
blob: f1702d6b524527304c3240cd92d005537f53d2fa (plain)
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
package com.vaadin.tests.components.orderedlayout;

import com.vaadin.server.Sizeable;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.ui.Table;
import com.vaadin.v7.ui.TextArea;
import com.vaadin.v7.ui.TextField;

public class VerticalLayoutWithEmptyLabel extends AbstractReindeerTestUI {

    private static final float UPPER_BAR_HEIGHT = 42;

    private final VerticalLayout rootLayout = new VerticalLayout();
    private final Label subtitleLabel = new Label();
    private final String rootTitle;

    private Component lowerPanel;

    public VerticalLayoutWithEmptyLabel() {
        rootTitle = "Vaadin Layout Bug";
        getPage().setTitle(rootTitle);
    }

    @Override
    public void setup(VaadinRequest request) {
        buildRootLayout();
        setContent(rootLayout);
    }

    @Override
    public void attach() {
        super.attach();
        rebuildLowerPanel();
    }

    protected void rebuildLowerPanel() {
        updateLowerPanel(null);
    }

    private void updateLowerPanel(Object user) {

        // Remove previous content
        if (lowerPanel != null) {
            rootLayout.removeComponent(lowerPanel);
        }

        // If not logged in, present login form, otherwise check user's rights
        // and build lower panel
        lowerPanel = new MyPanel();

        // Update layout
        rootLayout.addComponent(lowerPanel);
        rootLayout.setExpandRatio(lowerPanel, 1.0f);
        rootLayout.setComponentAlignment(lowerPanel, Alignment.MIDDLE_CENTER);
    }

    protected Component getRootLowerPanel() {
        return lowerPanel;
    }

    protected void buildRootLayout() {
        rootLayout.setSpacing(true);
        rootLayout.setSizeFull();
        rootLayout.setMargin(new MarginInfo(false, true, true, true));
        rootLayout.addComponent(buildRootUpperBar());
        rootLayout.addComponent(buildRootSeparator());
        rebuildLowerPanel();
    }

    protected Component buildRootUpperBar() {

        // Title
        Label titleLabel = new Label(rootTitle);
        titleLabel.addStyleName("pexp-application-title");
        titleLabel.setSizeUndefined();
        titleLabel.setHeight(18, Sizeable.Unit.PIXELS);
        subtitleLabel.setSizeUndefined();
        VerticalLayout titleLayout = new VerticalLayout();
        titleLayout.setSizeUndefined();
        titleLayout.addComponent(titleLabel);
        titleLayout.setComponentAlignment(titleLabel, Alignment.BOTTOM_CENTER);
        titleLayout.addComponent(subtitleLabel);
        titleLayout.setComponentAlignment(subtitleLabel,
                Alignment.BOTTOM_CENTER);

        // Sequence parts
        HorizontalLayout layout = new HorizontalLayout();
        layout.addStyleName("pexp-main-upper-bar");
        layout.setSpacing(true);
        layout.setWidth("100%");
        layout.setHeight(UPPER_BAR_HEIGHT, Sizeable.Unit.PIXELS);
        layout.addComponent(titleLayout);
        layout.setExpandRatio(titleLayout, 1.0f);
        layout.setComponentAlignment(titleLayout, Alignment.BOTTOM_CENTER);
        return layout;
    }

    protected Component buildRootSeparator() {
        VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        Panel panel = new Panel(layout);
        panel.addStyleName("pexp-separator");
        panel.setWidth("100%");
        panel.setHeight(3.0f, Sizeable.Unit.PIXELS);
        return panel;
    }

    class MyPanel extends VerticalLayout {

        private final Table table;
        private final Label myLabel = new Label("");
        private final TextField filterPhoneField = new TextField(
                "Foobar Number");
        private final TextField filterFoobarField = new TextField("Foobar ID");
        private final CheckBox incomingOnlyField = new CheckBox(
                "Incoming foobar only");

        public MyPanel() {

            // Setup layout
            this.setMargin(true);
            setSpacing(true);
            this.setHeight("100%");

            // Setup top layout with controls and fields
            HorizontalLayout topLayout = new HorizontalLayout();
            topLayout.setSpacing(true);

            // Foobar Content
            final TextArea smsContent = new TextArea("Foobar Content");
            topLayout.addComponent(smsContent);
            topLayout.setExpandRatio(smsContent, 1);
            smsContent.setRows(3);
            smsContent.setColumns(40);
            // topLayout.setWidth("100%");
            this.addComponent(topLayout);

            // Foobar phone #
            final TextField smsNumber = new TextField("Foobar Phone #");
            smsNumber.setSizeUndefined();
            smsNumber.setColumns(12);
            smsNumber.setMaxLength(16);
            // smsNumber.setStyleName("pexp-fixed-width");

            // Phone number and button layout
            VerticalLayout buttonNumberLayout = new VerticalLayout();
            buttonNumberLayout.setSizeUndefined();
            buttonNumberLayout.setHeight("100%");
            buttonNumberLayout.addComponent(smsNumber);
            buttonNumberLayout.addComponent(myLabel);
            Button button = new Button("Receive Foobar");
            buttonNumberLayout.addComponent(button);
            buttonNumberLayout.setExpandRatio(button, 1);
            buttonNumberLayout.setComponentAlignment(button,
                    Alignment.BOTTOM_LEFT);
            topLayout.addComponent(buttonNumberLayout);

            // Add message table
            table = new Table();
            table.setWidth("100%");
            table.setHeight("100%");
            this.addComponent(table);
            setExpandRatio(table, 1);

            // Message table controls
            VerticalLayout tableControlsLayout = new VerticalLayout();
            tableControlsLayout.setSizeUndefined();
            tableControlsLayout.setSpacing(true);

            // Configure filter for phone #
            filterPhoneField.setSizeUndefined();
            filterPhoneField.setImmediate(true);
            filterPhoneField.setColumns(12);
            filterPhoneField.setMaxLength(16);
            // this.filterPhoneField.setStyleName("pexp-fixed-width");

            // Configure filter for foobar ID
            filterFoobarField.setSizeUndefined();
            filterFoobarField.setImmediate(true);
            filterFoobarField.setColumns(16);
            filterFoobarField.setMaxLength(16);
            // this.filterFoobarField.setStyleName("pexp-fixed-width");

            // Add filter inputs for phone # and foobar ID
            tableControlsLayout.addComponent(filterPhoneField);
            tableControlsLayout.addComponent(filterFoobarField);
            topLayout.addComponent(tableControlsLayout);
            topLayout.addComponent(incomingOnlyField);
            topLayout.setComponentAlignment(incomingOnlyField,
                    Alignment.BOTTOM_LEFT);
        }
    }

    @Override
    protected String getTestDescription() {
        return "foobar";
    }

    @Override
    protected Integer getTicketNumber() {
        return 10098;
    }
}