*/
private CompoundDirectedGraph mapDiagramToGraph() {
Map<AnchorContainer, Node> shapeToNode = new HashMap<AnchorContainer, Node>();
Diagram d = getDiagram();
CompoundDirectedGraph dg = new CompoundDirectedGraph();
EdgeList edgeList = new EdgeList();
NodeList nodeList = new NodeList();
EList<Shape> children = d.getChildren();
for (Shape shape : children) {
Node node = new Node();
GraphicsAlgorithm ga = shape.getGraphicsAlgorithm();
node.x = ga.getX();
node.y = ga.getY();
node.width = ga.getWidth();
node.height = ga.getHeight();
node.data = shape;
shapeToNode.put(shape, node);
nodeList.add(node);
}
EList<Connection> connections = d.getConnections();
for (Connection connection : connections) {
//Be wary about broken connections
AnchorContainer source = null;
if (connection.getStart() != null) {
source = connection.getStart().getParent();
}
AnchorContainer target = null;
if (connection.getEnd() != null) {
target = connection.getEnd().getParent();
}
if (target == null || source == null) {
break;
}
Node srcNode = shapeToNode.get(source);
if (srcNode == null) {
srcNode = shapeToNode.get(source.eContainer());
}
Node tgtNode = shapeToNode.get(target);
if (tgtNode == null) {
tgtNode = shapeToNode.get(target.eContainer());
}
Edge edge = new Edge(srcNode, tgtNode);
edge.data = connection;
edgeList.add(edge);
}
dg.nodes = nodeList;
dg.edges = edgeList;
return dg;
}