use of com.vaadin.server.SessionDestroyListener in project opennms by OpenNMS.
the class VaadinOSGiServlet method createServletService.
@Override
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException {
final VaadinServletService service = super.createServletService(deploymentConfiguration);
service.addSessionInitListener(new SessionInitListener() {
@Override
public void sessionInit(SessionInitEvent event) throws ServiceException {
final VaadinSession session = event.getSession();
m_sessions.add(session);
if (session.getUIProviders().isEmpty() || !session.getUIProviders().contains(m_provider)) {
session.addUIProvider(m_provider);
}
}
});
service.addSessionDestroyListener(new SessionDestroyListener() {
@Override
public void sessionDestroy(SessionDestroyEvent event) {
final VaadinSession session = event.getSession();
m_sessions.remove(session);
if (session.getUIProviders().contains(m_provider)) {
session.removeUIProvider(m_provider);
}
}
});
// Additional listeners
SessionListenerRepository sessionListenerRepository = SessionListenerRepository.getRepository(m_context);
if (sessionListenerRepository != null) {
service.addSessionInitListener(sessionListenerRepository);
service.addSessionDestroyListener(sessionListenerRepository);
}
// The Default location of the favicon is "theme://favicon.ico".
// However the theme may not provide a favicon. To avoid each theme to host the favicon.ico file, we just use
// the one defined in /opennms
service.addSessionInitListener(new SessionInitListener() {
@Override
public void sessionInit(SessionInitEvent event) throws ServiceException {
event.getSession().addBootstrapListener(new BootstrapListener() {
@Override
public void modifyBootstrapPage(BootstrapPageResponse response) {
response.getDocument().head().getElementsByAttributeValue("rel", "shortcut icon").attr("href", "/opennms/favicon.ico");
response.getDocument().head().getElementsByAttributeValue("rel", "icon").attr("href", "/opennms/favicon.ico");
}
@Override
public void modifyBootstrapFragment(BootstrapFragmentResponse response) {
}
});
}
});
return service;
}
use of com.vaadin.server.SessionDestroyListener in project opennms by OpenNMS.
the class TopologyUI method init.
@Override
protected void init(final VaadinRequest request) {
// Register a cleanup
request.getService().addSessionDestroyListener((SessionDestroyListener) event -> m_widgetManager.removeUpdateListener(TopologyUI.this));
try {
m_headerHtml = getHeader(((VaadinServletRequest) request).getHttpServletRequest());
} catch (final Exception e) {
LOG.error("failed to get header HTML for request " + request.getPathInfo(), e.getCause());
}
// create VaadinApplicationContext
m_applicationContext = m_serviceManager.createApplicationContext(new VaadinApplicationContextCreator() {
@Override
public VaadinApplicationContext create(OnmsServiceManager manager) {
VaadinApplicationContextImpl context = new VaadinApplicationContextImpl();
context.setSessionId(request.getWrappedSession().getId());
context.setUiId(getUIId());
context.setUsername(request.getRemoteUser());
return context;
}
});
m_verticesUpdateManager = new OsgiVerticesUpdateManager(m_serviceManager, m_applicationContext);
m_serviceManager.getEventRegistry().addPossibleEventConsumer(this, m_applicationContext);
// Set the algorithm last so that the criteria and SZLs are
// in place before we run the layout algorithm.
m_graphContainer.setApplicationContext(m_applicationContext);
createLayouts();
// Set up an error handler for UI-level exceptions
setupErrorHandler();
// Add an auto refresh handler to the GraphContainer
setupAutoRefresher();
loadUserSettings();
// If no Topology Provider was selected (due to loadUserSettings(), fallback to default
if (Strings.isNullOrEmpty(m_graphContainer.getMetaTopologyId())) {
CheckedOperation defaultTopologySelectorOperation = getDefaultTopologySelectorOperation(m_bundlecontext);
// no default found, abort
Objects.requireNonNull(defaultTopologySelectorOperation, "No default GraphProvider found.");
defaultTopologySelectorOperation.execute(Lists.newArrayList(), new DefaultOperationContext(TopologyUI.this, m_graphContainer, DisplayLocation.MENUBAR));
}
// Add a request handler that parses incoming focusNode and szl query parameters
TopologyUIRequestHandler handler = new TopologyUIRequestHandler();
getSession().addRequestHandler(handler);
// deal with those in init case
handler.handleRequestParameter(request);
// Add the default criteria if we do not have already a criteria set
if (getWrappedVertexHopCriteria(m_graphContainer).isEmpty() && noAdditionalFocusCriteria()) {
List<Criteria> defaultCriteriaList = m_graphContainer.getTopologyServiceClient().getDefaults().getCriteria();
if (defaultCriteriaList != null) {
// set default
defaultCriteriaList.forEach(m_graphContainer::addCriteria);
}
}
// We set the listeners at the end, to not fire them all the time when initializing the UI
setupListeners();
// We force a reload to trigger a fireGraphChanged()
m_graphContainer.setDirty(true);
m_graphContainer.redoLayout();
// Trigger a selectionChanged
m_selectionManager.selectionChanged(m_selectionManager);
}
Aggregations