Search in sources :

Example 6 with ViewFrame

use of easik.ui.ViewFrame in project fql by CategoricalData.

the class DefineQueryNodeFromTreeAction method updateNode.

/**
 * Prompts user for name and query values and make appropriate updates on
 * query node.
 *
 * @param ourNode
 */
public static void updateNode(QueryNode ourNode) {
    ViewFrame ourFrame = ourNode.getMModel().getFrame();
    View ourView = ourFrame.getMModel();
    String originalName = ourNode.getName();
    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();
    }
    String query = dqnd.getQuery();
    try {
        ourNode.setQuery(query);
    } catch (QueryException e) {
        JOptionPane.showMessageDialog(ourView.getParent(), "New Query not set. Not valid query.", "Error", JOptionPane.ERROR_MESSAGE);
    }
    ourView.clearSelection();
}
Also used : QueryException(easik.view.util.QueryException) DefineQueryNodeDialog(easik.ui.DefineQueryNodeDialog) ViewFrame(easik.ui.ViewFrame) View(easik.view.View)

Example 7 with ViewFrame

use of easik.ui.ViewFrame in project fql by CategoricalData.

the class View method initialiseModel.

/**
 * When we initialize the sketch, we flush out all the data concerning the
 * sketch itself. Even the modelAdapter is reinitialized.
 *
 * This methods serves as a "new sketch" function.
 */
@Override
public void initialiseModel() {
    clearSelection();
    model = new ViewGraphModel(this);
    final GraphLayoutCache glc = new GraphLayoutCache(model, new ModelViewFactory<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>());
    setModel(model);
    setGraphLayoutCache(glc);
    _nodes = new LinkedHashMap<>();
    _edges = new LinkedHashMap<>();
    if (_Frame.getInfoTreeUI() != null) {
        // Wipe
        _Frame.setInfoTreeUI(new ModelInfoTreeUI<>(_Frame));
        // Tree
        _Frame.getInfoTreeUI().refreshTree();
    }
    _docInfo.reset();
    model.discardUndo();
}
Also used : ViewGraphModel(easik.view.util.graph.ViewGraphModel) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) ViewFrame(easik.ui.ViewFrame) QueryNode(easik.view.vertex.QueryNode) View_Edge(easik.view.edge.View_Edge)

Example 8 with ViewFrame

use of easik.ui.ViewFrame 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

ViewFrame (easik.ui.ViewFrame)8 View_Edge (easik.view.edge.View_Edge)4 QueryNode (easik.view.vertex.QueryNode)4 View (easik.view.View)3 QueryException (easik.view.util.QueryException)3 ViewDefinitionEdge (easik.overview.edge.ViewDefinitionEdge)2 ViewNode (easik.overview.vertex.ViewNode)2 DefineQueryNodeDialog (easik.ui.DefineQueryNodeDialog)2 SketchFrame (easik.ui.SketchFrame)2 InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)2 PartialViewEdge (easik.view.edge.PartialViewEdge)2 ViewGraphModel (easik.view.util.graph.ViewGraphModel)2 DocumentInfo (easik.DocumentInfo)1 ModelConstraint (easik.model.constraint.ModelConstraint)1 GuideEdge (easik.model.edge.GuideEdge)1 Cascade (easik.model.edge.ModelEdge.Cascade)1 TriangleEdge (easik.model.edge.TriangleEdge)1 GetPathState (easik.model.states.GetPathState)1 Overview (easik.overview.Overview)1 SketchNode (easik.overview.vertex.SketchNode)1