/**
   * This will reload all positions of all vertices in the layout's graph. It will not reload if the
   * used layout type does not match the saved one. (the position of x/y in a circle is not valid
   * for x/y in a tree).
   *
   * @param layout
   * @param type
   * @param properties
   * @param category
   */
  private static void reloadAllVerticesPositions(
      final Layout<DatabaseObject, Relation> layout,
      final LayoutType type,
      final ConnectionProperties properties,
      final AttributeMapSet category) {
    final Collection<DatabaseObject> vertices = layout.getGraph().getVertices();
    if (vertices.isEmpty()) {
      return;
    }

    for (final DatabaseObject object : vertices) {
      // If special positions contained in properties' attributes map, use them.
      if (properties != null) {
        final ConnectionAttributesMap attributes = properties.getAttributesMap(category, object);
        final int newPosX = attributes.getPositionX();
        final int newPosY = attributes.getPositionY();
        final String oldLayout = attributes.getLayout();

        // Is this the same layout?
        if (oldLayout.isEmpty() || oldLayout.equalsIgnoreCase(type.toString())) {
          // Are this valid number values?
          if ((newPosX > 0) && (newPosY > 0)) {
            layout.setLocation(object, new Point2D.Double(newPosX, newPosY));
          }
        }
      }
    }
  }