blob: 942e5ed1ef701fea30467a009fd91d555f02169d (
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
|
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;
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;
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);
}
}
|