use of easik.view.edge.NormalViewEdge in project fql by CategoricalData.
the class OverviewHandler method startElement.
/**
* Overloaded method that is called any time the start of an element is
* found
*
* @param namespace
* @see org.xml.sax.helpers.DefaultHandler
* @param localName
* @see org.xml.sax.helpers.DefaultHandler
* @param qName
* @see org.xml.sax.helpers.DefaultHandler
* @param atts
* @see org.xml.sax.helpers.DefaultHandler
*/
@Override
public void startElement(String namespace, String localName, String qName, Attributes atts) {
_currNode = qName;
// call
if (_sketchParser != null) {
_sketchParser.startElement(namespace, localName, qName, atts);
} else // Initialize a sketch handler, and note this sketch's attributes
if (qName.equals("easketch")) {
String sketchName = atts.getValue("name");
int sketchX = Integer.parseInt(atts.getValue("x"));
int sketchY = Integer.parseInt(atts.getValue("y"));
String cascade = atts.getValue("cascade"), pCascade = atts.getValue("partial-cascade");
if (cascade == null) {
cascade = Easik.getInstance().getSettings().getProperty("sql_cascade", "restrict");
}
if (pCascade == null) {
pCascade = Easik.getInstance().getSettings().getProperty("sql_cascade_partial", "set_null");
}
Cascade c = cascade.equals("cascade") ? Cascade.CASCADE : Cascade.RESTRICT;
Cascade cp = pCascade.equals("cascade") ? Cascade.CASCADE : pCascade.equals("restrict") ? Cascade.RESTRICT : Cascade.SET_NULL;
_sketchParser = SketchFileIO.getNewSketchHandler(_theFrame.getOverview());
SketchFrame frame = _sketchParser.getFrame();
Sketch sketch = frame.getMModel();
sketch.setDefaultCascading(c);
sketch.setDefaultPartialCascading(cp);
_newSketchNode = new SketchNode(sketchName, sketchX, sketchY, frame);
_sketchNodes.put(sketchName, _newSketchNode);
} else // know not to override the overview's
if (qName.equals("view")) {
_parsingView = true;
_queryNodes = new HashMap<>();
String viewName = atts.getValue("name");
int x = Integer.parseInt(atts.getValue("x"));
int y = Integer.parseInt(atts.getValue("y"));
String edgeLabel = atts.getValue("viewDefinitionEdge");
String sketchName = atts.getValue("on_sketch");
ViewFrame viewFrame = new ViewFrame(_theFrame.getOverview(), _sketchNodes.get(sketchName).getFrame().getMModel());
_newViewNode = new ViewNode(viewName, x, y, viewFrame);
_viewDefEdge.put(edgeLabel, new ViewDefinitionEdge(_newViewNode, _sketchNodes.get(sketchName), edgeLabel));
_viewDocInfo = new DocumentInfo(viewFrame);
_viewNodes.put(viewName, _newViewNode);
_sketchNodes.get(sketchName).getFrame().getMModel().addView(_newViewNode);
} else if (qName.equals("queryNode")) {
String name = atts.getValue("name");
int x = Integer.parseInt(atts.getValue("x"));
int y = Integer.parseInt(atts.getValue("y"));
String query = atts.getValue("query");
// exception so they can't be saved
try {
_queryNodes.put(name, new QueryNode(name, x, y, _newViewNode.getFrame().getMModel(), query));
} catch (QueryException e) {
e.printStackTrace();
}
} else if (qName.equals("View_Edge")) {
View_Edge newEdge;
String edgeType = atts.getValue("type");
QueryNode source = _queryNodes.get(atts.getValue("source"));
QueryNode target = _queryNodes.get(atts.getValue("target"));
String id = atts.getValue("id");
String cascadeAtt = atts.getValue("cascade");
if (cascadeAtt == null) {
// This is from an export before Easik had per-edge cascading
// (in other words, before r583)
// We use the global preferences for cascading
String key = "sql_cascade", def = "restrict";
if (edgeType.equals("partial")) {
key = "sql_cascade_partial";
def = "set_null";
}
cascadeAtt = Easik.getInstance().getSettings().getProperty(key, def);
}
@SuppressWarnings("unused") SketchEdge.Cascade cascade = cascadeAtt.equals("set_null") ? SketchEdge.Cascade.SET_NULL : cascadeAtt.equals("cascade") ? SketchEdge.Cascade.CASCADE : SketchEdge.Cascade.RESTRICT;
if (edgeType.equals("injective")) {
newEdge = new InjectiveViewEdge(source, target, id);
} else if (edgeType.equals("partial")) {
newEdge = new PartialViewEdge(source, target, id);
} else {
newEdge = new NormalViewEdge(source, target, id);
}
_viewEdges.put(id, newEdge);
}
}
use of easik.view.edge.NormalViewEdge in project fql by CategoricalData.
the class View method autoAddExistingEdges.
/**
* Call this method when a new QueryNode or Edge is created to automatically
* add whatever existing edges It has in the underlying sketch with other
* existing QueryNodes.
*
* @author Federico Mora
*/
public void autoAddExistingEdges() {
Collection<SketchEdge> sketchEdges = _ourSketch.getEdges().values();
HashMap<EntityNode, QueryNode> nodeMatches = getEntityNodePairs();
for (SketchEdge se : sketchEdges) {
if (nodeMatches.containsKey(se.getTargetEntity()) && nodeMatches.containsKey(se.getSourceEntity()) && !_edges.containsKey(se.getName())) {
View_Edge vEdge;
// need to move down??
if (se.isPartial()) {
vEdge = new PartialViewEdge(nodeMatches.get(se.getSourceEntity()), nodeMatches.get(se.getTargetEntity()), se.getName());
} else if (se.isInjective()) {
// System.out.println("Edge is injective");
// **NEED TO FIGURE OUT CASCADING
vEdge = new InjectiveViewEdge(nodeMatches.get(se.getSourceEntity()), nodeMatches.get(se.getTargetEntity()), se.getName(), Cascade.RESTRICT);
} else {
vEdge = new NormalViewEdge(nodeMatches.get(se.getSourceEntity()), nodeMatches.get(se.getTargetEntity()), se.getName());
}
this.addEdge(vEdge);
}
}
}
use of easik.view.edge.NormalViewEdge 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