Search in sources :

Example 6 with QueryException

use of easik.view.util.QueryException in project fql by CategoricalData.

the class DefineQueryNodeAction method updateNode.

/**
 * Prompts user for name and query values and make appropriate updates on
 * query node.
 *
 * @param ourNode
 */
public static void updateNode(QueryNode ourNode) {
    boolean hadWhere = !ourNode.getWhere().isEmpty();
    boolean hadEntityNode = !(ourNode.getQueriedEntity() == null);
    ViewFrame ourFrame = ourNode.getMModel().getFrame();
    View ourView = ourFrame.getMModel();
    String originalName = ourNode.getName();
    String originalQuery = ourNode.getQuery();
    DefineQueryNodeDialog dqnd = new DefineQueryNodeDialog(ourFrame, "Define Query Node", ourNode);
    if (!dqnd.isAccepted()) {
        return;
    }
    String errorMess = null;
    String name = dqnd.getName();
    if (name.equals("")) {
        errorMess = "Blank name field: did not update.";
    } else if (ourView.isNameUsed(name) && !originalName.equals(name)) {
        errorMess = "Name already in use: not update.";
    }
    if (errorMess != null) {
        JOptionPane.showMessageDialog(ourView.getParent(), errorMess, "Error", JOptionPane.ERROR_MESSAGE);
    } else if (!name.equals(originalName)) {
        ourNode.setName(name);
        ourFrame.getInfoTreeUI().refreshTree();
        ourView.getGraphLayoutCache().reload();
        ourView.repaint();
        ourView.setDirty();
    } else if (!dqnd.getQuery().equals(originalQuery)) {
        String query = dqnd.getQuery();
        // Any malformed sql should be rejected here.
        try {
            ourNode.setQuery(query);
        } catch (QueryException e) {
            JOptionPane.showMessageDialog(ourView.getParent(), "New Query not set. Not valid query.\n" + e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        if (hadWhere && ourNode.getWhere().isEmpty()) {
            // remove constraints that this queryNode used to be a part of
            ourView.updateConstraints(ourNode, hadWhere);
        } else if (!hadWhere && !ourNode.getWhere().isEmpty()) {
            ourView.updateConstraints(ourNode, hadWhere);
        }
        if (!hadEntityNode && !(ourNode.getQueriedEntity() == null)) {
            ourView.autoAddExistingEdges();
        }
    }
    ourView.clearSelection();
}
Also used : QueryException(easik.view.util.QueryException) DefineQueryNodeDialog(easik.ui.DefineQueryNodeDialog) ViewFrame(easik.ui.ViewFrame) View(easik.view.View)

Aggregations

QueryException (easik.view.util.QueryException)6 DefineQueryNodeDialog (easik.ui.DefineQueryNodeDialog)3 ViewFrame (easik.ui.ViewFrame)3 QueryNode (easik.view.vertex.QueryNode)3 View (easik.view.View)2 DocumentInfo (easik.DocumentInfo)1 Cascade (easik.model.edge.ModelEdge.Cascade)1 ViewDefinitionEdge (easik.overview.edge.ViewDefinitionEdge)1 SketchNode (easik.overview.vertex.SketchNode)1 ViewNode (easik.overview.vertex.ViewNode)1 Sketch (easik.sketch.Sketch)1 SketchEdge (easik.sketch.edge.SketchEdge)1 EntityNode (easik.sketch.vertex.EntityNode)1 SketchFrame (easik.ui.SketchFrame)1 InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)1 NormalViewEdge (easik.view.edge.NormalViewEdge)1 PartialViewEdge (easik.view.edge.PartialViewEdge)1 View_Edge (easik.view.edge.View_Edge)1 ArrayList (java.util.ArrayList)1