Search in sources :

Example 36 with Sketch

use of easik.sketch.Sketch in project fql by CategoricalData.

the class DocInfoUI method getOptions.

/**
 * @return
 */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<Option> getOptions() {
    LinkedList<Option> opts = new LinkedList<>();
    // Add a title:
    if (context == InfoContext.OVERVIEW) {
        opts.add(new Option.Title("Document information"));
    } else if (context == InfoContext.SKETCH) {
        opts.add(new Option.Title("Sketch information"));
    } else {
        opts.add(new Option.Title("View information"));
    }
    // Add the name field
    opts.add(new Option(new JLabel("Title"), name = JUtils.textField(docInfo.getName(), 15)));
    // Add the author field
    opts.add(new Option(new JLabel("Author(s)"), author = JUtils.textField(docInfo.getAuthorString(), 15)));
    // Add the description field
    opts.add(new Option(new JLabel("Description"), description = JUtils.textArea(docInfo.getDesc())));
    // add the time info
    Date created = docInfo.getCreationDate(), modified = docInfo.getModificationDate();
    String sCreated = (created == null) ? "N/A" : EasikConstants.DATETIME_LONG.format(created);
    String sModified = (modified == null) ? "N/A" : EasikConstants.DATETIME_LONG.format(modified);
    opts.add(new Option(new JLabel("Created"), new JLabel(sCreated)));
    opts.add(new Option(new JLabel("Last modified"), new JLabel(sModified)));
    // edges of this sketch
    if (context == InfoContext.SKETCH) {
        Sketch sketch = ((SketchFrame) _theFrame).getMModel();
        edgeCascading = new JComboBox(new String[] { "Restrict deletions", "Cascade deletions" });
        edgeCascading.setSelectedIndex((sketch.getDefaultCascading() == Cascade.CASCADE) ? 1 : 0);
        edgeCascadingPartial = new JComboBox(new String[] { "Set null", "Restrict deletions", "Cascade deletions" });
        edgeCascadingPartial.setSelectedIndex((sketch.getDefaultPartialCascading() == Cascade.CASCADE) ? 2 : (sketch.getDefaultPartialCascading() == Cascade.RESTRICT) ? 1 : 0);
        JLabel cascadeLabel = new JLabel("Edge Cascading");
        String cascadeTT = JUtils.tooltip("This option affects how new edges of this sketch are handled when exporting to a db.\n\n\"Cascade deletions\" cause deletions in one table to trigger deletions of any rows in other tables that point to the row(s) being deleted.\n\n\"Restrict deletions\" causes attempted deletions of referenced rows to fail.\n\nThis option will be used by default for any new normal or injective edges of this sketch.");
        cascadeLabel.setToolTipText(cascadeTT);
        edgeCascading.setToolTipText(cascadeTT);
        opts.add(new Option(cascadeLabel, edgeCascading));
        JLabel cascadePartialLabel = new JLabel("Partial Edge Cascading");
        String cascadePartialTT = JUtils.tooltip("This option affects how EASIK creates partial edges when exporting to a db.\n\n\"Cascade deletions\" cause deletions in one table to trigger deletions of any rows in other tables that point to the row(s) being deleted.\n\n\"Restrict deletions\" cause attempted deletions of referenced rows to fail.\n\n\"Set null\" causes references to be set to NULL when the targeted row is deleted.\n\nThis option will be used by default for new partial edges of this sketch.");
        cascadePartialLabel.setToolTipText(cascadePartialTT);
        edgeCascadingPartial.setToolTipText(cascadePartialTT);
        opts.add(new Option(cascadePartialLabel, edgeCascadingPartial));
    }
    return opts;
}
Also used : JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) Sketch(easik.sketch.Sketch) LinkedList(java.util.LinkedList) Date(java.util.Date)

Example 37 with Sketch

use of easik.sketch.Sketch 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 38 with Sketch

