Search in sources :

Example 16 with QueryNode

use of easik.view.vertex.QueryNode in project fql by CategoricalData.

the class NewQueryNodeAction method actionPerformed.

/**
 * Create the new query node.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    String defaultName = _theFrame.getMModel().getNewName();
    QueryNode newNode;
    try {
        newNode = new QueryNode(defaultName, (int) _newPoint.getX(), (int) _newPoint.getY(), _theFrame.getMModel(), "");
        DefineQueryNodeDialog dqnd = new DefineQueryNodeDialog(_theFrame, "New Query Node", newNode);
        if (!dqnd.isAccepted()) {
            return;
        }
        String name = dqnd.getName();
        while (name.equals("") || _theFrame.getMModel().isNameUsed(name)) {
            JOptionPane.showMessageDialog(_theFrame, "Error while naming entity.\n" + "Please ensure that entity name is:\n" + "1) Not blank\n" + "2) Not already in use", "Error", JOptionPane.ERROR_MESSAGE);
            name = (String) JOptionPane.showInputDialog(_theFrame, "Name for new entity:", "Get name", JOptionPane.QUESTION_MESSAGE, null, null, name);
            if (name == null) {
                return;
            }
            name = name.trim();
        }
        String query = dqnd.getQuery();
        newNode.setName(name);
        newNode.setQuery(query);
        _theFrame.getMModel().addEntity(newNode);
        _theFrame.getMModel().setDirty();
    } catch (QueryException e1) {
        // this can technically throw an exception in two spots but will
        // only really throw in the setQuery call
        // because the first call, a constructor call to queryNode, gives an
        // emptry query which is ok
        JOptionPane.showMessageDialog(_theFrame.getParent(), "New Query node not created. Not valid query.\n" + e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : QueryException(easik.view.util.QueryException) DefineQueryNodeDialog(easik.ui.DefineQueryNodeDialog) QueryNode(easik.view.vertex.QueryNode)

Example 17 with QueryNode

use of easik.view.vertex.QueryNode 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 18 with QueryNode

use of easik.view.vertex.QueryNode in project fql by CategoricalData.

the class ViewDeleteAction method actionPerformed.

/**
 * @param e
 *            The action event
 * @author Sarah van der Laan
 */
@Override
public void actionPerformed(ActionEvent e) {
    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 _ourEntityNode = null;
    // set corresponding node in order to use
    for (EntityNode node : _ourSketch.getEntities()) {
        if (node.getName().equalsIgnoreCase(entityNodeName)) {
            _ourEntityNode = node;
        }
    }
    if (!_ourSketch.hasDatabase()) {
        JOptionPane.showMessageDialog(null, "Not currently connected to a database.");
        return;
    } else {
        UpdateMonitor um = _ourSketch.getDatabase().newUpdateMonitor();
        if (um == null) {
            JOptionPane.showMessageDialog(null, "Could not perform update: problem accessing db driver");
            return;
        }
        if (_ourEntityNode != null)
            um.deleteFrom(_ourEntityNode);
    }
}
Also used : UpdateMonitor(easik.ui.datamanip.UpdateMonitor) QueryNode(easik.view.vertex.QueryNode) EntityNode(easik.sketch.vertex.EntityNode)

Aggregations

QueryNode (easik.view.vertex.QueryNode)18 View_Edge (easik.view.edge.View_Edge)8 EntityNode (easik.sketch.vertex.EntityNode)5 InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)5 PartialViewEdge (easik.view.edge.PartialViewEdge)5 ViewFrame (easik.ui.ViewFrame)4 SketchEdge (easik.sketch.edge.SketchEdge)3 UpdateMonitor (easik.ui.datamanip.UpdateMonitor)3 NormalViewEdge (easik.view.edge.NormalViewEdge)3 QueryException (easik.view.util.QueryException)3 DocumentInfo (easik.DocumentInfo)2 Sketch (easik.sketch.Sketch)2 View (easik.view.View)2 ViewGraphModel (easik.view.util.graph.ViewGraphModel)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 AttributeMap (org.jgraph.graph.AttributeMap)2 GraphLayoutCache (org.jgraph.graph.GraphLayoutCache)2 ModelConstraint (easik.model.constraint.ModelConstraint)1 GuideEdge (easik.model.edge.GuideEdge)1 Cascade (easik.model.edge.ModelEdge.Cascade)1