Search in sources :

Example 1 with SessionDestroyListener

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;
}
Also used : SessionInitEvent(com.vaadin.server.SessionInitEvent) ServiceException(com.vaadin.server.ServiceException) VaadinSession(com.vaadin.server.VaadinSession) SessionListenerRepository(org.opennms.vaadin.extender.SessionListenerRepository) SessionInitListener(com.vaadin.server.SessionInitListener) SessionDestroyListener(com.vaadin.server.SessionDestroyListener) BootstrapPageResponse(com.vaadin.server.BootstrapPageResponse) BootstrapListener(com.vaadin.server.BootstrapListener) VaadinServletService(com.vaadin.server.VaadinServletService) BootstrapFragmentResponse(com.vaadin.server.BootstrapFragmentResponse) SessionDestroyEvent(com.vaadin.server.SessionDestroyEvent)

Example 2 with SessionDestroyListener

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);
}
Also used : HasExtraComponents(org.opennms.features.topology.api.HasExtraComponents) VerticalSplitPanel(com.vaadin.ui.VerticalSplitPanel) Alignment(com.vaadin.ui.Alignment) SelectionAwareTable(org.opennms.features.topology.api.browsers.SelectionAwareTable) SearchBox(org.opennms.features.topology.app.internal.ui.SearchBox) VertexHopGraphProvider.getWrappedVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.getWrappedVertexHopCriteria) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) Map(java.util.Map) ServiceReference(org.osgi.framework.ServiceReference) RedoLayoutOperation(org.opennms.features.topology.app.internal.operations.RedoLayoutOperation) VaadinResponse(com.vaadin.server.VaadinResponse) Property(com.vaadin.data.Property) HistoryManager(org.opennms.features.topology.api.HistoryManager) Set(java.util.Set) AbsoluteLayout(com.vaadin.ui.AbsoluteLayout) IconRepositoryManager(org.opennms.features.topology.app.internal.support.IconRepositoryManager) Criteria(org.opennms.features.topology.api.topo.Criteria) VaadinApplicationContextImpl(org.opennms.osgi.VaadinApplicationContextImpl) VertexRef(org.opennms.features.topology.api.topo.VertexRef) MenuUpdateListener(org.opennms.features.topology.app.internal.menu.MenuUpdateListener) DefaultErrorHandler(com.vaadin.server.DefaultErrorHandler) UriFragmentChangedListener(com.vaadin.server.Page.UriFragmentChangedListener) Title(com.vaadin.annotations.Title) VerticalLayout(com.vaadin.ui.VerticalLayout) TreeSet(java.util.TreeSet) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) VertexUpdateListener(org.opennms.features.topology.app.internal.TopologyComponent.VertexUpdateListener) DefaultTopologyProviderInfo(org.opennms.features.topology.api.topo.DefaultTopologyProviderInfo) Strings(com.google.common.base.Strings) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) VaadinApplicationContextCreator(org.opennms.osgi.VaadinApplicationContextCreator) TopologyMenuBar(org.opennms.features.topology.app.internal.menu.TopologyMenuBar) OnmsHeaderProvider(org.opennms.web.api.OnmsHeaderProvider) InfoPanelItem(org.opennms.features.topology.api.info.item.InfoPanelItem) IOException(java.io.IOException) PreserveOnRefresh(com.vaadin.annotations.PreserveOnRefresh) Refresher(com.github.wolfie.refresher.Refresher) LayoutHintComponent(org.opennms.features.topology.app.internal.ui.LayoutHintComponent) HorizontalLayout(com.vaadin.ui.HorizontalLayout) TopologyProviderInfo(org.opennms.features.topology.api.topo.TopologyProviderInfo) InfoPanelItemProvider(org.opennms.features.topology.api.info.InfoPanelItemProvider) OperationManager(org.opennms.features.topology.app.internal.menu.OperationManager) ContentType(org.opennms.features.topology.api.browsers.ContentType) EventConsumer(org.opennms.osgi.EventConsumer) GraphContainer(org.opennms.features.topology.api.GraphContainer) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) ConfirmationDialog(org.opennms.netmgt.vaadin.core.ConfirmationDialog) RequestHandler(com.vaadin.server.RequestHandler) ToolbarPanel(org.opennms.features.topology.app.internal.ui.ToolbarPanel) LoggerFactory(org.slf4j.LoggerFactory) UI(com.vaadin.ui.UI) CheckedOperation(org.opennms.features.topology.api.CheckedOperation) Window(com.vaadin.ui.Window) VaadinRequest(com.vaadin.server.VaadinRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultInfoPanelItem(org.opennms.features.topology.api.info.item.DefaultInfoPanelItem) SelectionListener(org.opennms.features.topology.api.SelectionListener) VaadinApplicationContext(org.opennms.osgi.VaadinApplicationContext) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Collection(java.util.Collection) OnmsServiceManager(org.opennms.osgi.OnmsServiceManager) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) Objects(java.util.Objects) List(java.util.List) Theme(com.vaadin.annotations.Theme) HudDisplay(org.opennms.features.topology.app.internal.ui.HudDisplay) TabSheet(com.vaadin.ui.TabSheet) TransactionOperations(org.springframework.transaction.support.TransactionOperations) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) TopologyContextMenu(org.opennms.features.topology.app.internal.menu.TopologyContextMenu) Optional(java.util.Optional) WidgetUpdateListener(org.opennms.features.topology.api.WidgetUpdateListener) IViewContribution(org.opennms.features.topology.api.IViewContribution) SessionDestroyListener(com.vaadin.server.SessionDestroyListener) VerticesUpdateManager(org.opennms.features.topology.api.VerticesUpdateManager) WidgetManager(org.opennms.features.topology.api.WidgetManager) LayoutManager(org.opennms.features.topology.app.internal.support.LayoutManager) TopologyLinkBuilder(org.opennms.features.topology.link.TopologyLinkBuilder) SelectionContext(org.opennms.features.topology.api.SelectionContext) Vertex(org.opennms.features.topology.api.topo.Vertex) MapViewManager(org.opennms.features.topology.api.MapViewManager) BreadcrumbComponent(org.opennms.features.topology.app.internal.ui.breadcrumbs.BreadcrumbComponent) CustomLayout(com.vaadin.ui.CustomLayout) SelectionNotifier(org.opennms.features.topology.api.SelectionNotifier) OnmsServiceManagerLocator(org.opennms.osgi.locator.OnmsServiceManagerLocator) Notification(com.vaadin.ui.Notification) Label(com.vaadin.ui.Label) WidgetContext(org.opennms.features.topology.api.WidgetContext) Logger(org.slf4j.Logger) SelectedTabChangeEvent(com.vaadin.ui.TabSheet.SelectedTabChangeEvent) DisplayLocation(org.opennms.features.topology.api.OperationContext.DisplayLocation) MapViewManagerListener(org.opennms.features.topology.api.MapViewManagerListener) InfoPanel(org.opennms.features.topology.app.internal.ui.InfoPanel) VaadinServletRequest(com.vaadin.server.VaadinServletRequest) SelectedTabChangeListener(com.vaadin.ui.TabSheet.SelectedTabChangeListener) UriFragmentChangedEvent(com.vaadin.server.Page.UriFragmentChangedEvent) VaadinSession(com.vaadin.server.VaadinSession) OperationContext(org.opennms.features.topology.api.OperationContext) ToolbarPanelController(org.opennms.features.topology.app.internal.ui.ToolbarPanelController) SelectionManager(org.opennms.features.topology.api.SelectionManager) NoSuchProviderException(org.opennms.features.topology.app.internal.service.NoSuchProviderException) NoContentAvailableWindow(org.opennms.features.topology.app.internal.ui.NoContentAvailableWindow) Collections(java.util.Collections) InputStream(java.io.InputStream) Component(com.vaadin.ui.Component) OnmsServiceManager(org.opennms.osgi.OnmsServiceManager) VaadinApplicationContextCreator(org.opennms.osgi.VaadinApplicationContextCreator) VaadinServletRequest(com.vaadin.server.VaadinServletRequest) VertexHopGraphProvider.getWrappedVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.getWrappedVertexHopCriteria) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) IOException(java.io.IOException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) NoSuchProviderException(org.opennms.features.topology.app.internal.service.NoSuchProviderException) VaadinApplicationContextImpl(org.opennms.osgi.VaadinApplicationContextImpl) CheckedOperation(org.opennms.features.topology.api.CheckedOperation)

