blob: 9a66e9ad0ac8b2e99a74e82c1215d4a98ba66839 (
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.Application;
import com.vaadin.server.WrappedRequest;
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<Application, AtomicInteger> numberOfUIsOpened = new ConcurrentHashMap<Application, AtomicInteger>();
public static class TabUI extends UI {
@Override
protected void init(WrappedRequest request) {
Application application = Application.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(Application application,
WrappedRequest request) {
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);
}
}
|