aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/tickets/Ticket2048.java
blob: 05ca9c4526e35fe50d0ed830a036286fed9685cd (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
package com.vaadin.tests.tickets;

import com.vaadin.LegacyApplication;
import com.vaadin.server.ThemeResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
import com.vaadin.ui.Panel;
import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.VerticalLayout;

public class Ticket2048 extends LegacyApplication {

    private Embedded embedded;
    private Panel p;
    private VerticalLayout orderedLayout;

    @Override
    public void init() {
        LegacyWindow w = new LegacyWindow(getClass().getSimpleName());
        setMainWindow(w);
        // setTheme("tests-tickets");
        // splitPanel = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL);
        // getMainWindow().setContent(splitPanel);

        // GridLayout layout = new GridLayout(10, 10);
        // w.setContent(layout);
        // gridLayout = new GridLayout(1, 1);
        orderedLayout = new VerticalLayout();

        getMainWindow().setContent(orderedLayout);
        // getMainWindow().setContent(new GridLayout(1, 1));
        getMainWindow().setSizeFull();
        getMainWindow().getContent().setSizeFull();

        createUI(orderedLayout);
        // createUI(gridLayout);

    }

    private void createUI(Layout layout) {
        // Button sw = new Button("Switch", new ClickListener() {
        //
        // public void buttonClick(ClickEvent event) {
        // Layout l = getMainWindow().getLayout();
        // if (l == orderedLayout) {
        // getMainWindow().setContent(gridLayout);
        // } else {
        // getMainWindow().setContent(orderedLayout);
        // }
        //
        // }
        // });
        // layout.addComponent(sw);

        Layout ol = new GridLayout(1, 2);
        p = new Panel("Panel", ol);
        p.setSizeFull();
        Label l = new Label("Spacer");
        l.setHeight("400px");
        p.addComponent(l);

        embedded = new Embedded(null, new ThemeResource(
                "icons/64/folder-add.png"));
        layout.addComponent(embedded);
        Button b = new Button(
                "Replace image with new embedded component (flashes)",
                new ClickListener() {

                    @Override
                    public void buttonClick(ClickEvent event) {
                        Embedded newEmbedded = new Embedded(null,
                                new ThemeResource("icons/64/folder-add.png"));
                        getMainWindow().getContent().replaceComponent(embedded,
                                newEmbedded);
                        embedded = newEmbedded;

                    }

                });
        p.addComponent(b);

        b = new Button("Change image source (is fine)", new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                String img = "folder-add";
                if (((ThemeResource) embedded.getSource()).getResourceId()
                        .contains("folder-add")) {
                    img = "folder-delete";
                }
                embedded.setSource(new ThemeResource("icons/64/" + img + ".png"));

            }

        });

        p.addComponent(b);
        layout.addComponent(p);
    }
}