Search in sources :

Example 36 with VertexRef

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

the class DefaultSelectionContext method deselectVertexRefs.

@Override
public boolean deselectVertexRefs(Collection<? extends VertexRef> vertexRefs) {
    Set<VertexRef> oldSet = new HashSet<>();
    oldSet.addAll(getSelectedVertexRefs());
    for (VertexRef vertexRef : vertexRefs) {
        setVertexRefSelected(vertexRef, false);
    }
    if (oldSet.equals(getSelectedVertexRefs())) {
        return false;
    } else {
        return true;
    }
}
Also used : VertexRef(org.opennms.features.topology.api.topo.VertexRef) HashSet(java.util.HashSet)

Example 37 with VertexRef

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

the class DefaultSelectionContext method selectVertexRefs.

@Override
public boolean selectVertexRefs(Collection<? extends VertexRef> vertexRefs) {
    Set<VertexRef> oldSet = new HashSet<>();
    oldSet.addAll(getSelectedVertexRefs());
    for (VertexRef vertexRef : vertexRefs) {
        setVertexRefSelected(vertexRef, true);
    }
    if (oldSet.equals(getSelectedVertexRefs())) {
        return false;
    } else {
        return true;
    }
}
Also used : VertexRef(org.opennms.features.topology.api.topo.VertexRef) HashSet(java.util.HashSet)

Example 38 with VertexRef

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

the class SavedHistory method getFragment.

public String getFragment() {
    final StringBuilder retval = new StringBuilder().append("(").append(m_szl).append("),").append(m_boundBox.fragment()).append(",").append(m_boundBox.getCenter());
    // Add a CRC of all of the key-value pairs in m_settings to make the fragment unique
    CRC32 settingsCrc = new CRC32();
    for (Map.Entry<String, String> entry : m_settings.entrySet()) {
        settingsCrc.update(entry.getKey().getBytes(StandardCharsets.UTF_8));
        settingsCrc.update(entry.getValue().getBytes(StandardCharsets.UTF_8));
    }
    retval.append(String.format(",(%X)", settingsCrc.getValue()));
    CRC32 locationsCrc = new CRC32();
    for (Map.Entry<VertexRef, Point> entry : m_locations.entrySet()) {
        locationsCrc.update(entry.getKey().getId().getBytes(StandardCharsets.UTF_8));
        // TODO cast to int for now
        locationsCrc.update((int) entry.getValue().getX());
        locationsCrc.update((int) entry.getValue().getY());
    }
    retval.append(String.format(",(%X)", locationsCrc.getValue()));
    CRC32 selectionsCrc = new CRC32();
    for (VertexRef entry : m_selectedVertices) {
        selectionsCrc.update(entry.getNamespace().getBytes(StandardCharsets.UTF_8));
        selectionsCrc.update(entry.getId().getBytes(StandardCharsets.UTF_8));
    }
    retval.append(String.format(",(%X)", selectionsCrc.getValue()));
    CRC32 focusCrc = new CRC32();
    for (VertexRef entry : m_focusVertices) {
        focusCrc.update(entry.getNamespace().getBytes(StandardCharsets.UTF_8));
        focusCrc.update(entry.getId().getBytes(StandardCharsets.UTF_8));
    }
    retval.append(String.format(",(%X)", focusCrc.getValue()));
    CRC32 historyCrc = new CRC32();
    for (SearchResult query : m_searchQueries) {
        historyCrc.update(query.toString().getBytes(StandardCharsets.UTF_8));
    }
    retval.append(String.format(",(%X)", historyCrc.getValue()));
    return retval.toString();
}
Also used : CRC32(java.util.zip.CRC32) SearchResult(org.opennms.features.topology.api.topo.SearchResult) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) HashMap(java.util.HashMap) Map(java.util.Map)

Example 39 with VertexRef

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

the class SavedHistory method toString.

@Override
public String toString() {
    final StringBuilder retval = new StringBuilder().append(this.getClass().getSimpleName()).append(": ").append(getFragment()).append(": ");
    boolean first = true;
    for (Map.Entry<String, String> entry : m_settings.entrySet()) {
        if (first) {
            first = false;
        } else {
            retval.append(",");
        }
        retval.append(entry.getKey()).append("->").append(entry.getValue());
    }
    if (m_selectedVertices.size() > 0) {
        first = true;
        retval.append(",selectedVertices->{");
        for (VertexRef entry : m_selectedVertices) {
            if (first) {
                first = false;
            } else {
                retval.append(",");
            }
            retval.append("[").append(entry.getNamespace()).append(":").append(entry.getId()).append("]");
        }
        retval.append("}");
    }
    if (m_focusVertices.size() > 0) {
        first = true;
        retval.append(",focusVertices->{");
        for (VertexRef entry : m_focusVertices) {
            if (first) {
                first = false;
            } else {
                retval.append(",");
            }
            retval.append("[").append(entry.getNamespace()).append(":").append(entry.getId()).append("]");
        }
        retval.append("}");
    }
    return retval.toString();
}
Also used : VertexRef(org.opennms.features.topology.api.topo.VertexRef) HashMap(java.util.HashMap) Map(java.util.Map)

Example 40 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef 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");
        }
    }
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Aggregations

VertexRef (org.opennms.features.topology.api.topo.VertexRef)105 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)33 Vertex (org.opennms.features.topology.api.topo.Vertex)31 Point (org.opennms.features.topology.api.Point)23 Criteria (org.opennms.features.topology.api.topo.Criteria)22 Edge (org.opennms.features.topology.api.topo.Edge)22 Test (org.junit.Test)21 List (java.util.List)20 ArrayList (java.util.ArrayList)19 Collectors (java.util.stream.Collectors)18 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)18 Map (java.util.Map)17 Status (org.opennms.features.topology.api.topo.Status)15 Collection (java.util.Collection)13 HashSet (java.util.HashSet)13 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)12 HashMap (java.util.HashMap)12 Layout (org.opennms.features.topology.api.Layout)12 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)12 Lists (com.google.common.collect.Lists)11