Search in sources :

Example 1 with PartialEdge

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

the class SketchFileIO method sketchToElement.

/**
 * Converts a sketch to an Element.
 *
 * @param document
 *            The Document in which our information is being placed.
 * @param sketch
 * @return All of the information needed to rebuild our sketch containted in
 *         an Element. Returns null in the event that the element could not
 *         be created.
 */
public static Element sketchToElement(Document document, Sketch sketch) {
    try {
        Element rootElement = document.createElement("easketch");
        Element header = document.createElement("header");
        // Add Header info to document
        DocumentInfo d = sketch.getDocInfo();
        Element name = document.createElement("title");
        name.appendChild(document.createTextNode(d.getName()));
        header.appendChild(name);
        for (String aut : d.getAuthors()) {
            Element author = document.createElement("author");
            author.appendChild(document.createTextNode(aut));
            header.appendChild(author);
        }
        Element desc = document.createElement("description");
        desc.appendChild(document.createTextNode(d.getDesc()));
        header.appendChild(desc);
        Element creationDate = document.createElement("creationDate");
        creationDate.appendChild(document.createTextNode(EasikConstants.XML_DATETIME.format(d.getCreationDate())));
        header.appendChild(creationDate);
        Element modDate = document.createElement("lastModificationDate");
        modDate.appendChild(document.createTextNode(EasikConstants.XML_DATETIME.format(d.getModificationDate())));
        header.appendChild(modDate);
        Map<String, String> connParams = sketch.getConnectionParams();
        for (String key : connParams.keySet()) {
            Element connParam = document.createElement("connectionParam");
            connParam.setAttribute("name", key);
            connParam.setAttribute("value", connParams.get(key));
            header.appendChild(connParam);
        }
        if (sketch.isSynced()) {
            header.appendChild(document.createElement("synchronized"));
        }
        rootElement.appendChild(header);
        Element entities = document.createElement("entities");
        // Loop through entities, add them to the document
        for (EntityNode currentEntity : sketch.getEntities()) {
            if (currentEntity == null) {
                continue;
            }
            Element thisEntity = document.createElement("entity");
            thisEntity.setAttribute("name", currentEntity.toString());
            thisEntity.setAttribute("x", currentEntity.getX() + "");
            thisEntity.setAttribute("y", currentEntity.getY() + "");
            entities.appendChild(thisEntity);
            // Loop through attributes, add them to the document
            for (EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> curAttribute : currentEntity.getEntityAttributes()) {
                Element attributeElmt = document.createElement("attribute");
                attributeElmt.setAttribute("name", curAttribute.getName());
                EasikType attType = curAttribute.getType();
                attributeElmt.setAttribute("attributeTypeClass", attType.getClass().getName());
                Map<String, String> typeAttribs = attType.attributes();
                for (String key : typeAttribs.keySet()) {
                    attributeElmt.setAttribute(key, typeAttribs.get(key));
                }
                thisEntity.appendChild(attributeElmt);
            }
        // We can't go through unique keys yet: they have to come
        // *after* edges
        }
        rootElement.appendChild(entities);
        Element edges = document.createElement("edges");
        for (SketchEdge currentEdge : sketch.getEdges().values()) {
            Element thisEdge = document.createElement("edge");
            thisEdge.setAttribute("id", currentEdge.getName());
            thisEdge.setAttribute("source", currentEdge.getSourceEntity().getName());
            thisEdge.setAttribute("target", currentEdge.getTargetEntity().getName());
            thisEdge.setAttribute("type", (currentEdge instanceof PartialEdge) ? "partial" : (currentEdge instanceof InjectiveEdge) ? "injective" : "normal");
            thisEdge.setAttribute("cascade", (currentEdge.getCascading() == SketchEdge.Cascade.SET_NULL) ? "set_null" : (currentEdge.getCascading() == SketchEdge.Cascade.CASCADE) ? "cascade" : "restrict");
            edges.appendChild(thisEdge);
        }
        rootElement.appendChild(edges);
        Element keys = document.createElement("keys");
        // Loop through unique keys for every node, add them to the document
        for (EntityNode currentEntity : sketch.getEntities()) {
            for (UniqueKey<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> curKey : currentEntity.getUniqueKeys()) {
                Element uniqueKeyElmt = document.createElement("uniqueKey");
                uniqueKeyElmt.setAttribute("name", curKey.getKeyName());
                uniqueKeyElmt.setAttribute("noderef", currentEntity.toString());
                keys.appendChild(uniqueKeyElmt);
                for (UniqueIndexable curElem : curKey.getElements()) {
                    if (curElem instanceof EntityAttribute) {
                        Element attributeElmt = document.createElement("attref");
                        attributeElmt.setAttribute("name", curElem.getName());
                        uniqueKeyElmt.appendChild(attributeElmt);
                    } else if (curElem instanceof SketchEdge) {
                        Element edgeElmt = document.createElement("edgekeyref");
                        edgeElmt.setAttribute("id", curElem.getName());
                        uniqueKeyElmt.appendChild(edgeElmt);
                    } else {
                        System.err.println("Unknown unique key item encountered: element '" + curElem.getName() + "' is neither EntityAttribute nor SketchEdge");
                    }
                }
            }
        }
        rootElement.appendChild(keys);
        Element constraints = document.createElement("constraints");
        // Now add the constraints
        for (ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> curConstraint : sketch.getConstraints().values()) {
            Element thisConstraint = document.createElement(curConstraint.getType());
            thisConstraint.setAttribute("x", curConstraint.getX() + "");
            thisConstraint.setAttribute("y", curConstraint.getY() + "");
            thisConstraint.setAttribute("isVisible", curConstraint.isVisible() ? "true" : "false");
            if (curConstraint instanceof LimitConstraint) {
                LimitConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> lc = (LimitConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) curConstraint;
                // TODO A better way? really long
                // cone - AB
                Element pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getCone().AB.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getCone().AB.getCoDomain().getName());
                for (SketchEdge edge : lc.getCone().AB.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // cone - BC
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getCone().BC.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getCone().BC.getCoDomain().getName());
                for (SketchEdge edge : lc.getCone().BC.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // cone - AC
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getCone().AC.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getCone().AC.getCoDomain().getName());
                for (SketchEdge edge : lc.getCone().AC.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // limit cone 1 - AB
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getLimitCone1().AB.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getLimitCone1().AB.getCoDomain().getName());
                for (SketchEdge edge : lc.getLimitCone1().AB.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // limit cone 1 - BC
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getLimitCone1().BC.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getLimitCone1().BC.getCoDomain().getName());
                for (SketchEdge edge : lc.getLimitCone1().BC.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // limit cone 1 - AC
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getLimitCone1().AC.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getLimitCone1().AC.getCoDomain().getName());
                for (SketchEdge edge : lc.getLimitCone1().AC.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // limit cone 2 - AB
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getLimitCone2().AB.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getLimitCone2().AB.getCoDomain().getName());
                for (SketchEdge edge : lc.getLimitCone2().AB.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // limit cone 2 - BC
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getLimitCone2().BC.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getLimitCone2().BC.getCoDomain().getName());
                for (SketchEdge edge : lc.getLimitCone2().BC.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // limit cone 2 - AC
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getLimitCone2().AC.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getLimitCone2().AC.getCoDomain().getName());
                for (SketchEdge edge : lc.getLimitCone2().AC.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // Add constraint to constraints
                constraints.appendChild(thisConstraint);
                continue;
            }
            for (ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : curConstraint.getPaths()) {
                // Add pathref to constraint
                Element pathElem = document.createElement("path");
                pathElem.setAttribute("domain", path.getDomain().getName());
                pathElem.setAttribute("codomain", path.getCoDomain().getName());
                for (SketchEdge edge : path.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
            }
            // Add constraint to constraints
            constraints.appendChild(thisConstraint);
        }
        rootElement.appendChild(constraints);
        return rootElement;
    } catch (Exception e) {
        return null;
    }
}
Also used : LimitConstraint(easik.model.constraint.LimitConstraint) EntityAttribute(easik.model.attribute.EntityAttribute) Element(org.w3c.dom.Element) PartialEdge(easik.sketch.edge.PartialEdge) EntityNode(easik.sketch.vertex.EntityNode) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) SketchFrame(easik.ui.SketchFrame) InjectiveEdge(easik.sketch.edge.InjectiveEdge) SketchEdge(easik.sketch.edge.SketchEdge) Sketch(easik.sketch.Sketch) EasikType(easik.database.types.EasikType) DocumentInfo(easik.DocumentInfo) UniqueIndexable(easik.model.keys.UniqueIndexable)

