Search in sources :

Example 26 with DefaultVertexRef

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

the class VertexHopGraphProviderTest method testCollapseEdges.

@Test
public void testCollapseEdges() {
    CollapsibleCriteria collapseMe = new CollapsibleCriteria() {

        @Override
        public void setCollapsed(boolean collapsed) {
        }

        @Override
        public boolean isCollapsed() {
            return true;
        }

        @Override
        public Set<VertexRef> getVertices() {
            Set<VertexRef> retval = new HashSet<VertexRef>();
            retval.add(new DefaultVertexRef("nodes", "g2"));
            return retval;
        }

        @Override
        public String getNamespace() {
            return "nodes";
        }

        @Override
        public String getLabel() {
            return "Test Criteria";
        }

        @Override
        public String getId() {
            return "Test Criteria";
        }

        @Override
        public Vertex getCollapsedRepresentation() {
            return new AbstractVertex("category", "c");
        }
    };
    Set<Edge> edges = VertexHopGraphProvider.collapseEdges(new HashSet<Edge>(m_provider.getEdges()), new CollapsibleCriteria[] { collapseMe });
    for (Edge edge : edges) {
        assertEquals("nodes", edge.getNamespace());
        /*
			Here's the original list of edges

			.edge("e1", "g0", "g1").eLabel("edge1").eStyleName("edge")
			.edge("e2", "g0", "g2").eLabel("edge2").eStyleName("edge")
			.edge("e3", "g1", "v1").eLabel("edge3").eStyleName("edge")
			.edge("e4", "g1", "v2").eLabel("edge4").eStyleName("edge")
			.edge("e5", "g2", "v3").eLabel("edge5").eStyleName("edge")
			.edge("e6", "g2", "v4").eLabel("edge6").eStyleName("edge")
			*/
        if (edge.getId().equals("e1")) {
            assertEquals("nodes", edge.getSource().getVertex().getNamespace());
            assertEquals("g0", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("g1", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("collapsedTarget-e2")) {
            assertEquals("nodes", edge.getSource().getVertex().getNamespace());
            assertEquals("g0", edge.getSource().getVertex().getId());
            assertEquals("category", edge.getTarget().getVertex().getNamespace());
            assertEquals("c", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("e3")) {
            assertEquals("nodes", edge.getSource().getVertex().getNamespace());
            assertEquals("g1", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("v1", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("e4")) {
            assertEquals("nodes", edge.getSource().getVertex().getNamespace());
            assertEquals("g1", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("v2", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("collapsedSource-e5")) {
            assertEquals("category", edge.getSource().getVertex().getNamespace());
            assertEquals("c", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("v3", edge.getTarget().getVertex().getId());
        } else if (edge.getId().equals("collapsedSource-e6")) {
            assertEquals("category", edge.getSource().getVertex().getNamespace());
            assertEquals("c", edge.getSource().getVertex().getId());
            assertEquals("nodes", edge.getTarget().getVertex().getNamespace());
            assertEquals("v4", edge.getTarget().getVertex().getId());
        } else {
            fail("Unexpected edge found: " + edge.toString());
        }
    }
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with DefaultVertexRef

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

the class NodeSelectionLinkGenerator method generateCell.

@Override
public Object generateCell(final Table source, final Object itemId, Object columnId) {
    final Property<Integer> nodeIdProperty = source.getContainerProperty(itemId, m_nodeIdProperty);
    Object cellValue = m_generator.generateCell(source, itemId, columnId);
    if (cellValue == null) {
        return null;
    } else {
        if (nodeIdProperty.getValue() == null) {
            return cellValue;
        } else {
            Button button = new Button(cellValue.toString());
            button.setStyleName(BaseTheme.BUTTON_LINK);
            button.setDescription(nodeIdProperty.getValue().toString());
            button.addClickListener(new ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    Integer nodeId = nodeIdProperty.getValue();
                    String nodeLabel = (String) source.getContainerProperty(itemId, m_nodeLabelProperty).getValue();
                    VertexRef vertexRef = new DefaultVertexRef("nodes", String.valueOf(nodeId), nodeLabel);
                    fireVertexUpdatedEvent(vertexRef);
                }
            });
            return button;
        }
    }
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) Button(com.vaadin.ui.Button) ClickEvent(com.vaadin.ui.Button.ClickEvent) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) ClickListener(com.vaadin.ui.Button.ClickListener)

Aggregations

DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)27 VertexRef (org.opennms.features.topology.api.topo.VertexRef)19 Test (org.junit.Test)10 Point (org.opennms.features.topology.api.Point)6 HashMap (java.util.HashMap)4 TreeSet (java.util.TreeSet)4 AbstractEdge (org.opennms.features.topology.api.topo.AbstractEdge)4 RefComparator (org.opennms.features.topology.api.topo.RefComparator)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 SimpleGraphBuilder (org.opennms.features.topology.api.support.SimpleGraphBuilder)3 VertexHopGraphProvider (org.opennms.features.topology.api.support.VertexHopGraphProvider)3 GraphProvider (org.opennms.features.topology.api.topo.GraphProvider)3 Vertex (org.opennms.features.topology.api.topo.Vertex)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2