Search in sources :

Example 11 with ModelConstraint

use of easik.model.constraint.ModelConstraint 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 12 with ModelConstraint

use of easik.model.constraint.ModelConstraint in project fql by CategoricalData.

the class EntityNode method getShadowEdges.

/**
 * This method returns the edges that will be "shadowed" in this entity for
 * allowing various types of constraints. The problem arises when we have
 * something like: A -&gt; B -&gt; C, where A is the summand of B, but B has
 * to be specified. In this case, the B to C edge will be returned as a
 * "shadow" edge. We handle this for other constraint types, too. For a
 * good, working, technical example, see the shadowEdges.easik sample
 * sketch.
 *
 * @return a set of edges that will be shadowed by this entity node.
 *
 *         Removing shadow edges completely. Started by Sarah Van der Laan
 *         continued by Federico Mora because a partial solution is worse
 *         than all or nothing
 *
 *         public LinkedHashSet<SketchEdge> getShadowEdges() { return
 *         getShadowEdges(new LinkedHashSet<EntityNode>(5), new
 *         LinkedHashSet<SketchEdge>(5)); }
 */
// Package-only implementation of the above that breaks recursion by
// ignoring
// shadowed nodes that we already know about.
/**
 * @param ignore
 * @param constraintEdges
 *
 * @return
 */
LinkedHashSet<SketchEdge> getShadowEdges(final Collection<EntityNode> ignore, final LinkedHashSet<SketchEdge> constraintEdges) {
    // These are the other entity node that we (potentially) need to shadow:
    final Collection<EntityNode> shadow = new LinkedHashSet<>(10);
    CONSTRAINT: for (final ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> c : getMModel().getConstraints().values()) {
        if (c instanceof SumConstraint) {
            final SumConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> s = (SumConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c;
            for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : s.getPaths()) {
                // for this entity, of course):
                if (path.getDomain() == this) {
                    shadow.addAll(path.getEntities());
                    constraintEdges.addAll(path.getEdges());
                    continue CONSTRAINT;
                }
            }
        } else if (c instanceof ProductConstraint) {
            final ProductConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> p = (ProductConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c;
            for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : p.getPaths()) {
                // codomains), along each product path
                if (path.getCoDomain() == this) {
                    for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> prodPath : p.getPaths()) {
                        // But we ignore all of the product path edges,
                        // since they will be automatically generated:
                        constraintEdges.addAll(prodPath.getEdges());
                        final Deque<EntityNode> pathNodes = new LinkedList<>();
                        pathNodes.addAll(prodPath.getEntities());
                        pathNodes.removeLast();
                        shadow.addAll(pathNodes);
                    }
                    continue CONSTRAINT;
                }
            }
        } else if (c instanceof EqualizerConstraint) {
            final EqualizerConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> e = (EqualizerConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c;
            // injective *edge* doesn't cause that problem).
            if (e.getSourceEntity() == this) {
                final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> projection = e.getProjection();
                shadow.addAll(projection.getEntities());
                // Ignore the projection edge itself:
                constraintEdges.addAll(projection.getEdges());
                continue CONSTRAINT;
            }
        } else if (c instanceof PullbackConstraint) {
            final PullbackConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> pb = (PullbackConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c;
            // WPBEDIT CF2012
            for (int i = 0; i < pb.getWidth(); i++) {
                ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> proj = pb.getProjectionPath(i);
                if (this == proj.getCoDomain()) {
                    for (int j = 0; j < pb.getWidth(); j++) {
                        proj = pb.getProjectionPath(j);
                        Deque<EntityNode> projNodes = new LinkedList<>(proj.getEntities());
                        projNodes.removeLast();
                        shadow.addAll(projNodes);
                        constraintEdges.addAll(proj.getEdges());
                    }
                    continue CONSTRAINT;
                }
            }
        } else if (c instanceof LimitConstraint) {
        // TRIANGLES TODO CF2012 incomplete
        }
    }
    final LinkedHashSet<SketchEdge> shadowEdges = new LinkedHashSet<>(20);
    // All of the ignore entities, plus everything we just found should be
    // ignored by any recursion:
    final Collection<EntityNode> toIgnore = new LinkedHashSet<>(3);
    toIgnore.add(this);
    toIgnore.addAll(ignore);
    toIgnore.addAll(shadow);
    for (final EntityNode node : shadow) {
        // it:
        if ((node == this) || ignore.contains(node)) {
            continue;
        }
        // Otherwise, shadow its non-partial edges, and all of its shadow
        // edges:
        shadowEdges.addAll(node.getShadowEdges(toIgnore, constraintEdges));
        shadowEdges.addAll(node.getNonPartialEdges());
        // Remove edges already
        shadowEdges.removeAll(constraintEdges);
    // involved in the sum
    }
    return shadowEdges;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LimitConstraint(easik.model.constraint.LimitConstraint) ModelConstraint(easik.model.constraint.ModelConstraint) PullbackConstraint(easik.model.constraint.PullbackConstraint) SumConstraint(easik.model.constraint.SumConstraint) 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) ModelConstraint(easik.model.constraint.ModelConstraint) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) SketchFrame(easik.ui.SketchFrame) ProductConstraint(easik.model.constraint.ProductConstraint) SketchEdge(easik.sketch.edge.SketchEdge) ModelPath(easik.model.path.ModelPath) EqualizerConstraint(easik.model.constraint.EqualizerConstraint) Sketch(easik.sketch.Sketch)

Example 13 with ModelConstraint

use of easik.model.constraint.ModelConstraint in project fql by CategoricalData.

the class JDBCViewUpdateMonitor method getDialogOptions.

