Search in sources :

Example 11 with GraphLayoutCache

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;
}
Also used : AbstractUndoableEdit(javax.swing.undo.AbstractUndoableEdit) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) SketchEdge(easik.sketch.edge.SketchEdge) KosarajuSCC(easik.model.util.graph.KosarajuSCC)

Aggregations

GraphLayoutCache (org.jgraph.graph.GraphLayoutCache)11 Rectangle2D (java.awt.geom.Rectangle2D)4 GuideEdge (easik.model.edge.GuideEdge)3 AbstractUndoableEdit (javax.swing.undo.AbstractUndoableEdit)3 AttributeMap (org.jgraph.graph.AttributeMap)3 SketchEdge (easik.sketch.edge.SketchEdge)2 EntityNode (easik.sketch.vertex.EntityNode)2 QueryNode (easik.view.vertex.QueryNode)2 JGraph (org.jgraph.JGraph)2 DefaultCellViewFactory (org.jgraph.graph.DefaultCellViewFactory)2 DefaultGraphCell (org.jgraph.graph.DefaultGraphCell)2 DefaultGraphModel (org.jgraph.graph.DefaultGraphModel)2 GraphModel (org.jgraph.graph.GraphModel)2 DocumentInfo (easik.DocumentInfo)1 KosarajuSCC (easik.model.util.graph.KosarajuSCC)1 OverviewGraphModel (easik.overview.util.graph.OverviewGraphModel)1 SketchNode (easik.overview.vertex.SketchNode)1 ViewNode (easik.overview.vertex.ViewNode)1 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)1 SketchFrame (easik.ui.SketchFrame)1