for (UIProvider p : uiProviders) {
// Check for existing LegacyWindow
if (p instanceof LegacyApplicationUIProvider) {
LegacyApplicationUIProvider legacyProvider = (LegacyApplicationUIProvider) p;
UI existingUi = legacyProvider
.getExistingUI(classSelectionEvent);
if (existingUi != null) {
reinitUI(existingUi, request);
return existingUi;
}
}
uiClass = p.getUIClass(classSelectionEvent);
if (uiClass != null) {
provider = p;
break;
}
}
if (provider == null || uiClass == null) {
return null;
}
// Check for an existing UI based on embed id
String embedId = getEmbedId(request);
UI retainedUI = session.getUIByEmbedId(embedId);
if (retainedUI != null) {
if (vaadinService.preserveUIOnRefresh(provider, new UICreateEvent(
request, uiClass))) {
if (uiClass.isInstance(retainedUI)) {
reinitUI(retainedUI, request);
return retainedUI;
} else {
getLogger().info(
"Not using the preserved UI " + embedId
+ " because it is of type "
+ retainedUI.getClass() + " but " + uiClass
+ " is expected for the request.");
}
}
/*
* Previous UI without preserve on refresh will be closed when the
* new UI gets added to the session.
*/
}
// No existing UI found - go on by creating and initializing one
Integer uiId = Integer.valueOf(session.getNextUIid());
// Explicit Class.cast to detect if the UIProvider does something
// unexpected
UICreateEvent event = new UICreateEvent(request, uiClass, uiId);
UI ui = uiClass.cast(provider.createInstance(event));
// Initialize some fields for a newly created UI
if (ui.getSession() != session) {
// Session already set for LegacyWindow
ui.setSession(session);
}
PushMode pushMode = provider.getPushMode(event);
if (pushMode == null) {
pushMode = session.getService().getDeploymentConfiguration()
.getPushMode();
}
ui.getPushConfiguration().setPushMode(pushMode);
Transport transport = provider.getPushTransport(event);
if (transport != null) {
ui.getPushConfiguration().setTransport(transport);
}
// Set thread local here so it is available in init
UI.setCurrent(ui);
ui.doInit(request, uiId.intValue(), embedId);
session.addUI(ui);
// Warn if the window can't be preserved
if (embedId == null