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

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import com.vaadin.server.UIClassSelectionEvent;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinSession;
import com.vaadin.tests.components.AbstractTestUIProvider;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

public class UIsInMultipleTabs extends AbstractTestUIProvider {
    // No cleanup -> will leak, but shouldn't matter for tests
    private static ConcurrentHashMap<VaadinSession, AtomicInteger> numberOfUIsOpened = new ConcurrentHashMap<VaadinSession, AtomicInteger>();

    public static class TabUI extends UI {
        @Override
        protected void init(VaadinRequest request) {
            VaadinSession application = VaadinSession.getCurrent();
            AtomicInteger count = numberOfUIsOpened.get(application);
            if (count == null) {
                numberOfUIsOpened.putIfAbsent(application, new AtomicInteger());
                // Get our added instance or another instance that was added by
                // another thread between previous get and putIfAbsent
                count = numberOfUIsOpened.get(application);
            }
            int currentCount = count.incrementAndGet();
            String message = "This is UI number " + currentCount;

            VerticalLayout layout = new VerticalLayout();
            layout.setMargin(true);
            setContent(layout);

            layout.addComponent(new Label(message));
        }
    }

    @Override
    public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
        return TabUI.class;
    }

    @Override
    protected String getTestDescription() {
        return "Opening the same application again (e.g. in a new tab) should create a new UI.";
    }

    @Override
    protected Integer getTicketNumber() {
        return Integer.valueOf(7894);
    }
}