use of org.opennms.osgi.VaadinApplicationContext in project opennms by OpenNMS.
the class OnmsServiceManagerImpl method createApplicationContext.
@Override
public VaadinApplicationContext createApplicationContext(VaadinApplicationContextCreator creator) {
VaadinApplicationContext newContext = creator.create(this);
VaadinApplicationContext oldContext = getService(VaadinApplicationContext.class, newContext);
if (oldContext != null)
return oldContext;
registerAsService(VaadinApplicationContext.class, newContext, newContext);
return newContext;
}
use of org.opennms.osgi.VaadinApplicationContext in project opennms by OpenNMS.
the class OSGiVerticesUpdateManagerTest method testVertexRefSelectedUpdate.
@Test
public void testVertexRefSelectedUpdate() {
MockEventProxy mockEventProxy = new MockEventProxy();
OnmsServiceManager serviceManager = new DummyOnmsServiceManager();
VaadinApplicationContext vaadinApplicationContext = new DummyVaadinApplicationContext(mockEventProxy);
OsgiVerticesUpdateManager updateManager = new OsgiVerticesUpdateManager(serviceManager, vaadinApplicationContext);
updateManager.selectionChanged(createContextWithVertRefIds(1, 2, 3, 4));
assertEquals(1, mockEventProxy.getFireEventCalls());
VerticesUpdateManager.VerticesUpdateEvent event = mockEventProxy.getLastFiredEvent();
assertEquals(4, event.getVertexRefs().size());
updateManager.selectionChanged(createContextWithVertRefIds(1, 2, 3, 4));
assertEquals(1, mockEventProxy.getFireEventCalls());
VerticesUpdateManager.VerticesUpdateEvent event2 = mockEventProxy.getLastFiredEvent();
assertNull(event2);
updateManager.selectionChanged(createContextWithVertRefIds(2, 3, 4, 5));
assertEquals(2, mockEventProxy.getFireEventCalls());
VerticesUpdateManager.VerticesUpdateEvent event3 = mockEventProxy.getLastFiredEvent();
assertEquals(4, event3.getVertexRefs().size());
updateManager.selectionChanged(createContextWithVertRefIds(5, 6));
assertEquals(3, mockEventProxy.getFireEventCalls());
VerticesUpdateManager.VerticesUpdateEvent event4 = mockEventProxy.getLastFiredEvent();
assertEquals(2, event4.getVertexRefs().size());
}
use of org.opennms.osgi.VaadinApplicationContext 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);
}
use of org.opennms.osgi.VaadinApplicationContext in project opennms by OpenNMS.
the class OSGiVerticesUpdateManagerTest method testGraphUpdated.
@Test
public void testGraphUpdated() {
MockEventProxy mockEventProxy = new MockEventProxy();
OnmsServiceManager serviceManager = new DummyOnmsServiceManager();
VaadinApplicationContext vaadinApplicationContext = new DummyVaadinApplicationContext(mockEventProxy);
OsgiVerticesUpdateManager updateManager = new OsgiVerticesUpdateManager(serviceManager, vaadinApplicationContext);
updateManager.graphChanged(createGraph(1, 2, 3, 4, 5, 6, 7));
assertEquals(1, mockEventProxy.getFireEventCalls());
updateManager.selectionChanged(createContextWithVertRefIds(1, 2, 3, 4));
assertEquals(2, mockEventProxy.getFireEventCalls());
updateManager.graphChanged(createGraph(1, 2, 3, 4, 5, 6, 7));
assertEquals(2, mockEventProxy.getFireEventCalls());
}
Aggregations