Search in sources :

Example 16 with SketchFrame

use of easik.ui.SketchFrame in project fql by CategoricalData.

the class DocumentInfo method setAllInfo.

/**
 * Sets all editable information, with the parameters determined by the
 * user. If any parameters have been changed, the sketch is set to dirty so
 * user will be prompted for a save if an attempt to discard the current
 * sketch is made before a save. If a name change results in a conflict, we
 * add numbers. If no name is specified, we keep the old name.
 *
 * @param name
 *            The name of the sketch
 * @param author
 *            The string of all authors of the sketch
 * @param desc
 *            The description of the sketch
 */
public void setAllInfo(String name, String author, String desc) {
    name = name.trim();
    if (!_name.equals(name) || !getAuthorString().equals(author) || !_desc.equals(desc)) {
        Overview overview = _theFrame.getOverview();
        if (_theFrame instanceof SketchFrame) {
            ((SketchFrame) _theFrame).getNode().setName(name);
            ((SketchFrame) _theFrame).getMModel().setDirty();
        } else if (_theFrame instanceof ViewFrame) {
            ((ViewFrame) _theFrame).getNode().setName(name);
            ((ViewFrame) _theFrame).getMModel().setDirty();
        } else {
            // The Sketch and View setDirty()'s
            overview.setDirty(true);
        // will make this happen anyway
        }
        if (!name.equals("")) {
            setName(name);
        }
        _authors = new ArrayList<>();
        for (String aut : author.split(",")) {
            aut = aut.trim();
            if (!aut.equals("")) {
                _authors.add(aut);
            }
        }
        _desc = desc;
    }
}
Also used : SketchFrame(easik.ui.SketchFrame) ViewFrame(easik.ui.ViewFrame) Overview(easik.overview.Overview)

Example 17 with SketchFrame

use of easik.ui.SketchFrame in project fql by CategoricalData.

the class XSDElement method setKeys.

/**
 * Use an entity node to set the keys, including foreign keyrefs and
 * uniques.
 * <p/>
 * Key is set from the primary key. KeyRefs are set from the outgoing edges.
 * Uniques are set by Uniques and by noninclusion injective outgoing edges.
 *
 * @param node
 *            we are working with
 */
@SuppressWarnings("unused")
public void setKeys(final EntityNode node) {
    final List<UniqueKey<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> uniqueKeyList = node.getUniqueKeys();
    final XSDComplexType myType = (XSDComplexType) getElementType();
    constraints = new ArrayList<XSDAbstractKey>(uniqueKeyList.size() + 3);
    final String idName = Easik.getInstance().getSettings().getProperty("xml_id_name");
    final String keyrefName = Easik.getInstance().getSettings().getProperty("xml_keyref_name");
    final boolean idIsAttribute = Boolean.valueOf(Easik.getInstance().getSettings().getProperty("xml_id_is_attribute"));
    final XSDKey primaryKey = node.createXMLPrimaryKey(this);
    final XSDElement theParent = (XSDElement) getParent();
    theParent.addConstraint(primaryKey);
    for (final SketchEdge edge : node.getOutgoingEdges()) {
        final boolean isInclusion = edge.getTargetEntity().getName().equals(theParent.getName());
        if (edge.isInjective()) {
            if (!isInclusion) {
                constraints.add(new XSDUniqueKey(edge.getForeignKeyName(keyrefName), this, edge.getName()));
            }
        }
        if (!isInclusion) {
            theParent.addConstraint(new XSDKeyRef(this, edge.getTargetEntity().getXMLPrimaryKeyName(), edge.getName()));
            myType.addAtom(new XSDElement(edge.getName(), edge.isPartial(), XSDBaseType.xsInt));
        }
    }
    for (final UniqueKey<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> k : uniqueKeyList) {
        this.addConstraint(new XSDUniqueKey(this, k));
    }
}
Also used : XSDAbstractKey(easik.xml.xsd.nodes.constraints.XSDAbstractKey) XSDKey(easik.xml.xsd.nodes.constraints.XSDKey) XSDKeyRef(easik.xml.xsd.nodes.constraints.XSDKeyRef) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode) SketchFrame(easik.ui.SketchFrame) XSDUniqueKey(easik.xml.xsd.nodes.constraints.XSDUniqueKey) SketchEdge(easik.sketch.edge.SketchEdge) XSDUniqueKey(easik.xml.xsd.nodes.constraints.XSDUniqueKey) UniqueKey(easik.model.keys.UniqueKey) Sketch(easik.sketch.Sketch) XSDComplexType(easik.xml.xsd.nodes.types.XSDComplexType)

