use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class OSGiVerticesUpdateManagerTest method createGraph.
private GraphContainer createGraph(int... vertIds) {
final List<Vertex> vertexRefsWithIds = createVerticsWithIds(vertIds);
final Graph graphMock = EasyMock.createNiceMock(Graph.class);
final GraphContainer graphContainerMock = EasyMock.createNiceMock(GraphContainer.class);
EasyMock.expect(graphMock.getDisplayVertices()).andReturn(vertexRefsWithIds).anyTimes();
EasyMock.expect(graphContainerMock.getGraph()).andReturn(graphMock).anyTimes();
EasyMock.replay(graphMock, graphContainerMock);
return graphContainerMock;
}
use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class HierarchyLayoutAlgorithmTest method buildLayout.
private void buildLayout() {
// Mock ALL the things
final GraphContainer mockGraphContainer = Mockito.mock(GraphContainer.class);
layout = new DefaultLayout();
final TestGraph testGraph = new TestGraph(layout, vertices, edges);
Mockito.when(mockGraphContainer.getGraph()).thenReturn(testGraph);
// Update layouts and ensure no exception is thrown
new HierarchyLayoutAlgorithm().updateLayout(testGraph);
}
use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class OperationManagerTest method getMenuBar.
private static TopologyMenuBar getMenuBar(OperationManager operationManager) {
// Mock all the things
GraphContainer graphContainerMock = Mockito.mock(GraphContainer.class);
SelectionManager selectionManagerMock = Mockito.mock(SelectionManager.class);
Mockito.when(graphContainerMock.getSelectionManager()).thenReturn(selectionManagerMock);
Mockito.when(selectionManagerMock.getSelectedVertexRefs()).thenReturn(new ArrayList<>());
// Create menu bar
TopologyMenuBar topologyMenuBar = new TopologyMenuBar();
topologyMenuBar.updateMenu(graphContainerMock, null, operationManager);
return topologyMenuBar;
}
use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class LayoutManager method persistLayout.
public void persistLayout(GraphContainer graphContainer) {
final List<VertexRef> vertexRefs = toVertexRef(graphContainer.getGraph().getDisplayVertices());
final String id = calculateHash(vertexRefs);
LayoutEntity layoutEntity = layoutDao.get(id);
if (layoutEntity == null) {
layoutEntity = new LayoutEntity();
layoutEntity.setId(id);
layoutEntity.setCreated(new Date());
layoutEntity.setCreator(graphContainer.getApplicationContext().getUsername());
}
layoutEntity.setUpdated(new Date());
layoutEntity.setUpdator(graphContainer.getApplicationContext().getUsername());
final Layout layout = graphContainer.getGraph().getLayout();
final List<VertexPositionEntity> vertexPositionEntities = vertexRefs.stream().map(vertexRef -> {
final Point p = layout.getLocation(vertexRef);
PointEntity pointEntity = new PointEntity();
pointEntity.setX((int) p.getX());
pointEntity.setY((int) p.getY());
final VertexPositionEntity vertexEntity = new VertexPositionEntity();
vertexEntity.setVertexRef(toVertexRefEntity(vertexRef));
vertexEntity.setPosition(pointEntity);
return vertexEntity;
}).collect(Collectors.toList());
layoutEntity.getVertexPositions().clear();
for (VertexPositionEntity eachVertexPosition : vertexPositionEntities) {
layoutEntity.addVertexPosition(eachVertexPosition);
}
layoutDao.saveOrUpdate(layoutEntity);
}
use of org.opennms.features.topology.api.GraphContainer in project opennms by OpenNMS.
the class RemoveFocusOtherVerticesOperation 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;
}
// Are the selected vertices in focus?
for (VertexRef target : targets) {
if (!wrappedVertexHopCriteria.contains(target)) {
return false;
}
}
// Are there any other vertices in focus?
for (VertexRef vertex : wrappedVertexHopCriteria.getVertices()) {
if (!targets.contains(vertex)) {
return true;
}
}
return false;
}
Aggregations