Search in sources :

Example 51 with EntityNode

use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.

the class JDBCUpdateMonitor method updateRow.

/**
 * Pops up a row entry dialog for the given table. The default field values
 * will be the values stored in the row of the table who's primary ID
 * matches the one given. Some cases call for use to restrict the update of
 * foreign keys. Those cases are: a) A pullback b) The summands of a sum
 * constrain c) The product of a product constraint If the table is in a
 * constraint and the user wishes to break it the update is aborted leaving
 * the old values in the record. Note: There are currently no checks to
 * ensure that pk matches a record in our table.
 *
 * @param table
 *            The EntityNode representing the table we wish to update.
 * @param pk
 *            The primary ID of the row whos data will be used to set
 *            defaults for our row entry dialog.
 * @return The Success of the update.
 */
@Override
public boolean updateRow(final EntityNode table, final int pk) {
    final DialogOptions dOpts = getDialogOptions(table);
    try {
        // Remove option to update foreign keys restricted by constraints
        for (final ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> c : table.getConstraints()) {
            for (final SketchEdge se : table.getOutgoingEdges()) {
                if (c.hasEdge(se)) {
                    dOpts.fKeys.remove(cn.tableFK(se));
                }
            }
        }
        // Display dialog for user with defaults as old record values
        final RowEntryDialog red = new RowEntryDialog(_theSketch.getFrame(), "Update " + table.getName() + ": " + cn.tablePK(table) + " = " + pk, dOpts.attToType, dOpts.fKeys, DatabaseUtil.getRecord(table, pk));
        if (red.isAccepted()) {
            final Set<ColumnEntry> input = new LinkedHashSet<>(red.getInput());
            // if we do not have any new input, no need to execute an update
            if (input.isEmpty()) {
                return true;
            }
            final StringBuilder sb = new StringBuilder("UPDATE " + table.getName() + " SET ");
            for (final ColumnEntry ce : input) {
                sb.append(dbd.quoteId(ce.getColumnName())).append('=' + "?,");
            }
            // remove last comma
            sb.delete(sb.length() - 1, sb.length());
            sb.append(" WHERE ").append(cn.tablePK(table)).append('=').append(pk);
            dbd.executePreparedUpdate(sb.toString(), input);
            return true;
        }
        return false;
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(table.getMModel().getFrame(), "Could not update record: " + e.getMessage());
        return false;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SQLException(java.sql.SQLException) ColumnEntry(easik.ui.datamanip.ColumnEntry) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode) SketchFrame(easik.ui.SketchFrame) SketchEdge(easik.sketch.edge.SketchEdge) Sketch(easik.sketch.Sketch) RowEntryDialog(easik.ui.datamanip.RowEntryDialog)

Example 52 with EntityNode

use of easik.sketch.vertex.EntityNode 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 53 with EntityNode

use of easik.sketch.vertex.EntityNode 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 54 with EntityNode

use of easik.sketch.vertex.EntityNode 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)

Example 55 with EntityNode

use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.

the class Sketch method initialiseModel.

/**
 * When we initialise the sketch, we flush out all the data concerning the
 * sketch itself.
 *
 * This methods serves as a "new sketch" function.
 */
@Override
public void initialiseModel() {
    clearSelection();
    model = new SketchGraphModel(this);
    final GraphLayoutCache glc = new GraphLayoutCache(model, new ModelViewFactory<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>());
    setModel(model);
    setGraphLayoutCache(glc);
    _nodes = new LinkedHashMap<>();
    _edges = new LinkedHashMap<>();
    if (_Frame.getInfoTreeUI() != null) {
        // Wipe
        _Frame.setInfoTreeUI(new ModelInfoTreeUI<>(_Frame));
        // Tree
        _Frame.getInfoTreeUI().refreshTree();
    }
    _docInfo.reset();
    _views = new HashMap<>();
    _connParams = new HashMap<>();
    model.discardUndo();
}
Also used : SketchFrame(easik.ui.SketchFrame) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) SketchEdge(easik.sketch.edge.SketchEdge) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode)

Aggregations

EntityNode (easik.sketch.vertex.EntityNode)62 SketchEdge (easik.sketch.edge.SketchEdge)45 Sketch (easik.sketch.Sketch)30 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)30 SketchFrame (easik.ui.SketchFrame)29 LinkedList (java.util.LinkedList)21 LimitConstraint (easik.model.constraint.LimitConstraint)16 ProductConstraint (easik.model.constraint.ProductConstraint)15 PullbackConstraint (easik.model.constraint.PullbackConstraint)15 SumConstraint (easik.model.constraint.SumConstraint)15 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)12 ModelConstraint (easik.model.constraint.ModelConstraint)12 ArrayList (java.util.ArrayList)12 ModelPath (easik.model.path.ModelPath)8 InjectiveEdge (easik.sketch.edge.InjectiveEdge)7 UpdateMonitor (easik.ui.datamanip.UpdateMonitor)6 SQLException (java.sql.SQLException)6 LinkedHashSet (java.util.LinkedHashSet)6 QueryNode (easik.view.vertex.QueryNode)5 XSDAnnotation (easik.xml.xsd.nodes.XSDAnnotation)5