Search in sources :

Example 51 with SketchEdge

use of easik.sketch.edge.SketchEdge in project fql by CategoricalData.

the class NewViewEdgeAction method actionPerformed.

/**
 * The action for creating a new edge. Make sure the selection is alright,
 * and then create the edge.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    View _ourView = _theFrame.getMModel();
    Sketch _ourSketch = _ourView.getSketch();
    boolean foundEdge = false, forward = false, reverse = false;
    // cancel operation
    if (_ourSketch.isSynced()) {
        if (JOptionPane.showConfirmDialog(_theFrame, "Warning: this sketch is currently synced with a db; continue and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
            return;
        }
    }
    Object[] currentSelection = _ourView.getSelectionCells();
    QueryNode currNode = (QueryNode) currentSelection[0];
    String queryString = currNode.getQuery();
    String entityNodeName = null;
    // find corresponding entity node name
    String[] tokens = queryString.split("\\s+");
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i].equalsIgnoreCase("from")) {
            entityNodeName = tokens[i + 1];
        }
    }
    EntityNode[] node = new EntityNode[2];
    // set corresponding node in order to use
    for (EntityNode sketchNode : _ourSketch.getEntities()) {
        if (sketchNode.getName().equalsIgnoreCase(entityNodeName)) {
            node[0] = sketchNode;
        }
    }
    if (currentSelection.length > 1) {
        currNode = (QueryNode) currentSelection[1];
        queryString = currNode.getQuery();
        entityNodeName = null;
        // find corresponding entity node name
        tokens = queryString.split("\\s+");
        for (int i = 0; i < tokens.length; i++) {
            if (tokens[i].equalsIgnoreCase("from")) {
                entityNodeName = tokens[i + 1];
            }
        }
        // set corresponding node in order to use
        for (EntityNode sketchNode : _ourSketch.getEntities()) {
            if (sketchNode.getName().equalsIgnoreCase(entityNodeName)) {
                node[1] = sketchNode;
            }
        }
        for (SketchEdge edge : _ourSketch.getEdges().values()) {
            View_Edge vEdge;
            forward = (edge.getTargetEntity().equals(node[0]) && edge.getSourceEntity().equals(node[1]));
            reverse = (edge.getTargetEntity().equals(node[1]) && edge.getSourceEntity().equals(node[0]));
            if (forward || reverse) {
                // System.out.println("This edge exists");
                foundEdge = true;
                // need to move down??
                if (edge.isPartial()) {
                    // ***NEED TO FIGURE OUT CASCADING
                    vEdge = new PartialViewEdge((QueryNode) currentSelection[0], (QueryNode) currentSelection[0], edge.getName());
                } else if (edge.isInjective()) {
                    // **NEED TO FIGURE OUT CASCADING
                    if (forward) {
                        vEdge = new InjectiveViewEdge((QueryNode) currentSelection[1], (QueryNode) currentSelection[0], edge.getName(), Cascade.RESTRICT);
                    } else {
                        vEdge = new InjectiveViewEdge((QueryNode) currentSelection[0], (QueryNode) currentSelection[1], edge.getName(), Cascade.RESTRICT);
                    }
                // System.out.println(vEdge.getName());
                } else {
                    if (forward) {
                        vEdge = new NormalViewEdge((QueryNode) currentSelection[1], (QueryNode) currentSelection[0], edge.getName());
                    } else {
                        vEdge = new NormalViewEdge((QueryNode) currentSelection[0], (QueryNode) currentSelection[1], edge.getName());
                    }
                }
                _ourView.addEdge(vEdge);
            }
        }
        if (!foundEdge) {
        // System.out.println("This edge does not exist");
        }
    } else // end checking if 2 nodes
    // edge that goes into itself
    {
    /*
			 * for(SketchEdge edge: node[0].getOutgoingEdges()) {
			 * 
			 * }
			 */
    }
}
Also used : NormalViewEdge(easik.view.edge.NormalViewEdge) View(easik.view.View) View_Edge(easik.view.edge.View_Edge) InjectiveViewEdge(easik.view.edge.InjectiveViewEdge) PartialViewEdge(easik.view.edge.PartialViewEdge) EntityNode(easik.sketch.vertex.EntityNode) SketchEdge(easik.sketch.edge.SketchEdge) QueryNode(easik.view.vertex.QueryNode) Sketch(easik.sketch.Sketch)

Aggregations

SketchEdge (easik.sketch.edge.SketchEdge)51 EntityNode (easik.sketch.vertex.EntityNode)45 Sketch (easik.sketch.Sketch)31 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)31 SketchFrame (easik.ui.SketchFrame)30 LinkedList (java.util.LinkedList)22 LimitConstraint (easik.model.constraint.LimitConstraint)17 ProductConstraint (easik.model.constraint.ProductConstraint)16 PullbackConstraint (easik.model.constraint.PullbackConstraint)16 SumConstraint (easik.model.constraint.SumConstraint)16 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)13 ModelConstraint (easik.model.constraint.ModelConstraint)13 ArrayList (java.util.ArrayList)11 ModelPath (easik.model.path.ModelPath)9 LinkedHashSet (java.util.LinkedHashSet)9 InjectiveEdge (easik.sketch.edge.InjectiveEdge)7 UniqueIndexable (easik.model.keys.UniqueIndexable)5 XSDAnnotation (easik.xml.xsd.nodes.XSDAnnotation)5 XSDType (easik.xml.xsd.nodes.types.XSDType)5 EasikType (easik.database.types.EasikType)4