summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/layouts/ComplexGLColumnExpansionWithColSpan.java
blob: f4050ea0855da32ca03cbfd8c5d20e3b95b11809 (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
package com.vaadin.tests.layouts;

import com.vaadin.server.Sizeable;
import com.vaadin.tests.components.AbstractTestCase;
import com.vaadin.ui.Button;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

public class ComplexGLColumnExpansionWithColSpan extends AbstractTestCase {
    private int cols;

    @Override
    protected String getDescription() {
        return "Buttons should stay stacked on left when clicking new button";
    }

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

    @Override
    public void init() {
        final VerticalLayout mainLayout = new VerticalLayout();

        mainLayout.setSpacing(true);
        mainLayout.setMargin(true);
        mainLayout.setHeight(100, Sizeable.UNITS_PERCENTAGE);
        mainLayout.setWidth(100, Sizeable.UNITS_PERCENTAGE);
        setMainWindow(new LegacyWindow("Vaadin Test", mainLayout));

        cols = 1;
        final GridLayout gl = new GridLayout(cols, 3);
        gl.setWidth("1000px");
        // textfield spreads across all cols
        final TextField textfield = new TextField();
        textfield.setWidth(100, Sizeable.UNITS_PERCENTAGE);
        Button b1 = new Button("new button");
        Button b2 = new Button("nothing");
        gl.addComponent(textfield, 0, 0);
        gl.addComponent(b1, 0, 1);
        gl.addComponent(b2, 0, 2);
        b1.setWidth(270, Sizeable.UNITS_PIXELS);
        b2.setWidth(270, Sizeable.UNITS_PIXELS);
        b1.addListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                cols++;
                gl.setColumns(cols);
                Button b1 = new Button("new button" + cols);
                Button b2 = new Button("nothing" + cols);
                gl.addComponent(b1, cols - 1, 1);
                gl.addComponent(b2, cols - 1, 2);
                b1.setWidth(270, Sizeable.UNITS_PIXELS);
                b2.setWidth(270, Sizeable.UNITS_PIXELS);
                // adjust expand ratios...
                if (cols > 0) {
                    // next to last colum 0, last column 100
                    gl.setColumnExpandRatio(cols - 2, 0);
                    gl.setColumnExpandRatio(cols - 1, 100);
                }
                gl.removeComponent(textfield);
                gl.addComponent(textfield, 0, 0, cols - 1, 0);
            }
        });
        gl.setSizeFull();
        mainLayout.addComponent(gl);
        mainLayout.setExpandRatio(gl, 100);
        Button restart = new Button("restart");
        mainLayout.addComponent(restart);
        restart.addListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                mainLayout.getUI().getApplication().close();
            }
        });

    }

}