aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/window/SubWindows.java
blob: 0ea6b8b21ca51b4d241d6574081c1a11200f5560 (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
package com.vaadin.tests.components.window;

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class SubWindows extends TestBase {

    private Window autoWideWindow;

    @Override
    protected String getDescription() {
        return "Three windows should be shown. "
                + "The width of the one in the upper left corner should be adjusted according to the contents. "
                + "The centered windows width should be set according to the caption and the second textfield should be clipped. "
                + "The third window should be initially the width and height of its content and when resizing the window the content width should be updated so it is always 100% of the window.";
    }

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

    private Component createRemoveButton() {
        Button b = new Button("Remove");
        b.addListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                Button b = event.getButton();
                ComponentContainer cc = (ComponentContainer) b.getParent();
                cc.removeComponent(b);
            }
        });

        return b;
    }

    @Override
    protected void setup() {
        final HorizontalLayout hl = new HorizontalLayout();
        autoWideWindow = new Window("Dialog - width by contents", hl);
        hl.setSizeUndefined();
        hl.addComponent(new TextField("Field 1"));
        hl.addComponent(new TextField("Field 2"));
        hl.addComponent(new Button("Add", new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                hl.addComponent(createRemoveButton());

            }

        }));

        getMainWindow().addWindow(autoWideWindow);

        {
            VerticalLayout vl = new VerticalLayout();
            vl.setMargin(true);
            Window dialog = new Window("Dialog - undefined width", vl);
            vl.addComponent(new TextField("Field 1"));

            TextField tf2 = new TextField("Field 2");
            tf2.setWidth("500px");
            vl.addComponent(tf2);
            vl.addComponent(new Button("Ok"));

            dialog.center();
            getMainWindow().addWindow(dialog);
        }

        {
            VerticalLayout layout = new VerticalLayout();
            layout.setMargin(true);
            Window dialog = new Window("Dialog - width defined by content",
                    layout);
            layout.setHeight(null);
            layout.setWidth("100%");

            TextArea ta = new TextArea();
            ta.setValue("The textfield should fill the window (except margins)."
                    + "\n - Try to resize the window\n");
            ta.setRows(5);
            ta.setWidth("100%");
            layout.addComponent(ta);

            dialog.setPositionX(20);
            dialog.setPositionY(100);
            getMainWindow().addWindow(dialog);
        }

        {
            VerticalLayout layout = new VerticalLayout();
            layout.setMargin(true);
            Window dialog = new Window("Dialog - size defined by content",
                    layout);
            layout.setHeight("100%");
            layout.setWidth("100%");

            TextArea ta = new TextArea();
            ta.setValue("The textfield should fill the window (except margins)."
                    + "\n - Try to resize the window\n");
            ta.setWidth("100%");
            ta.setHeight("100%");
            ta.setRows(5);
            layout.addComponent(ta);

            dialog.setPositionX(20);
            dialog.setPositionY(300);
            getMainWindow().addWindow(dialog);
        }
    }
}