Search in sources :

Example 1 with Breadcrumb

use of org.opennms.features.topology.api.support.breadcrumbs.Breadcrumb in project opennms by OpenNMS.

the class BreadcrumbComponent method graphChanged.

@Override
public void graphChanged(GraphContainer graphContainer) {
    final BreadcrumbCriteria criteria = Criteria.getSingleCriteriaForGraphContainer(graphContainer, BreadcrumbCriteria.class, true);
    final HorizontalLayout breadcrumbLayout = (HorizontalLayout) getCompositionRoot();
    breadcrumbLayout.removeAllComponents();
    // Verify that breadcrumbs are enabled
    if (graphContainer.getTopologyServiceClient().getBreadcrumbStrategy() == BreadcrumbStrategy.SHORTEST_PATH_TO_ROOT) {
        final Collection<Vertex> displayVertices = graphContainer.getGraph().getDisplayVertices();
        if (!displayVertices.isEmpty()) {
            final PathTree pathTree = BreadcrumbPathCalculator.findPath(graphContainer.getTopologyServiceClient(), displayVertices.stream().map(v -> (VertexRef) v).collect(Collectors.toSet()));
            final List<Breadcrumb> breadcrumbs = pathTree.toBreadcrumbs();
            criteria.setBreadcrumbs(breadcrumbs);
        }
        for (Breadcrumb eachBreadcrumb : criteria.getBreadcrumbs()) {
            if (breadcrumbLayout.getComponentCount() >= 1) {
                breadcrumbLayout.addComponent(new Label(" > "));
            }
            breadcrumbLayout.addComponent(createButton(graphContainer, eachBreadcrumb));
        }
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) Label(com.vaadin.ui.Label) Breadcrumb(org.opennms.features.topology.api.support.breadcrumbs.Breadcrumb) BreadcrumbCriteria(org.opennms.features.topology.api.support.breadcrumbs.BreadcrumbCriteria) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 2 with Breadcrumb

use of org.opennms.features.topology.api.support.breadcrumbs.Breadcrumb in project opennms by OpenNMS.

the class PathTree method toBreadcrumbs.

public List<Breadcrumb> toBreadcrumbs() {
    final List<Breadcrumb> breadcrumbList = Lists.newArrayList();
    // Build from bottom to top (including root)
    List<Node> work = getLeafs();
    while (!work.isEmpty() && !work.get(0).isRoot()) {
        // All working nodes must be on the same layer (resulting in the same namespace)
        String targetNamespace = work.get(0).getVertexRef().getNamespace();
        Set<Node> parentNodes = work.stream().map(eachLeaf -> eachLeaf.getParent()).filter(node -> node != null).collect(Collectors.toSet());
        breadcrumbList.add(0, new Breadcrumb(targetNamespace, parentNodes.stream().map(p -> p.getVertexRef()).filter(v -> v != null).collect(Collectors.toList())));
        work = Lists.newArrayList(parentNodes);
    }
    return breadcrumbList;
}
Also used : List(java.util.List) Lists(com.google.common.collect.Lists) Set(java.util.Set) Breadcrumb(org.opennms.features.topology.api.support.breadcrumbs.Breadcrumb) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Collectors(java.util.stream.Collectors) Breadcrumb(org.opennms.features.topology.api.support.breadcrumbs.Breadcrumb)

Aggregations

Breadcrumb (org.opennms.features.topology.api.support.breadcrumbs.Breadcrumb)2 Lists (com.google.common.collect.Lists)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Label (com.vaadin.ui.Label)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 BreadcrumbCriteria (org.opennms.features.topology.api.support.breadcrumbs.BreadcrumbCriteria)1 Vertex (org.opennms.features.topology.api.topo.Vertex)1 VertexRef (org.opennms.features.topology.api.topo.VertexRef)1