Example 18 with SketchFrame

use of easik.ui.SketchFrame in project fql by CategoricalData.

the class DeleteAttributeAction method actionPerformed.

/**
 * Deletes the currently selected attribute
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    // If there is nothing seleceted then just do nothing
    if (_theFrame.getInfoTreeUI().getInfoTree().isSelectionEmpty()) {
        return;
    }
    // cancel operation
    if (_theFrame.getMModel().isSynced()) {
        int choice = JOptionPane.showConfirmDialog(_theFrame, "Warning: this sketch is currently synced with a db; continue and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
        if (choice == JOptionPane.CANCEL_OPTION) {
            return;
        }
    }
    // Get currently selected object
    DefaultMutableTreeNode curSelected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree().getSelectionPath().getLastPathComponent();
    // Selection is an attribute
    if (curSelected instanceof EntityAttribute) {
        @SuppressWarnings("unchecked") EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> curAttribute = (EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) curSelected;
        EntityNode parentEntity = curAttribute.getEntity();
        // Show a confirmation dialog box for the deletion
        if (JOptionPane.showConfirmDialog(_theFrame, "Are you sure you want to delete the '" + curAttribute.getName() + "' attribute from the '" + parentEntity + "' entity?", "Confirm Delete", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
            // Delete the attribute from entity
            parentEntity.removeEntityAttribute(curAttribute);
            _theFrame.getMModel().setDirty();
            _theFrame.getMModel().setSynced(false);
        }
    } else // Selection is not an attribute
    {
        JOptionPane.showMessageDialog(_theFrame, "You don't have an attribute selected. \nPlease select an attribute and try again.", "No Attribute Selected", JOptionPane.ERROR_MESSAGE);
        return;
    }
    _theFrame.getInfoTreeUI().revertExpansion();
}
Also used : SketchFrame(easik.ui.SketchFrame) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) EntityAttribute(easik.model.attribute.EntityAttribute) SketchEdge(easik.sketch.edge.SketchEdge) Sketch(easik.sketch.Sketch) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode)

Example 19 with SketchFrame

use of easik.ui.SketchFrame in project fql by CategoricalData.

the class Overview method addNewSketch.

/**
 * Add a new sketch at point (x,y). Returns the new SketchNode.
 *
 * @param name
 *            The name of the new sketch being added
 * @param x
 *            X Coordinate of new sketch
 * @param y
 *            Y Coordinate of new sketch
 * @return the created SketchNode
 */
public SketchNode addNewSketch(String name, double x, double y) {
    SketchFrame newFrame = new SketchFrame(this);
    SketchNode newNode = new SketchNode(name, (int) x, (int) y, newFrame);
    addVertex(newNode);
    return newNode;
}
Also used : SketchFrame(easik.ui.SketchFrame) SketchNode(easik.overview.vertex.SketchNode)

Example 20 with SketchFrame

use of easik.ui.SketchFrame in project fql by CategoricalData.

the class MySQLExporter method createConstraint.

/**
 * @param constraint
 * @param id
 *
 * @return
 */
