aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTemplate.java
blob: 2e1ac21892d8e68f89b73abd5a23ad4806805cbc (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
package com.vaadin.tests.components.customlayout;

import java.io.IOException;
import java.io.InputStream;

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.CustomLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;

public class CustomLayoutUsingTemplate extends TestBase implements
        ClickListener {

    CustomLayout layout;
    Button button1 = new Button("Add Button to first location", this);
    Button button2 = new Button("Add TextField to second location", this);

    @Override
    protected void setup() {
        String thisPackage = CustomLayoutUsingTemplate.class.getName().replace(
                '.', '/');
        thisPackage = thisPackage.replaceAll(
                CustomLayoutUsingTemplate.class.getSimpleName() + "$", "");
        String template = thisPackage + "template.htm";
        InputStream is = getClass().getClassLoader().getResourceAsStream(
                template);

        addComponent(button1);

        try {
            layout = new CustomLayout(is);
            addComponent(layout);
        } catch (IOException e) {
            addComponent(new Label(e.getMessage()));
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    @Override
    protected String getDescription() {
        return "Test for using a CustomLayout with a template read from an input stream and passed through the state";
    }

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

    @Override
    public void buttonClick(ClickEvent event) {
        if (event.getButton() == button1) {
            layout.addComponent(button2, "location1");
        } else {
            layout.addComponent(new TextField("A text field!"), "location2");
        }
    }
}