public void addVertexPosition(VertexPositionEntity position) { Objects.requireNonNull(position); getVertexPositions().add(position); }
public LayoutEntity loadLayout(Graph graph) { LayoutEntity layoutEntity = findBy(graph); if (layoutEntity != null) { layoutEntity.setLastUsed(new Date()); layoutDao.saveOrUpdate(layoutEntity); } return layoutEntity; }
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()); }) .collect(Collectors.toList()); layoutEntity.getVertexPositions().clear(); for (VertexPositionEntity eachVertexPosition : vertexPositionEntities) { layoutEntity.addVertexPosition(eachVertexPosition);
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()));
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()); }) .collect(Collectors.toList()); layoutEntity.getVertexPositions().clear(); for (VertexPositionEntity eachVertexPosition : vertexPositionEntities) { layoutEntity.addVertexPosition(eachVertexPosition);
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()));
public void addVertexPosition(VertexPositionEntity position) { Objects.requireNonNull(position); getVertexPositions().add(position); }
public LayoutEntity loadLayout(Graph graph) { LayoutEntity layoutEntity = findBy(graph); if (layoutEntity != null) { layoutEntity.setLastUsed(new Date()); layoutDao.saveOrUpdate(layoutEntity); } return layoutEntity; }
public boolean isPersistedLayoutEqualToCurrentLayout(Graph graph) { LayoutEntity layoutEntity = loadLayout(graph); if (layoutEntity != null) { // If we have a layout persisted, we verify if it is equal. final Map<VertexRef, Point> persistedLocations = layoutEntity.getVertexPositions() .stream() .collect(Collectors.toMap((Function<VertexPositionEntity, VertexRef>) vertexPositionEntity -> { VertexRefEntity vertexRefEntity = vertexPositionEntity.getVertexRef(); return new DefaultVertexRef(vertexRefEntity.getNamespace(), vertexRefEntity.getId()); }, vertexPositionEntity -> { PointEntity position = vertexPositionEntity.getPosition(); return new Point(position.getX(), position.getY()); })); // The locations may contain elements currently not visible, we filter them final Map<VertexRef, Point> manualLocations = new HashMap<>(); graph.getLayout().getLocations().forEach((key, value) -> { if (persistedLocations.containsKey(key)) { // layoutEntity stores int coordinates, but manualLocations are stored as double. // Convert to int to make it comparable. manualLocations.put(key, new Point((int) value.getX(), (int) value.getY())); } }); final boolean layoutIsEqual = manualLocations.equals(persistedLocations); return layoutIsEqual; } return false; // We don't have anything persisted, so they are not equal } }
public boolean isPersistedLayoutEqualToCurrentLayout(Graph graph) { LayoutEntity layoutEntity = loadLayout(graph); if (layoutEntity != null) { // If we have a layout persisted, we verify if it is equal. final Map<VertexRef, Point> persistedLocations = layoutEntity.getVertexPositions() .stream() .collect(Collectors.toMap((Function<VertexPositionEntity, VertexRef>) vertexPositionEntity -> { VertexRefEntity vertexRefEntity = vertexPositionEntity.getVertexRef(); return new DefaultVertexRef(vertexRefEntity.getNamespace(), vertexRefEntity.getId()); }, vertexPositionEntity -> { PointEntity position = vertexPositionEntity.getPosition(); return new Point(position.getX(), position.getY()); })); // The locations may contain elements currently not visible, we filter them final Map<VertexRef, Point> manualLocations = new HashMap<>(); graph.getLayout().getLocations().forEach((key, value) -> { if (persistedLocations.containsKey(key)) { // layoutEntity stores int coordinates, but manualLocations are stored as double. // Convert to int to make it comparable. manualLocations.put(key, new Point((int) value.getX(), (int) value.getY())); } }); final boolean layoutIsEqual = manualLocations.equals(persistedLocations); return layoutIsEqual; } return false; // We don't have anything persisted, so they are not equal } }