aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java
blob: a3ca2420f7467f7f545c8f925bc261000ec117ff (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
package com.vaadin.tests.components.ui;

import com.vaadin.server.ExternalResource;
import com.vaadin.server.VaadinSession;
import com.vaadin.server.WrappedRequest;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.components.AbstractTestUIProvider;
import com.vaadin.ui.Label;
import com.vaadin.ui.Link;
import com.vaadin.ui.UI;

public class LazyInitUIs extends AbstractTestUIProvider {

    // @EagerInit
    private static class EagerInitUI extends UI {
        @Override
        public void init(WrappedRequest request) {
            addComponent(getRequestInfo("EagerInitUI", request));
        }
    }

    @Override
    public UI createInstance(VaadinSession application, Class<? extends UI> type,
            WrappedRequest request) {
        return getUI(request);
    }

    @Override
    public Class<? extends UI> getUIClass(VaadinSession application,
            WrappedRequest request) {
        return getUI(request).getClass();
    }

    private UI getUI(WrappedRequest request) {
        if (request.getParameter("lazyCreate") != null) {
            // UI created on second request
            UI uI = new UI() {
                @Override
                protected void init(WrappedRequest request) {
                    addComponent(getRequestInfo("LazyCreateUI", request));
                }
            };
            return uI;
        } else if (request.getParameter("eagerInit") != null) {
            // UI inited on first request
            return new EagerInitUI();
        } else {
            // The standard UI
            UI uI = new UI() {
                @Override
                protected void init(WrappedRequest request) {
                    addComponent(getRequestInfo("NormalUI", request));

                    Link lazyCreateLink = new Link("Open lazyCreate UI",
                            new ExternalResource(VaadinSession.getCurrent()
                                    .getURL() + "?lazyCreate#lazyCreate"));
                    lazyCreateLink.setTargetName("_blank");
                    addComponent(lazyCreateLink);

                    Link lazyInitLink = new Link("Open eagerInit UI",
                            new ExternalResource(VaadinSession.getCurrent()
                                    .getURL() + "?eagerInit#eagerInit"));
                    lazyInitLink.setTargetName("_blank");
                    addComponent(lazyInitLink);
                }
            };

            return uI;
        }
    }

    public static Label getRequestInfo(String name, WrappedRequest request) {
        String info = name;
        info += "<br />pathInfo: " + request.getRequestPathInfo();
        info += "<br />parameters: " + request.getParameterMap().keySet();
        info += "<br />uri fragment: "
                + request.getBrowserDetails().getUriFragment();
        return new Label(info, ContentMode.XHTML);
    }

    @Override
    protected String getTestDescription() {
        return "BrowserDetails should be available in Application.getUI if UIRequiresMoreInformation has been thrown and in UI.init if the UI has the @UIInitRequiresBrowserDetals annotation";
    }

    @Override
    protected Integer getTicketNumber() {
        return Integer.valueOf(7883); // + #7882 + #7884
    }

}