Example 2 with PartialEdge

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

the class SketchHandler method startElement.

/**
 * Overloaded method that is called any time the start of an element is
 * found
 *
 * @param namespace
 * 			@see org.xml.sax.helpers.DefaultHandler
 * @param localName
 * 			@see org.xml.sax.helpers.DefaultHandler
 * @param qName
 * 			@see org.xml.sax.helpers.DefaultHandler
 * @param atts
 * 			@see org.xml.sax.helpers.DefaultHandler
 */
@Override
public void startElement(String namespace, String localName, String qName, Attributes atts) {
    _currNode = qName;
    if (qName.equals("entity")) {
        String name = atts.getValue("name");
        int x = Integer.parseInt(atts.getValue("x"));
        int y = Integer.parseInt(atts.getValue("y"));
        if (_entityNodes.containsKey(name)) {
            System.err.println("Duplicate nodes found in XML");
            return;
        }
        _newNode = new EntityNode(name, x, y, _theFrame.getMModel());
        _entityNodes.put(name, _newNode);
        _curNodeAtts = new LinkedHashMap<>();
    } else if (qName.equals("attribute")) {
        EasikType type;
        // attributeType was created by old Easik versions, and is the SQL
        // type signature
        // (such as "VARCHAR(255)"). Easik now uses attributeTypeClass,
        // containing the
        // class name, and any number of extra attributes which
        // EasikType.newType() uses to
        // recreate the appropriate EasikType object.
        String typesig = atts.getValue("attributeType");
        if (typesig != null) {
            type = EasikType.typeFromSignature(typesig);
        } else {
            String typename = atts.getValue("attributeTypeClass");
            try {
                type = EasikType.newType(typename, attributeMap(atts, "attributeType", "attributeTypeClass", "name"));
            } catch (ClassNotFoundException e) {
                System.err.println("Invalid type found in XML: '" + typename + "' (" + e.getMessage() + ")");
                return;
            }
        }
        EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> myAtt = new EntityAttribute<>(atts.getValue("name"), type, _newNode);
        _curNodeAtts.put(atts.getValue("name"), myAtt);
        _newNode.addEntityAttribute(myAtt);
    } else if (qName.equals("uniqueKey")) {
        // New EASIK has noderef, telling us what we refer to. In old easik,
        // uniqueKey is under
        // the node itself (but as a result, cannot contain edge
        // references).
        String noderef = atts.getValue("noderef");
        if (noderef != null) {
            // Restore _newNode and _curNodeAtts, since we're going to need
            // them:
            _newNode = _entityNodes.get(noderef);
            _curNodeAtts = new LinkedHashMap<>();
            for (EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> att : _newNode.getEntityAttributes()) {
                _curNodeAtts.put(att.getName(), att);
            }
        }
        _curUniqueKeyName = atts.getValue("name");
        _curUniqueKeyElems = new LinkedList<>();
    } else if (qName.equals("attref")) {
        _curUniqueKeyElems.add(_curNodeAtts.get(atts.getValue("name")));
    } else if (qName.equals("edgekeyref")) {
        SketchEdge e = _edges.get(atts.getValue("id"));
        if (e instanceof UniqueIndexable) {
            _curUniqueKeyElems.add((UniqueIndexable) e);
        } else {
            System.err.println("Encountered an non-unique-indexable <edgekeyref> " + e);
        }
    } else if (qName.equals("edge")) {
        SketchEdge newEdge;
        String edgeType = atts.getValue("type");
        // injective is an old EASIK attribute:
        String injective = atts.getValue("injective");
        if (injective != null) {
            edgeType = atts.getValue("injective").equals("true") ? "injective" : "normal";
        }
        EntityNode source = _entityNodes.get(atts.getValue("source"));
        EntityNode target = _entityNodes.get(atts.getValue("target"));
        String id = atts.getValue("id");
        String cascadeAtt = atts.getValue("cascade");
        if (cascadeAtt == null) {
            // This is from an export before Easik had per-edge cascading
            // (in other words, before r583)
            // We use the global preferences for cascading
            String key = "sql_cascade", def = "restrict";
            if (edgeType.equals("partial")) {
                key = "sql_cascade_partial";
                def = "set_null";
            }
            cascadeAtt = Easik.getInstance().getSettings().getProperty(key, def);
        }
        SketchEdge.Cascade cascade = cascadeAtt.equals("set_null") ? SketchEdge.Cascade.SET_NULL : cascadeAtt.equals("cascade") ? SketchEdge.Cascade.CASCADE : SketchEdge.Cascade.RESTRICT;
        if (edgeType.equals("injective")) {
            newEdge = new InjectiveEdge(source, target, id, cascade);
        } else if (edgeType.equals("partial")) {
            newEdge = new PartialEdge(source, target, id, cascade);
        } else {
            newEdge = new NormalEdge(source, target, id, cascade);
        }
        _edges.put(id, newEdge);
    } else if (qName.equals("path")) {
        _curPath = new LinkedList<>();
        _curPathId = atts.getValue("id");
        _curDomain = _entityNodes.get(atts.getValue("domain"));
    } else if (qName.equals("edgeref")) {
        _curPath.add(_edges.get(atts.getValue("id")));
    } else if (// TRIANGLES
    qName.equals("sumconstraint") || qName.equals("pullbackconstraint") || qName.equals("productconstraint") || qName.equals("commutativediagram") || qName.equals("equalizerconstraint") || qName.equals("limitconstraint")) // CF2012
    {
        _curConstraintX = Integer.parseInt(atts.getValue("x"));
        _curConstraintY = Integer.parseInt(atts.getValue("y"));
        _curConstraintVisible = atts.getValue("isVisible").equals("true");
        _curConstraintPaths = new ArrayList<>();
        _allConstraintsVisible = atts.getValue("isVisible").equals("true");
    } else if (qName.equals("pathref")) {
        // This is for compatibility with old versions of Easik (pre-2.0);
        // new versions
        // put <path> elements directly inside the various constraint
        // elements.
        _curConstraintPaths.add(_allPaths.get(atts.getValue("id")));
    } else if (qName.equals("connectionParam")) {
        _connParams.put(atts.getValue("name"), atts.getValue("value"));
    } else if (qName.equals("synchronized")) {
        // The existance of this tag tells us the sketch is synchronized
        _curSketchSync = true;
    }
}
Also used : EntityAttribute(easik.model.attribute.EntityAttribute) PartialEdge(easik.sketch.edge.PartialEdge) LimitConstraint(easik.model.constraint.LimitConstraint) EqualizerConstraint(easik.model.constraint.EqualizerConstraint) ProductConstraint(easik.model.constraint.ProductConstraint) SumConstraint(easik.model.constraint.SumConstraint) PullbackConstraint(easik.model.constraint.PullbackConstraint) ModelConstraint(easik.model.constraint.ModelConstraint) EntityNode(easik.sketch.vertex.EntityNode) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) SketchFrame(easik.ui.SketchFrame) InjectiveEdge(easik.sketch.edge.InjectiveEdge) SketchEdge(easik.sketch.edge.SketchEdge) NormalEdge(easik.sketch.edge.NormalEdge) Sketch(easik.sketch.Sketch) EasikType(easik.database.types.EasikType) UniqueIndexable(easik.model.keys.UniqueIndexable)

