Search in sources :

Example 16 with GraphContainer

use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.

the class RemoveFocusVerticesOperation method enabled.

@Override
public boolean enabled(List<VertexRef> targets, OperationContext operationContext) {
    if (targets == null || targets.isEmpty()) {
        return false;
    }
    final GraphContainer graphContainer = operationContext.getGraphContainer();
    final WrappedVertexHopCriteria wrappedVertexHopCriteria = VertexHopGraphProvider.getWrappedVertexHopCriteria(graphContainer);
    if (wrappedVertexHopCriteria.isEmpty()) {
        return false;
    }
    for (VertexRef target : targets) {
        // If any of the vertices are currently in the criteria, return true
        if (wrappedVertexHopCriteria.contains(target)) {
            return true;
        }
    }
    return false;
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) WrappedVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.WrappedVertexHopCriteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 17 with GraphContainer

use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.

the class RemoveFocusVerticesOperation method execute.

@Override
public void execute(List<VertexRef> targets, final OperationContext operationContext) {
    if (targets == null || targets.isEmpty()) {
        return;
    }
    final GraphContainer graphContainer = operationContext.getGraphContainer();
    final Set<VertexHopCriteria> criteriaForGraphContainer = Criteria.getCriteriaForGraphContainer(graphContainer, VertexHopCriteria.class);
    for (VertexHopCriteria eachCriteria : criteriaForGraphContainer) {
        for (VertexRef eachTarget : targets) {
            if (eachCriteria.getVertices().contains(eachTarget)) {
                graphContainer.removeCriteria(eachCriteria);
            }
        }
    }
    graphContainer.redoLayout();
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) WrappedVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.WrappedVertexHopCriteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 18 with GraphContainer

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(vertexHopCriteria -> graphContainer.removeCriteria(vertexHopCriteria));
    new AddFocusVerticesOperation().execute(targets, operationContext);
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer)

Example 19 with GraphContainer

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(v -> v.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);
    }
}
Also used : Objects(java.util.Objects) GraphContainer(org.opennms.features.topology.api.GraphContainer) Callbacks(org.opennms.features.topology.api.Callbacks) List(java.util.List) Lists(com.google.common.collect.Lists) Collection(java.util.Collection) Criteria(org.opennms.features.topology.api.topo.Criteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 20 with GraphContainer

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(v -> v.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();
}
Also used : AddressInfo(org.opennms.features.geolocation.api.AddressInfo) GraphContainer(org.opennms.features.topology.api.GraphContainer) GeolocationConfiguration(org.opennms.features.geolocation.api.GeolocationConfiguration) Collection(java.util.Collection) InfoPanelItem(org.opennms.features.topology.api.info.item.InfoPanelItem) Vertex(org.opennms.features.topology.api.topo.Vertex) Set(java.util.Set) LocationConfiguration(org.opennms.features.topology.app.internal.ui.geographical.LocationConfiguration) Marker(org.opennms.features.topology.app.internal.ui.geographical.Marker) LocationComponent(org.opennms.features.topology.app.internal.ui.geographical.LocationComponent) Collectors(java.util.stream.Collectors) Sizeable(com.vaadin.server.Sizeable) GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) List(java.util.List) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) DefaultInfoPanelItem(org.opennms.features.topology.api.info.item.DefaultInfoPanelItem) StatusCalculationStrategy(org.opennms.features.geolocation.api.StatusCalculationStrategy) InfoPanelItemProvider(org.opennms.features.topology.api.info.InfoPanelItemProvider) Collections(java.util.Collections) GeolocationService(org.opennms.features.geolocation.api.GeolocationService) Vertex(org.opennms.features.topology.api.topo.Vertex) ArrayList(java.util.ArrayList) Marker(org.opennms.features.topology.app.internal.ui.geographical.Marker) LocationComponent(org.opennms.features.topology.app.internal.ui.geographical.LocationComponent) DefaultInfoPanelItem(org.opennms.features.topology.api.info.item.DefaultInfoPanelItem) LocationConfiguration(org.opennms.features.topology.app.internal.ui.geographical.LocationConfiguration) GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo)

Aggregations

GraphContainer (org.opennms.features.topology.api.GraphContainer)20 VertexRef (org.opennms.features.topology.api.topo.VertexRef)11 List (java.util.List)7 Collectors (java.util.stream.Collectors)6 Collection (java.util.Collection)5 Collections (java.util.Collections)4 Objects (java.util.Objects)4 Vertex (org.opennms.features.topology.api.topo.Vertex)4 Strings (com.google.common.base.Strings)3 UI (com.vaadin.ui.UI)3 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 OperationContext (org.opennms.features.topology.api.OperationContext)3 DefaultInfoPanelItem (org.opennms.features.topology.api.info.item.DefaultInfoPanelItem)3 InfoPanelItem (org.opennms.features.topology.api.info.item.InfoPanelItem)3 WrappedVertexHopCriteria (org.opennms.features.topology.api.support.VertexHopGraphProvider.WrappedVertexHopCriteria)3 GraphProvider (org.opennms.features.topology.api.topo.GraphProvider)3 Lists (com.google.common.collect.Lists)2 Component (com.vaadin.ui.Component)2 Label (com.vaadin.ui.Label)2