Search in sources :

Example 46 with SketchEdge

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

the class Sketch method addEdge.

/**
 * Adds a collection (set, list, etc.) of edges to the sketch.
 *
 * @param inEdges
 *            Collection of SketchEdges to add
 */
public String addEdge(final Collection<SketchEdge> inEdges) {
    // Push loading state
    _stateManager.pushState(new LoadingState<>(this));
    final GraphLayoutCache glc = getGraphLayoutCache();
    model.beginUpdate();
    for (final SketchEdge edge : inEdges) {
        if (_edges.containsKey(edge.getName())) {
            edge.setName(edge.getName());
        }
        // Add our entity to the graph
        glc.insert(edge);
        _edges.put(edge.getName(), edge);
        edge.getSourceEntity().addDepend(edge.getTargetEntity());
    }
    String warning = "";
    String prevCycle = strongConnected;
    KosarajuSCC s = new KosarajuSCC(this);
    strongConnected = s.getSCC();
    // about this cycle previously
    if (setHasCycle(!strongConnected.isEmpty()) && !prevCycle.equals(strongConnected)) {
        warning += this.getName() + " contains a strongly connected component" + "\n        " + strongConnected + "\n";
    }
    // if there is a mismatched path pair in the sketch
    String temp = pPaths;
    pPaths = this.multPathWarning();
    if (!pPaths.isEmpty() && !temp.equals(pPaths)) {
        warning += pPaths;
    }
    if (!warning.isEmpty() && useWarnings()) {
        JOptionPane.showMessageDialog(this, warning, "Warning", JOptionPane.ERROR_MESSAGE);
    } else if (!useWarnings()) {
        return warning;
    }
    model.postEdit(new AbstractUndoableEdit() {

        /**
         */
        private static final long serialVersionUID = -6523342649950083978L;

        @Override
        public void undo() {
            super.undo();
            for (final SketchEdge edge : inEdges) {
                _edges.remove(edge.getName());
            }
        }

        @Override
        public void redo() {
            super.redo();
            for (final SketchEdge edge : inEdges) {
                _edges.put(edge.getName(), edge);
                edge.getSourceEntity().addDepend(edge.getTargetEntity());
            }
        }
    });
    model.endUpdate();
    // Pop state
    _stateManager.popState();
    refresh();
    _theOverview.refresh();
    return null;
}
Also used : AbstractUndoableEdit(javax.swing.undo.AbstractUndoableEdit) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) SketchEdge(easik.sketch.edge.SketchEdge) KosarajuSCC(easik.model.util.graph.KosarajuSCC)

Example 47 with SketchEdge

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

the class Sketch method buildpath.

/**
 * Recursive method that does most of the work for multPathWarning
 *
 * @return ArrayList used to create path
 * @author Federico Mora
 */
@SuppressWarnings("unchecked")
private static ArrayList<LinkedList<SketchEdge>> buildpath(EntityNode start, EntityNode end) {
    ArrayList<SketchEdge> visited = new ArrayList<>();
    ArrayList<LinkedList<SketchEdge>> paths = new ArrayList<>();
    // BFS uses LinkedList data structure
    LinkedList<EntityNode> LinkedList = new LinkedList<>();
    LinkedList.add(start);
    // visited.add(start);
    while (!LinkedList.isEmpty()) {
        EntityNode node = LinkedList.remove();
        for (SketchEdge ed : node.getOutgoingEdges()) {
            if (!visited.contains(ed)) {
                visited.add(ed);
                // find a LinkedList to add the edge to
                boolean queueExists = false;
                LinkedList<SketchEdge> newPath = null;
                for (LinkedList<SketchEdge> q : paths) {
                    if (q.peekLast().getTargetEntity() == ed.getSourceEntity()) {
                        newPath = (java.util.LinkedList<SketchEdge>) q.clone();
                        newPath.add(ed);
                        queueExists = true;
                        continue;
                    }
                }
                // else make a new LinkedList
                if (!queueExists) {
                    LinkedList<SketchEdge> p = new LinkedList<>();
                    p.add(ed);
                    paths.add(p);
                } else {
                    paths.add(newPath);
                }
                if (ed.getTargetEntity() == end) {
                // return paths;
                } else {
                    LinkedList.add(ed.getTargetEntity());
                }
            }
        }
    }
    return paths;
}
Also used : SketchEdge(easik.sketch.edge.SketchEdge) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) EntityNode(easik.sketch.vertex.EntityNode)

Example 48 with SketchEdge

use of easik.sketch.edge.SketchEdge 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 49 with SketchEdge

use of easik.sketch.edge.SketchEdge 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)

Example 50 with SketchEdge

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

the class DeleteRowAction method actionPerformed.

/**
 * Create the new entity and set up its name
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    Object[] currentSelection = _theSketch.getSelectionCells();
    Object selected = currentSelection[0];
    if (!(selected instanceof EntityNode)) {
        System.err.println("Action only available on entity nodes: easik.ui.menu.popup.DeleteRowAction");
        return;
    }
    EntityNode table = (EntityNode) selected;
    ArrayList<String> domains = new ArrayList<>();
    // warn user about possible cascades
    for (SketchEdge sk : _theSketch.getEdges().values()) {
        if (sk.getTargetEntity().getName().equals(table.getName()) && sk.getCascading() == Cascade.CASCADE) {
            domains.add(sk.getSourceEntity().getName());
        }
    }
    if (domains.size() > 0) {
        if (JOptionPane.showConfirmDialog(_theSketch, "Warning: Rows in this table may have foreign rows in " + domains.toString() + " which will be deleted on cascade", "Warning", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
            return;
        }
    }
    UpdateMonitor um = _theSketch.getDatabase().newUpdateMonitor();
    um.deleteFrom(table);
}
Also used : SketchEdge(easik.sketch.edge.SketchEdge) UpdateMonitor(easik.ui.datamanip.UpdateMonitor) ArrayList(java.util.ArrayList) EntityNode(easik.sketch.vertex.EntityNode)

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