Example 3 with PartialEdge

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

the class SketchGraphModel method getAttributes.

/**
 * Overridden method to get cell attributes; we make sure the appropriate
 * attributes are applied to the Easik objects before returning them.
 *
 * @see DefaultGraphModel.getAttributes(Object)
 *
 * @param o
 *
 * @return
 */
@Override
@SuppressWarnings("unchecked")
public AttributeMap getAttributes(Object o) {
    _mode = (_sketch.getFrame().getMode() == Mode.EDIT) ? "edit_" : "manip_";
    if (o instanceof GraphCell) {
        GraphCell cell = (GraphCell) o;
        AttributeMap attribs = cell.getAttributes();
        AttributeMap easikAttribs = null;
        if (cell instanceof SketchEdge) {
            easikAttribs = (cell instanceof InjectiveEdge) ? injectiveEdgeAttributes() : (cell instanceof PartialEdge) ? partialEdgeAttributes() : normalEdgeAttributes();
        } else if (cell instanceof TriangleEdge) {
            easikAttribs = triangleEdgeAttributes((TriangleEdge<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) cell);
        } else if (cell instanceof GuideEdge) {
            easikAttribs = ((GuideEdge<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) cell).isHighlighted() ? virtualHighlightedEdgeAttributes() : virtualEdgeAttributes();
        } else if (cell instanceof ModelConstraint) {
            easikAttribs = virtualVertexAttributes();
        } else if (cell instanceof EntityNode) {
            easikAttribs = vertexAttributes();
        }
        if (easikAttribs != null) {
            if (_sketch.isCellSelected(cell)) {
                Color selColor;
                float lineWidth;
                if (_sketch.getStateManager().peekState() instanceof GetPathState) {
                    selColor = getColor("path_selection");
                    lineWidth = getWidth("path_selection", 2);
                } else {
                    selColor = getColor("selection");
                    lineWidth = getWidth("selection", 3);
                }
                int borderWidth = getIntWidth(_mode + ((cell instanceof ModelConstraint) ? "constraint" : "entity") + "_border", 1);
                GraphConstants.setBorder(easikAttribs, BorderFactory.createLineBorder(selColor, borderWidth));
                GraphConstants.setForeground(easikAttribs, selColor);
                GraphConstants.setLineColor(easikAttribs, selColor);
                GraphConstants.setLineWidth(easikAttribs, lineWidth);
            }
            if (attribs == null) {
                cell.setAttributes(easikAttribs);
                attribs = easikAttribs;
            } else {
                attribs.applyMap(easikAttribs);
            }
            return attribs;
        }
    }
    return super.getAttributes(o);
}
Also used : ModelConstraint(easik.model.constraint.ModelConstraint) GraphCell(org.jgraph.graph.GraphCell) Color(java.awt.Color) TriangleEdge(easik.model.edge.TriangleEdge) PartialEdge(easik.sketch.edge.PartialEdge) ModelConstraint(easik.model.constraint.ModelConstraint) EntityNode(easik.sketch.vertex.EntityNode) SketchFrame(easik.ui.SketchFrame) AttributeMap(org.jgraph.graph.AttributeMap) InjectiveEdge(easik.sketch.edge.InjectiveEdge) SketchEdge(easik.sketch.edge.SketchEdge) GetPathState(easik.model.states.GetPathState) Sketch(easik.sketch.Sketch) GuideEdge(easik.model.edge.GuideEdge)

