use of org.opennms.features.topology.app.internal.support.LayoutManager in project opennms by OpenNMS.
the class ManualLayoutAlgorithm method updateLayout.
@Override
public void updateLayout(Graph graph) {
final LayoutEntity layoutEntity = layoutManager != null ? layoutManager.loadLayout(graph) : null;
if (layoutEntity != null) {
// if we have a persisted layout, we apply it ...
final Layout layout = graph.getLayout();
final Collection<Vertex> vertices = graph.getDisplayVertices();
for (Vertex vertex : vertices) {
PointEntity pointEntity = layoutEntity.getPosition(vertex.getNamespace(), vertex.getId());
layout.setLocation(vertex, new Point(pointEntity.getX(), pointEntity.getY()));
}
} else {
// otherwise we apply the manual layout ...
final Collection<Vertex> vertices = graph.getDisplayVertices();
final Layout layout = graph.getLayout();
final long notLayedOutCount = vertices.stream().filter(v -> {
Point location = layout.getLocation(v);
return location.getX() == 0 && location.getY() == 0;
}).count();
final long noVertexLocationCount = vertices.stream().filter(v -> {
boolean hasNoX = v.getX() == null || v.getX().intValue() == 0;
boolean hasNoY = v.getY() == null || v.getY().intValue() == 0;
return hasNoX && hasNoY;
}).count();
// manually apply the Grid Layout
if (notLayedOutCount == vertices.size() && noVertexLocationCount == vertices.size()) {
new GridLayoutAlgorithm().updateLayout(graph);
} else if (noVertexLocationCount != vertices.size()) {
// If we have at least one vertex with coordinates != (0,0), we apply them to the layout
for (Vertex vertex : vertices) {
layout.setLocation(vertex, new Point(vertex.getX(), vertex.getY()));
}
} else {
// This is only done when the user explicitly saves the layout
for (Vertex vertex : vertices) {
Point p = layout.getLocation(vertex);
layout.setLocation(vertex, p);
}
}
}
}
Aggregations