aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/orderedlayout/SpacingLeak.java
blob: 647c1875688afcfd9cc2048ffa2ce87e2de5c336 (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
package com.vaadin.tests.components.orderedlayout;

import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

/**
 * HorizontalLayout and VerticalLayout should not leak .v-spacing elements via
 * listeners when removing components from a layout.
 * 
 * @since 7.1.12
 * @author Vaadin Ltd
 */
public class SpacingLeak extends UI {

    private HorizontalLayout spacingLayout;

    @Override
    public void init(VaadinRequest req) {
        final VerticalLayout root = new VerticalLayout();
        setContent(root);
        root.setSizeUndefined();

        final Button spacingButton = new Button("Add layout with spacing");
        spacingButton.setId("addbutton");
        root.addComponent(spacingButton);
        spacingButton.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                spacingLayout = new HorizontalLayout();
                spacingLayout.setSpacing(true);
                spacingLayout.setWidth("100%");

                for (int i = 0; i < 100; ++i) {
                    spacingLayout.addComponent(new Button("" + i));
                }

                root.addComponent(spacingLayout);
            }
        });

        final Button removeButton = new Button("Remove layouts");
        removeButton.setId("removebutton");
        root.addComponent(removeButton);
        removeButton.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                root.removeComponent(spacingLayout);
            }
        });
    }
}