@Override
public List<String> createConstraint(final ProductConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> constraint, final String id) {
    final List<String> sql = new LinkedList<>();
    final String delConName = "productConstraint" + id + "Delete";
    StringBuilder proc = new StringBuilder(500);
    proc.append("CREATE PROCEDURE ").append(quoteId(delConName)).append("(id ").append(pkType()).append(") BEGIN").append(lineSep);
    EntityNode begin = null;
    int j = 0;
    // c.b_id = b.id JOIN d ON d.c_id = c.id...> WHERE <begin> = id;
    for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> p : constraint.getPaths()) {
        if (begin == null) {
            begin = p.getDomain();
        }
        proc.append("   DELETE ").append(quoteId(p.getCoDomain())).append(" FROM ").append(joinPath(p)).append(lineSep).append("           WHERE ").append(qualifiedPK(begin)).append(" = id;").append(lineSep);
        // Federico Mora
        StringBuilder proc1 = new StringBuilder(500);
        StringBuilder body = new StringBuilder(50);
        proc1.append("CREATE PROCEDURE ").append("Update" + constraint.getID() + "Proj" + j++).append("() BEGIN").append(lineSep);
        for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> q : constraint.getPaths()) {
            if (p == q) {
            // do nothing, cascade will take care of it
            } else {
                // making the update string which is used by all the delete
                // procedures.
                final LinkedList<SketchEdge> edges = q.getEdges();
                if (edges.size() >= 2) {
                    Iterator<SketchEdge> iter = edges.iterator();
                    SketchEdge e = iter.next();
                    body.append("   UPDATE ").append(leftJoinPath(q)).append(lineSep);
                    body.append("   SET");
                    while (iter.hasNext()) {
                        SketchEdge ske = iter.next();
                        body.append(" " + quoteId(ske.getSourceEntity()) + ".BC" + constraint.getID() + " = " + false + ",");
                    }
                    body.delete(body.length() - 1, body.length());
                    body.append(" WHERE " + qualifiedFK(e) + " IS NULL;" + lineSep);
                }
            }
        }
        if (body.length() > 0) {
            proc1.append(body);
            proc1.append("END");
            sql.add(proc1.toString());
            // Now create the triggers to call the new procedure
            addTrigger(p.getCoDomain(), "AFTER DELETE", "CALL " + quoteId("Update" + constraint.getID() + "Proj" + (j - 1)) + "()");
        }
    // end Federico Mora
    }
    // Select B.id From A Join B On A.f1 = B.id Join D On A.f3 = D.id Where
    // D.id = 1
    proc.append("END");
    sql.add(proc.toString());
    // Now create the trigger to call the new procedure
    addTrigger(begin, "BEFORE DELETE", "CALL " + quoteId(delConName) + "(OLD." + quoteId(tablePK(begin)) + ')');
    for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> p : constraint.getPaths()) {
        final EntityNode dest = p.getCoDomain();
        final String conName = "productConstraint" + id + "Insert" + cleanId(dest);
        final Collection<String> args = new LinkedList<>();
        final Collection<String> params = new LinkedList<>();
        args.add("id " + pkType());
        params.add("NEW." + quoteId(tablePK(dest)));
        // commented out by Sarah van der Laan -- caused error in generated
        // SQL file (invalid foreign keys)
        /**
         * for (final SketchEdge shadow : dest.getShadowEdges()) {
         * args.add(quoteId("NEW_shadow_" + tableFK(shadow)) + ' ' +
         * pkType()); params.add("NEW." + quoteId(tableFK(shadow))); }
         */
        proc = new StringBuilder(500);
        proc.append("CREATE PROCEDURE ").append(quoteId(conName)).append('(').append(EasikTools.join(", ", args)).append(") BEGIN").append(lineSep).append(" DECLARE _lastId ").append(pkType()).append(';').append(lineSep);
        final StringBuilder createIntermediates = new StringBuilder(250);
        final Collection<String> clauses = new LinkedList<>();
        for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> q : constraint.getPaths()) {
            if (p == q) {
                continue;
            }
            // Older versions were doing "SELECT COUNT(*) FROM TABLE", but
            // that has a big
            // performance hit for very large, busy InnoDB tables, when all
            // we really care
            // about is non-empty:
            clauses.add("(SELECT 1 FROM " + quoteId(q.getCoDomain()) + " LIMIT 1) = 1");
            // If we end up putting anything in createIntermediate, we'll
            // use these
            // insertions when we insert the first row into one of the path
            // targets
            final LinkedList<SketchEdge> sketchEdgeLinkedList = q.getEdges();
            final SketchEdge[] edges = sketchEdgeLinkedList.toArray(new SketchEdge[sketchEdgeLinkedList.size()]);
            for (int i = edges.length - 1; i > 0; i--) {
                final SketchEdge e = edges[i];
                final EntityNode source = e.getSourceEntity();
                final EntityNode target = e.getTargetEntity();
                // after source there used to be dest.getShadowEdges();
                createIntermediates.append("                        ").append(insertInto(true, source, qualifiedPK(target), quoteId(target), Collections.singletonList(quoteId(tableFK(e))), null));
            }
        }
        // In words: If the tables forming the domains of the other paths
        // contain items.
        proc.append("       IF ").append(EasikTools.join(" AND ", clauses)).append(" THEN").append(lineSep);
        if (createIntermediates.length() > 0) {
            // If we just inserted the first row, we're going to have to
            // build a path of intermediate tables
            // for the other paths, which we built in createIntermediate.
            proc.append("           IF (SELECT COUNT(*) FROM (SELECT 1 FROM ").append(quoteId(dest)).append(" LIMIT 2) a) = 1 THEN").append(lineSep).append(createIntermediates).append("               END IF;").append(lineSep).append("").append(lineSep);
        }
        // Produce the intermediate path insertion strings
        final LinkedList<SketchEdge> sketchEdgeLinkedList = p.getEdges();
        final SketchEdge[] edges = sketchEdgeLinkedList.toArray(new SketchEdge[sketchEdgeLinkedList.size()]);
        if (edges.length > 1) {
            for (int i = edges.length - 1; i > 0; i--) {
                final SketchEdge e = edges[i];
                final EntityNode source = e.getSourceEntity();
                @SuppressWarnings("unused") final EntityNode target = e.getTargetEntity();
                // after source there used to be dest.getShadowEdges();
                proc.append("               ").append(insertInto(true, source, null, null, Collections.singletonList(quoteId(tableFK(e))), Collections.singletonList((i == edges.length - 1) ? "id" : "LAST_INSERT_ID()")));
            }
            proc.append("           SET _lastId = LAST_INSERT_ID();").append(lineSep);
        } else {
            proc.append("           SET _lastId = id;").append(lineSep);
        }
        // Now the proper insertion
        final List<String> columns = new LinkedList<>();
        final Collection<String> values = new LinkedList<>();
        final Collection<String> from = new LinkedList<>();
        EntityNode thisTarget = null;
        for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> q : constraint.getPaths()) {
            final EntityNode target = q.getFirstEdge().getTargetEntity();
            columns.add(quoteId(tableFK(q.getFirstEdge())));
            values.add(qualifiedPK(target));
            from.add(quoteId(target));
            if (q == p) {
                thisTarget = target;
            }
        }
        // after begin there used to be dest.getShadowEdges();
        proc.append("               ").append(insertInto(true, begin, EasikTools.join(", ", values), EasikTools.join(" CROSS JOIN ", from) + " WHERE " + qualifiedPK(thisTarget) + " = _lastId", columns, null)).append("   END IF;").append(lineSep).append("END");
        sql.add(proc.toString());
        addTrigger(dest, "AFTER INSERT", "CALL " + quoteId(conName) + '(' + EasikTools.join(", ", params) + ')');
    }
    return delimit("$$", sql);
}
Also used : LinkedList(java.util.LinkedList) 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) EntityNode(easik.sketch.vertex.EntityNode) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) SketchFrame(easik.ui.SketchFrame) SketchEdge(easik.sketch.edge.SketchEdge) Sketch(easik.sketch.Sketch)

Aggregations

SketchFrame (easik.ui.SketchFrame)35 SketchEdge (easik.sketch.edge.SketchEdge)31 Sketch (easik.sketch.Sketch)30 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)29 EntityNode (easik.sketch.vertex.EntityNode)29 LimitConstraint (easik.model.constraint.LimitConstraint)16 ProductConstraint (easik.model.constraint.ProductConstraint)15 PullbackConstraint (easik.model.constraint.PullbackConstraint)15 SumConstraint (easik.model.constraint.SumConstraint)15 LinkedList (java.util.LinkedList)15 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)12 ModelConstraint (easik.model.constraint.ModelConstraint)12 ModelPath (easik.model.path.ModelPath)9 ArrayList (java.util.ArrayList)8 LinkedHashSet (java.util.LinkedHashSet)7 XSDAnnotation (easik.xml.xsd.nodes.XSDAnnotation)5 XSDType (easik.xml.xsd.nodes.types.XSDType)5 EasikType (easik.database.types.EasikType)4 UniqueIndexable (easik.model.keys.UniqueIndexable)4 SketchNode (easik.overview.vertex.SketchNode)4