/**
 * Gets the options needed for open a dialog for row insertion: map of
 * attribute names to their type, and a map of foreign key names to a JTable
 * of data they point to.
 *
 * @param table
 *            The node representing the table who's information we want
 * @return Wrapper class holding the maps needed for insertion dialog
 */
private DialogOptions getDialogOptions(final EntityNode table) {
    @SuppressWarnings("unused") final HashSet<ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> constraints = new HashSet<ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>>(table.getConstraints());
    final HashMap<String, EasikType> attToType = new HashMap<>(25);
    final LinkedHashMap<String, EntityNode> fKeys = new LinkedHashMap<>(10);
    // find attributes, and map to their EasikType
    for (final EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> ea : table.getEntityAttributes()) {
        attToType.put(ea.getName(), ea.getType());
    }
    // find all foreign keys, and add to foreign key set
    for (final SketchEdge ske : table.getOutgoingEdges()) {
        fKeys.put(cn.tableFK(ske), ske.getTargetEntity());
    }
    return new DialogOptions(attToType, fKeys);
}
Also used : ModelConstraint(easik.model.constraint.ModelConstraint) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode) LinkedHashMap(java.util.LinkedHashMap) SketchFrame(easik.ui.SketchFrame) SketchEdge(easik.sketch.edge.SketchEdge) Sketch(easik.sketch.Sketch) EasikType(easik.database.types.EasikType) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 14 with ModelConstraint

use of easik.model.constraint.ModelConstraint in project fql by CategoricalData.

the class DeleteFromSketchAction method actionPerformed.

/**
 * When the action is performed, selection is deleted if possible. Error is
 * displayed if no graph item is selected.
 *
 * @param e
 *            The action event
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void actionPerformed(ActionEvent e) {
    Sketch _ourSketch = _theFrame.getMModel();
    // The confirm delete message. If we're currently synced with a db, add
    // that to the message;
    String confirm = _ourSketch.isSynced() ? "Warning: this sketch is currently synced with a db; delete and break synchronization?" : "Are you sure you want to delete selected item(s)?";
    if (JOptionPane.showConfirmDialog(_theFrame, confirm, "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
        return;
    }
    Object[] currentSelection = _ourSketch.getSelectionCells();
    if (currentSelection.length == 0) {
        JOptionPane.showMessageDialog(_theFrame, "Operation must be performed with something selected", "Error", JOptionPane.ERROR_MESSAGE);
    } else {
        _ourSketch.getGraphModel().beginUpdate();
        // First, delete any constraints:
        for (Object o : currentSelection) {
            if (o instanceof ModelConstraint) {
                _ourSketch.removeConstraint((ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) o);
                for (ViewNode v : _ourSketch.getViews()) {
                    if (v.getMModel().getConstraints().containsKey(((ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) o).getID())) {
                        v.getMModel().removeConstraint(((ModelConstraint) o));
                    }
                }
            }
        }
        // THEN any edges:
        for (Object o : currentSelection) {
            if (o instanceof SketchEdge) {
                for (ViewNode v : _theFrame.getMModel().getViews()) {
                    if (v.getMModel().getEdges().containsKey(((SketchEdge) o).getName())) {
                        // put up a warning cause this exists in a View
                        if (JOptionPane.showConfirmDialog(_theFrame, "SketchEdge " + ((SketchEdge) o).getName() + " exists in a View. Continue and delete in view as well?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
                            return;
                        }
                        // if we want to proceed and delete it...
                        v.getMModel().removeEdge(v.getMModel().getEdges().get(((SketchEdge) o).getName()));
                    }
                }
                _ourSketch.removeEdge((SketchEdge) o);
            }
        }
        // Then finally, any entities.
        for (Object o : currentSelection) {
            if (o instanceof EntityNode) {
                for (ViewNode v : _theFrame.getMModel().getViews()) {
                    if (v.getMModel().getEntityNodePairs().containsKey((o))) {
                        // put up a warning cause this exists in a View
                        if (JOptionPane.showConfirmDialog(_theFrame, "EntityNode " + ((EntityNode) o).getName() + " is being queried by a View. Continue and delete in view as well?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
                            return;
                        }
                        // if we want to proceed and delete it...
                        v.getMModel().removeNode(v.getMModel().getEntityNodePairs().get(o));
                    }
                }
                _ourSketch.removeNode((EntityNode) o);
            }
        }
        _ourSketch.setDirty();
        _ourSketch.getGraphModel().endUpdate();
        _ourSketch.setSynced(false);
    }
    // Clear selection after things have been deleted
    _ourSketch.clearSelection();
}
Also used : SketchFrame(easik.ui.SketchFrame) ModelConstraint(easik.model.constraint.ModelConstraint) SketchEdge(easik.sketch.edge.SketchEdge) Sketch(easik.sketch.Sketch) ViewNode(easik.overview.vertex.ViewNode) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode)

Aggregations

ModelConstraint (easik.model.constraint.ModelConstraint)14 Sketch (easik.sketch.Sketch)9 SketchEdge (easik.sketch.edge.SketchEdge)8 SketchFrame (easik.ui.SketchFrame)8 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)7 EntityNode (easik.sketch.vertex.EntityNode)7 ProductConstraint (easik.model.constraint.ProductConstraint)6 SumConstraint (easik.model.constraint.SumConstraint)6 CommutativeDiagram (easik.model.constraint.CommutativeDiagram)5 LinkedHashSet (java.util.LinkedHashSet)5 LimitConstraint (easik.model.constraint.LimitConstraint)4 PullbackConstraint (easik.model.constraint.PullbackConstraint)4 HashSet (java.util.HashSet)4 GuideEdge (easik.model.edge.GuideEdge)3 ModelPath (easik.model.path.ModelPath)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 EasikType (easik.database.types.EasikType)2 Int (easik.database.types.Int)2 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)2 TriangleEdge (easik.model.edge.TriangleEdge)2