Example 4 with PartialEdge

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

the class NewSketchEdgeAction 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) {
    Sketch _ourSketch = _theFrame.getMModel();
    // 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 = _ourSketch.getSelectionCells();
    EntityNode[] node = new EntityNode[(_edgeType == Edge.SELF) ? 1 : 2];
    if (currentSelection.length == node.length) {
        for (int i = 0; i < node.length; i++) {
            node[i] = null;
            if (currentSelection[i] instanceof EntityNode) {
                node[i] = (EntityNode) currentSelection[i];
            }
        }
    }
    if ((_edgeType == Edge.SELF) && (node[0] == null)) {
        JOptionPane.showMessageDialog(_theFrame, "Operation must be performed with one entity selected", "Error", JOptionPane.ERROR_MESSAGE);
    } else if ((_edgeType != Edge.SELF) && ((node[0] == null) || (node[1] == null))) {
        JOptionPane.showMessageDialog(_theFrame, "Operation must be performed with two entities selected", "Error", JOptionPane.ERROR_MESSAGE);
    } else {
        EdgeOptions opts = new EdgeOptions(_theFrame, _edgeType, node[0], (_edgeType == Edge.SELF) ? null : node[1]);
        if (opts.isAccepted()) {
            SketchEdge edge;
            if (_edgeType == Edge.SELF) {
                edge = new PartialEdge(node[0], node[0], opts.getName(), opts.getCascadeMode());
            } else {
                // UI:
                if (opts.isReversed()) {
                    node = new EntityNode[] { node[1], node[0] };
                }
                if (_edgeType == Edge.PARTIAL) {
                    edge = new PartialEdge(node[0], node[1], opts.getName(), opts.getCascadeMode());
                } else if (_edgeType == Edge.INJECTIVE) {
                    edge = new InjectiveEdge(node[0], node[1], opts.getName(), opts.getCascadeMode());
                } else {
                    edge = new NormalEdge(node[0], node[1], opts.getName(), opts.getCascadeMode());
                }
            }
            _ourSketch.addEdge(edge);
            _ourSketch.setDirty();
            _ourSketch.setSynced(false);
        }
    }
}
Also used : InjectiveEdge(easik.sketch.edge.InjectiveEdge) SketchEdge(easik.sketch.edge.SketchEdge) NormalEdge(easik.sketch.edge.NormalEdge) Sketch(easik.sketch.Sketch) PartialEdge(easik.sketch.edge.PartialEdge) EntityNode(easik.sketch.vertex.EntityNode)

Aggregations

Sketch (easik.sketch.Sketch)4 InjectiveEdge (easik.sketch.edge.InjectiveEdge)4 PartialEdge (easik.sketch.edge.PartialEdge)4 SketchEdge (easik.sketch.edge.SketchEdge)4 EntityNode (easik.sketch.vertex.EntityNode)4 SketchFrame (easik.ui.SketchFrame)3 EasikType (easik.database.types.EasikType)2 EntityAttribute (easik.model.attribute.EntityAttribute)2 LimitConstraint (easik.model.constraint.LimitConstraint)2 ModelConstraint (easik.model.constraint.ModelConstraint)2 UniqueIndexable (easik.model.keys.UniqueIndexable)2 NormalEdge (easik.sketch.edge.NormalEdge)2 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)2 DocumentInfo (easik.DocumentInfo)1 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)1 ProductConstraint (easik.model.constraint.ProductConstraint)1 PullbackConstraint (easik.model.constraint.PullbackConstraint)1 SumConstraint (easik.model.constraint.SumConstraint)1 GuideEdge (easik.model.edge.GuideEdge)1 TriangleEdge (easik.model.edge.TriangleEdge)1