Search in sources :

Example 1 with DefineQueryNodeDialog

use of easik.ui.DefineQueryNodeDialog 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 2 with DefineQueryNodeDialog

use of easik.ui.DefineQueryNodeDialog 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 3 with DefineQueryNodeDialog

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

DefineQueryNodeDialog (easik.ui.DefineQueryNodeDialog)3 QueryException (easik.view.util.QueryException)3 ViewFrame (easik.ui.ViewFrame)2 View (easik.view.View)2 QueryNode (easik.view.vertex.QueryNode)1