use of org.opennms.features.topology.api.GraphContainer 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.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class TopologyContextMenu method addNavigateToItems.
// adds menu items for the "navigate to" operation
private static void addNavigateToItems(MenuBuilder menuBuilder, List<VertexRef> targets, OperationContext operationContext) {
if (!targets.isEmpty()) {
menuBuilder.createPath("Navigate To");
final GraphContainer graphContainer = operationContext.getGraphContainer();
// Find the vertices in other graphs that this vertex links to
final Collection<VertexRef> oppositeVertices = graphContainer.getTopologyServiceClient().getOppositeVertices(targets.get(0));
// Find all namespaces
final Set<String> targetNamespaces = oppositeVertices.stream().map(VertexRef::getNamespace).collect(Collectors.toSet());
// Find provider for namespaces and add menu entry
for (String eachTargetNamespace : targetNamespaces) {
// Find the graph provider for the target namespace
final GraphProvider targetGraphProvider = graphContainer.getTopologyServiceClient().getGraphProviders().stream().filter(g -> g.getNamespace().equals(eachTargetNamespace)).findFirst().orElse(null);
if (targetGraphProvider == null) {
LOG.warn("No graph provider found for namespace '{}'.", eachTargetNamespace);
continue;
}
NavigationMenuItem item = new NavigationMenuItem(targetGraphProvider, targets.get(0));
menuBuilder.addMenuItem(item, "Navigate To");
}
}
}
use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class LocationInfoPanelItemProvider method getContributions.
@Override
public Collection<? extends InfoPanelItem> getContributions(GraphContainer container) {
final List<Vertex> vertices = new ArrayList<>(container.getGraph().getDisplayVertices());
final Set<Integer> nodeIds = vertices.stream().filter(v -> v.getNodeID() != null).map(Vertex::getNodeID).collect(Collectors.toSet());
if (nodeIds.isEmpty()) {
return Collections.emptyList();
}
final List<GeolocationInfo> locations = geolocationService.getLocations(new GeolocationQueryBuilder().withNodeIds(nodeIds).withStatusCalculationStrategy(StatusCalculationStrategy.None).build());
final List<Marker> markers = locations.stream().filter(locationInfo -> locationInfo.getCoordinates() != null).map(locationInfo -> {
final Vertex vertex = vertices.stream().filter(v -> v.getNodeID() != null && locationInfo.getNodeInfo().getNodeId() == v.getNodeID()).findFirst().get();
return new Marker(locationInfo.getCoordinates(), createTooltip(vertex, locationInfo.getAddressInfo()), container.getSelectionManager().isVertexRefSelected(vertex));
}).collect(Collectors.toList());
if (!markers.isEmpty()) {
final LocationConfiguration config = new LocationConfiguration().withTileLayer(geolocationConfiguration.getTileServerUrl()).withMarker(markers).withInitialZoom(10).withLayerOptions(geolocationConfiguration.getOptions());
final LocationComponent locationComponent = new LocationComponent(config, "mapId-" + getClass().getSimpleName().toLowerCase());
locationComponent.setWidth(300, Sizeable.Unit.PIXELS);
locationComponent.setHeight(300, Sizeable.Unit.PIXELS);
return Collections.singleton(new DefaultInfoPanelItem().withTitle(String.format("Geolocation (%d/%d)", markers.size(), vertices.size())).withOrder(1).withComponent(locationComponent));
}
return Collections.emptyList();
}
use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class SetFocusVertexOperation method execute.
@Override
public void execute(List<VertexRef> targets, OperationContext operationContext) {
if (targets == null || targets.isEmpty()) {
return;
}
final GraphContainer graphContainer = operationContext.getGraphContainer();
graphContainer.findCriteria(VertexHopGraphProvider.VertexHopCriteria.class).forEach(graphContainer::removeCriteria);
new AddFocusVerticesOperation().execute(targets, operationContext);
}
use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class BreadcrumbCriteria method handleClick.
public void handleClick(Breadcrumb breadcrumb, GraphContainer graphContainer) {
final GraphProvider targetGraphProvider = graphContainer.getTopologyServiceClient().getGraphProviderBy(breadcrumb.getTargetNamespace());
if (isLeaf(breadcrumb)) {
if (breadcrumb.getSourceVertices().isEmpty()) {
final List<VertexRef> defaultFocus = targetGraphProvider.getDefaults().getCriteria().stream().filter(c -> c instanceof VertexHopGraphProvider.VertexHopCriteria).map(c -> ((VertexHopGraphProvider.VertexHopCriteria) c).getVertices()).flatMap(Set::stream).collect(Collectors.toList());
handleClick(graphContainer, targetGraphProvider, defaultFocus, breadcrumb);
} else {
List<VertexRef> oppositeVertices = breadcrumb.getSourceVertices().stream().flatMap(sourceVertex -> getOppositeVertices(graphContainer, breadcrumb.getTargetNamespace(), sourceVertex).stream()).collect(Collectors.toList());
handleClick(graphContainer, targetGraphProvider, oppositeVertices, breadcrumb);
}
} else {
Breadcrumb next = getNext(breadcrumb);
handleClick(graphContainer, targetGraphProvider, next.getSourceVertices(), breadcrumb);
}
}
Aggregations