use of easik.sketch.Sketch 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 39 with Sketch

use of easik.sketch.Sketch in project fql by CategoricalData.

the class NewViewEdgeAction 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) {
    View _ourView = _theFrame.getMModel();
    Sketch _ourSketch = _ourView.getSketch();
    boolean foundEdge = false, forward = false, reverse = false;
    // 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 = _ourView.getSelectionCells();
    QueryNode currNode = (QueryNode) currentSelection[0];
    String queryString = currNode.getQuery();
    String entityNodeName = null;
    // find corresponding entity node name
    String[] tokens = queryString.split("\\s+");
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i].equalsIgnoreCase("from")) {
            entityNodeName = tokens[i + 1];
        }
    }
    EntityNode[] node = new EntityNode[2];
    // set corresponding node in order to use
    for (EntityNode sketchNode : _ourSketch.getEntities()) {
        if (sketchNode.getName().equalsIgnoreCase(entityNodeName)) {
            node[0] = sketchNode;
        }
    }
    if (currentSelection.length > 1) {
        currNode = (QueryNode) currentSelection[1];
        queryString = currNode.getQuery();
        entityNodeName = null;
        // find corresponding entity node name
        tokens = queryString.split("\\s+");
        for (int i = 0; i < tokens.length; i++) {
            if (tokens[i].equalsIgnoreCase("from")) {
                entityNodeName = tokens[i + 1];
            }
        }
        // set corresponding node in order to use
        for (EntityNode sketchNode : _ourSketch.getEntities()) {
            if (sketchNode.getName().equalsIgnoreCase(entityNodeName)) {
                node[1] = sketchNode;
            }
        }
        for (SketchEdge edge : _ourSketch.getEdges().values()) {
            View_Edge vEdge;
            forward = (edge.getTargetEntity().equals(node[0]) && edge.getSourceEntity().equals(node[1]));
            reverse = (edge.getTargetEntity().equals(node[1]) && edge.getSourceEntity().equals(node[0]));
            if (forward || reverse) {
                // System.out.println("This edge exists");
                foundEdge = true;
                // need to move down??
                if (edge.isPartial()) {
                    // ***NEED TO FIGURE OUT CASCADING
                    vEdge = new PartialViewEdge((QueryNode) currentSelection[0], (QueryNode) currentSelection[0], edge.getName());
                } else if (edge.isInjective()) {
                    // **NEED TO FIGURE OUT CASCADING
                    if (forward) {
                        vEdge = new InjectiveViewEdge((QueryNode) currentSelection[1], (QueryNode) currentSelection[0], edge.getName(), Cascade.RESTRICT);
                    } else {
                        vEdge = new InjectiveViewEdge((QueryNode) currentSelection[0], (QueryNode) currentSelection[1], edge.getName(), Cascade.RESTRICT);
                    }
                // System.out.println(vEdge.getName());
                } else {
                    if (forward) {
                        vEdge = new NormalViewEdge((QueryNode) currentSelection[1], (QueryNode) currentSelection[0], edge.getName());
                    } else {
                        vEdge = new NormalViewEdge((QueryNode) currentSelection[0], (QueryNode) currentSelection[1], edge.getName());
                    }
                }
                _ourView.addEdge(vEdge);
            }
        }
        if (!foundEdge) {
        // System.out.println("This edge does not exist");
        }
    } else // end checking if 2 nodes
    // edge that goes into itself
    {
    /*
			 * for(SketchEdge edge: node[0].getOutgoingEdges()) {
			 * 
			 * }
			 */
    }
}
Also used : NormalViewEdge(easik.view.edge.NormalViewEdge) View(easik.view.View) View_Edge(easik.view.edge.View_Edge) InjectiveViewEdge(easik.view.edge.InjectiveViewEdge) PartialViewEdge(easik.view.edge.PartialViewEdge) EntityNode(easik.sketch.vertex.EntityNode) SketchEdge(easik.sketch.edge.SketchEdge) QueryNode(easik.view.vertex.QueryNode) Sketch(easik.sketch.Sketch)

