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();
}
Aggregations