use of org.jgraph.graph.GraphLayoutCache in project fql by CategoricalData.
the class Sketch method addEdge.
/**
* Adds a collection (set, list, etc.) of edges to the sketch.
*
* @param inEdges
* Collection of SketchEdges to add
*/
public String addEdge(final Collection<SketchEdge> inEdges) {
// Push loading state
_stateManager.pushState(new LoadingState<>(this));
final GraphLayoutCache glc = getGraphLayoutCache();
model.beginUpdate();
for (final SketchEdge edge : inEdges) {
if (_edges.containsKey(edge.getName())) {
edge.setName(edge.getName());
}
// Add our entity to the graph
glc.insert(edge);
_edges.put(edge.getName(), edge);
edge.getSourceEntity().addDepend(edge.getTargetEntity());
}
String warning = "";
String prevCycle = strongConnected;
KosarajuSCC s = new KosarajuSCC(this);
strongConnected = s.getSCC();
// about this cycle previously
if (setHasCycle(!strongConnected.isEmpty()) && !prevCycle.equals(strongConnected)) {
warning += this.getName() + " contains a strongly connected component" + "\n " + strongConnected + "\n";
}
// if there is a mismatched path pair in the sketch
String temp = pPaths;
pPaths = this.multPathWarning();
if (!pPaths.isEmpty() && !temp.equals(pPaths)) {
warning += pPaths;
}
if (!warning.isEmpty() && useWarnings()) {
JOptionPane.showMessageDialog(this, warning, "Warning", JOptionPane.ERROR_MESSAGE);
} else if (!useWarnings()) {
return warning;
}
model.postEdit(new AbstractUndoableEdit() {
/**
*/
private static final long serialVersionUID = -6523342649950083978L;
@Override
public void undo() {
super.undo();
for (final SketchEdge edge : inEdges) {
_edges.remove(edge.getName());
}
}
@Override
public void redo() {
super.redo();
for (final SketchEdge edge : inEdges) {
_edges.put(edge.getName(), edge);
edge.getSourceEntity().addDepend(edge.getTargetEntity());
}
}
});
model.endUpdate();
// Pop state
_stateManager.popState();
refresh();
_theOverview.refresh();
return null;
}
Aggregations