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

import java.util.Iterator;

import com.vaadin.Application;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI.LegacyWindow;

public class Ticket1970 extends Application.LegacyApplication {

    @Override
    public void init() {
        setMainWindow(createWindow());
    }

    @Override
    public LegacyWindow getWindow(String name) {

        // If we already have the requested window, use it
        LegacyWindow w = super.getWindow(name);
        if (w == null) {

            // If no window found, create it
            w = createExtraWindow(name);
        }
        return w;
    }

    private LegacyWindow createExtraWindow(String name) {
        final LegacyWindow w = new LegacyWindow("Extra window: " + name);
        w.setName(name);
        addWindow(w);
        w.addComponent(new Label(
                "This window has been created on fly for name: " + name));
        w.addComponent(new Button("Show open windows",
                new Button.ClickListener() {

                    @Override
                    public void buttonClick(ClickEvent event) {
                        String openWindows = "";
                        for (Iterator<LegacyWindow> i = getWindows().iterator(); i
                                .hasNext();) {
                            LegacyWindow t = i.next();
                            openWindows += (openWindows.length() > 0 ? "," : "")
                                    + t.getName();
                        }
                        w.showNotification(openWindows);
                    }
                }));

        return w;
    }

    private LegacyWindow createWindow() {
        final LegacyWindow w = new LegacyWindow();
        w.addComponent(new Button("Show the name of the application",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        w.showNotification("Name of this window = "
                                + w.getName());
                    }
                }));
        w.addComponent(new Label("<a href='" + getURL().toExternalForm() + "'>"
                + getURL().toExternalForm() + "</a>", ContentMode.XHTML));
        w.addComponent(new Label(
                "<h2>How to reproduce</h2>Open the above link in another browser"
                        + " window and then press the Show-button on this window.",
                ContentMode.XHTML));

        return w;
    }
}