if (!(startVertex != null && endVertex != null)) {
Util.Assert(false, "Could not find vertice");
}
AbstractSparseEdge jungEdge = myEdgeMap.get(uiEdge);
boolean createJungEdge = false;
if (jungEdge != null) {
// find if an existing edge has changed
boolean edgeChanged = false;
if (uiEdge instanceof ElasticEdge) {
Double length = (Double) jungEdge.getUserDatum(ELASTIC_LENGTH_KEY);
if (length != ((ElasticEdge) uiEdge).getLength()) {
edgeChanged = true;
}
} else if (jungEdge.getEndpoints().getFirst() != startVertex
|| jungEdge.getEndpoints().getSecond() != endVertex) {
edgeChanged = true;
}
if (edgeChanged) {
myEdgeMap.remove(uiEdge);
myGraph.removeEdge(jungEdge);
graphChanged = true;
// try to add the new changed one
createJungEdge = true;
}
} else {
createJungEdge = true;
}
if (createJungEdge) {
// avoid recursive edges
if (startVertex != endVertex) {
if (uiEdge.isDirected()) {
jungEdge = new DirectedSparseEdge(startVertex, endVertex);
} else {
jungEdge = new UndirectedSparseEdge(startVertex, endVertex);
}
jungEdge.addUserDatum(ELASTIC_LENGTH_KEY, new Double(elasticEdge
.getLength()), UserData.SHARED);
myEdgeMap.put(uiEdge, jungEdge);
myGraph.addEdge(jungEdge);
graphChanged = true;
}
}
} else {
Util.Assert(false, "Could not find Elastic Nodes of edge");
}
}
}
/*
* Remove edges
*/
List<PXEdge> edgesToRemove = new ArrayList<PXEdge>();
for (PXEdge uiEdge : myEdgeMap.keySet()) {
if (!containsEdge(uiEdge)) {
edgesToRemove.add(uiEdge);
}
}
for (PXEdge uiEdge : edgesToRemove) {
AbstractSparseEdge jungEdge = myEdgeMap.get(uiEdge);
graphChanged = true;
// have to check if the edge is still there because it might have
// been removed when the vertice was removed
if (myGraph.getEdges().contains(jungEdge)) {
myGraph.removeEdge(jungEdge);