Example 40 with Sketch

use of easik.sketch.Sketch in project fql by CategoricalData.

the class RenameInSketchAction method actionPerformed.

/**
 * Called when clicked upon, will rename an article.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    Sketch _ourSketch = _theFrame.getMModel();
    // If we're currently synced, let user cancel operation.
    if (_ourSketch.isSynced()) {
        if (JOptionPane.showConfirmDialog(_theFrame, "Warning: this sketch is currently synced with a db; continue and break synchronization?", "Caution!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
            return;
        }
    }
    Object[] currentSelection = _ourSketch.getSelectionCells();
    EntityNode nodeToRename = null;
    // If only one entity is selected, then we allow this. We will ignore
    // any
    // non-entities which might be selected
    String originalName = "";
    if ((currentSelection.length == 1) && (currentSelection[0] instanceof EntityNode)) {
        nodeToRename = (EntityNode) currentSelection[0];
        originalName = nodeToRename.getName();
    }
    if (nodeToRename == null) {
        JOptionPane.showMessageDialog(_ourSketch.getParent(), "Operation must be performed with a single entity selected", "Error", JOptionPane.ERROR_MESSAGE);
    } else {
        String s = (String) JOptionPane.showInputDialog(_ourSketch.getParent(), "New name:", "Rename entity", JOptionPane.QUESTION_MESSAGE, null, null, originalName);
        if (s != null) {
            s = s.trim();
            if (s.equals("")) {
                JOptionPane.showMessageDialog(_ourSketch.getParent(), "Entity name is empty", "Error", JOptionPane.ERROR_MESSAGE);
            } else if (_ourSketch.isNameUsed(s) && !nodeToRename.getName().equals(s)) {
                JOptionPane.showMessageDialog(_ourSketch.getParent(), "Entity name is already in use", "Error", JOptionPane.ERROR_MESSAGE);
            } else if (s.equals(originalName)) {
                // no need to do anything
                ;
            } else {
                // Push loading state
                _ourSketch.getStateManager().pushState(new LoadingState<>(_ourSketch));
                nodeToRename.setName(s);
                _theFrame.getInfoTreeUI().refreshTree();
                _ourSketch.getGraphLayoutCache().reload();
                // Pop state
                _ourSketch.getStateManager().popState();
                _ourSketch.repaint();
                _ourSketch.setDirty();
                _ourSketch.setSynced(false);
            }
        }
        _ourSketch.clearSelection();
    }
}
Also used : Sketch(easik.sketch.Sketch) EntityNode(easik.sketch.vertex.EntityNode)

Aggregations

Sketch (easik.sketch.Sketch)40 SketchEdge (easik.sketch.edge.SketchEdge)32 EntityNode (easik.sketch.vertex.EntityNode)30 SketchFrame (easik.ui.SketchFrame)30 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)27 LimitConstraint (easik.model.constraint.LimitConstraint)16 ProductConstraint (easik.model.constraint.ProductConstraint)16 SumConstraint (easik.model.constraint.SumConstraint)16 PullbackConstraint (easik.model.constraint.PullbackConstraint)15 LinkedList (java.util.LinkedList)15 ModelConstraint (easik.model.constraint.ModelConstraint)13 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)12 ModelPath (easik.model.path.ModelPath)9 ArrayList (java.util.ArrayList)7 LinkedHashSet (java.util.LinkedHashSet)7 InjectiveEdge (easik.sketch.edge.InjectiveEdge)5 XSDAnnotation (easik.xml.xsd.nodes.XSDAnnotation)5 XSDType (easik.xml.xsd.nodes.types.XSDType)5 EasikType (easik.database.types.EasikType)4 EntityAttribute (easik.model.attribute.EntityAttribute)4