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