Aggregations

SessionDestroyListener (com.vaadin.server.SessionDestroyListener)2 VaadinSession (com.vaadin.server.VaadinSession)2 Refresher (com.github.wolfie.refresher.Refresher)1 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 PreserveOnRefresh (com.vaadin.annotations.PreserveOnRefresh)1 Theme (com.vaadin.annotations.Theme)1 Title (com.vaadin.annotations.Title)1 Property (com.vaadin.data.Property)1 BootstrapFragmentResponse (com.vaadin.server.BootstrapFragmentResponse)1 BootstrapListener (com.vaadin.server.BootstrapListener)1 BootstrapPageResponse (com.vaadin.server.BootstrapPageResponse)1 DefaultErrorHandler (com.vaadin.server.DefaultErrorHandler)1 UriFragmentChangedEvent (com.vaadin.server.Page.UriFragmentChangedEvent)1 UriFragmentChangedListener (com.vaadin.server.Page.UriFragmentChangedListener)1 RequestHandler (com.vaadin.server.RequestHandler)1 ServiceException (com.vaadin.server.ServiceException)1 SessionDestroyEvent (com.vaadin.server.SessionDestroyEvent)1 SessionInitEvent (com.vaadin.server.SessionInitEvent)1 SessionInitListener (com.vaadin.server.SessionInitListener)1