Search in sources :

Example 16 with VertexRef

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

the class NodeMapsApplication method init.

@Override
protected void init(final VaadinRequest vaadinRequest) {
    m_request = vaadinRequest;
    LOG.debug("initializing");
    final VaadinApplicationContextImpl context = new VaadinApplicationContextImpl();
    final UI currentUI = UI.getCurrent();
    context.setSessionId(currentUI.getSession().getSession().getId());
    context.setUiId(currentUI.getUIId());
    context.setUsername(vaadinRequest.getRemoteUser());
    Assert.notNull(m_alarmTable);
    Assert.notNull(m_nodeTable);
    final String searchString = vaadinRequest.getParameter("search");
    final Integer maxClusterRadius = Integer.getInteger("gwt.maxClusterRadius", 350);
    LOG.info("Starting search string: {}, max cluster radius: {}", searchString, maxClusterRadius);
    m_alarmTable.setVaadinApplicationContext(context);
    final EventProxy eventProxy = new EventProxy() {

        @Override
        public <T> void fireEvent(final T eventObject) {
            LOG.debug("got event: {}", eventObject);
            if (eventObject instanceof VerticesUpdateEvent) {
                final VerticesUpdateEvent event = (VerticesUpdateEvent) eventObject;
                final List<Integer> nodeIds = new ArrayList<Integer>();
                for (final VertexRef ref : event.getVertexRefs()) {
                    if ("nodes".equals(ref.getNamespace()) && ref.getId() != null) {
                        nodeIds.add(Integer.valueOf(ref.getId()));
                    }
                }
                m_nodeMapComponent.setSelectedNodes(nodeIds);
                return;
            }
            LOG.warn("Unsure how to deal with event: {}", eventObject);
        }

        @Override
        public <T> void addPossibleEventConsumer(final T possibleEventConsumer) {
            LOG.debug("(ignoring) add consumer: {}", possibleEventConsumer);
        /* throw new UnsupportedOperationException("Not yet implemented!"); */
        }
    };
    m_alarmTable.setEventProxy(eventProxy);
    m_nodeTable.setEventProxy(eventProxy);
    createMapPanel(searchString, maxClusterRadius);
    createRootLayout();
    addRefresher();
    // Notify the user if no tileserver url or options are set
    if (!configuration.isValid()) {
        new InvalidConfigurationWindow(configuration).open();
    }
}
Also used : VerticesUpdateEvent(org.opennms.features.topology.api.VerticesUpdateManager.VerticesUpdateEvent) VaadinApplicationContextImpl(org.opennms.osgi.VaadinApplicationContextImpl) UI(com.vaadin.ui.UI) ArrayList(java.util.ArrayList) VertexRef(org.opennms.features.topology.api.topo.VertexRef) EventProxy(org.opennms.osgi.EventProxy)

Example 17 with VertexRef

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

the class FRLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
    Collection<Vertex> vertices = graph.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    FRLayout<VertexRef, EdgeRef> layout = new FRLayout<VertexRef, EdgeRef>(jungGraph);
    // Initialize the vertex positions to the last known positions from the layout
    Dimension size = selectLayoutSize(graph);
    layout.setInitializer(initializer(graphLayout, (int) size.getWidth() / 2, (int) size.getHeight() / 2));
    // Resize the graph to accommodate the number of vertices
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    // Store the new positions in the layout
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - (size.getWidth() / 2), (int) layout.getY(v) - (size.getHeight() / 2)));
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Dimension(java.awt.Dimension) Point(org.opennms.features.topology.api.Point) SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Layout(org.opennms.features.topology.api.Layout) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 18 with VertexRef

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

the class CircleLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, Edge> jungGraph = new SparseGraph<VertexRef, Edge>();
    Collection<? extends Vertex> vertices = graph.getDisplayVertices();
    for (VertexRef v : vertices) {
        jungGraph.addVertex(v);
    }
    for (Edge e : graph.getDisplayEdges()) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    CircleLayout<VertexRef, Edge> layout = new CircleLayout<VertexRef, Edge>(jungGraph);
    layout.setInitializer(initializer(graphLayout));
    layout.setSize(selectLayoutSize(graph));
    for (VertexRef v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
    }
}
Also used : SparseGraph(edu.uci.ics.jung.graph.SparseGraph) CircleLayout(edu.uci.ics.jung.algorithms.layout.CircleLayout) CircleLayout(edu.uci.ics.jung.algorithms.layout.CircleLayout) Layout(org.opennms.features.topology.api.Layout) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 19 with VertexRef

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

the class RealUltimateLayoutAlgorithm method doFRLayout.

private static void doFRLayout(final Layout graphLayout, SparseGraph<VertexRef, EdgeRef> jungGraph, Dimension size, final int xOffset, final int yOffset) {
    FRLayout<VertexRef, EdgeRef> layout = new FRLayout<VertexRef, EdgeRef>(jungGraph);
    layout.setInitializer(initializer(graphLayout, xOffset, yOffset));
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    for (VertexRef v : jungGraph.getVertices()) {
        graphLayout.setLocation(v, new Point(layout.getX(v) + xOffset, layout.getY(v) + yOffset));
    }
}
Also used : FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 20 with VertexRef

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

the class KKLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, Edge> jungGraph = new SparseGraph<VertexRef, Edge>();
    Collection<? extends Vertex> vertices = graph.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<? extends Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    KKLayout<VertexRef, Edge> layout = new KKLayout<VertexRef, Edge>(jungGraph);
    layout.setInitializer(initializer(graphLayout));
    layout.setSize(selectLayoutSize(graph));
    while (!layout.done()) {
        layout.step();
    }
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
    }
}
Also used : SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Vertex(org.opennms.features.topology.api.topo.Vertex) KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) Layout(org.opennms.features.topology.api.Layout) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Aggregations

VertexRef (org.opennms.features.topology.api.topo.VertexRef)94 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)30 Vertex (org.opennms.features.topology.api.topo.Vertex)29 Point (org.opennms.features.topology.api.Point)23 Edge (org.opennms.features.topology.api.topo.Edge)22 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)18 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)17 List (java.util.List)13 Criteria (org.opennms.features.topology.api.topo.Criteria)13 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)12 Collectors (java.util.stream.Collectors)12 Layout (org.opennms.features.topology.api.Layout)12 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 GraphContainer (org.opennms.features.topology.api.GraphContainer)10 Collection (java.util.Collection)9 Map (java.util.Map)9 Set (java.util.Set)8 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)8