use of easik.sketch.edge.SketchEdge 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()) {
*
* }
*/
}
}
Aggregations