use of easik.model.edge.ModelEdge.Cascade 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.model.edge.ModelEdge.Cascade in project fql by CategoricalData.
the class OverviewFileIO method overviewToXML.
/**
* Converts an overview to an XML file. Returns the success of the save.
*
* @param outputFile
* The file we will output to
* @param overview
* The sketch we're reading to
* @return True if successful, false otherwise
*/
public static boolean overviewToXML(File outputFile, Overview overview) {
Document overviewAsXML;
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = docBuilderFactory.newDocumentBuilder();
overviewAsXML = db.newDocument();
Element rootElement = overviewAsXML.createElement("easketch_overview");
Element header = overviewAsXML.createElement("header");
Element sketches = overviewAsXML.createElement("sketches");
Element views = overviewAsXML.createElement("views");
// Add Header info to document
DocumentInfo d = overview.getDocInfo();
Element name = overviewAsXML.createElement("title");
name.appendChild(overviewAsXML.createTextNode(d.getName()));
header.appendChild(name);
for (String aut : d.getAuthors()) {
Element author = overviewAsXML.createElement("author");
author.appendChild(overviewAsXML.createTextNode(aut));
header.appendChild(author);
}
Element desc = overviewAsXML.createElement("description");
desc.appendChild(overviewAsXML.createTextNode(d.getDesc()));
header.appendChild(desc);
Element creationDate = overviewAsXML.createElement("creationDate");
creationDate.appendChild(overviewAsXML.createTextNode(EasikConstants.XML_DATETIME.format(d.getCreationDate())));
header.appendChild(creationDate);
Element modDate = overviewAsXML.createElement("lastModificationDate");
modDate.appendChild(overviewAsXML.createTextNode(EasikConstants.XML_DATETIME.format(d.getModificationDate())));
header.appendChild(modDate);
// Loop through sketches, add them to the document
for (SketchNode currentSketch : overview.getSketches()) {
if (currentSketch != null) {
Element thisSketch = SketchFileIO.sketchToElement(overviewAsXML, currentSketch.getFrame().getMModel());
thisSketch.setAttribute("name", currentSketch.toString());
thisSketch.setAttribute("x", currentSketch.getX() + "");
thisSketch.setAttribute("y", currentSketch.getY() + "");
Cascade c = currentSketch.getFrame().getMModel().getDefaultCascading();
Cascade cp = currentSketch.getFrame().getMModel().getDefaultPartialCascading();
thisSketch.setAttribute("cascade", (c == Cascade.CASCADE) ? "cascade" : "restrict");
thisSketch.setAttribute("partial-cascade", (cp == Cascade.CASCADE) ? "cascade" : (cp == Cascade.RESTRICT) ? "restrict" : "set_null");
sketches.appendChild(thisSketch);
}
}
for (ViewNode currentView : overview.getViews()) {
if (currentView != null) {
Element thisView = viewToElement(overviewAsXML, currentView.getFrame().getMModel());
thisView.setAttribute("name", currentView.toString());
thisView.setAttribute("x", currentView.getX() + "");
thisView.setAttribute("y", currentView.getY() + "");
ViewDefinitionEdge thisViewEdge = overview.getViewEdge(currentView.getFrame().getMModel());
thisView.setAttribute("viewDefinitionEdge", thisViewEdge.getName());
thisView.setAttribute("on_sketch", thisViewEdge.getTargetNode().getName());
views.appendChild(thisView);
}
}
// Add root elements to document
overviewAsXML.appendChild(rootElement);
rootElement.appendChild(header);
rootElement.appendChild(sketches);
rootElement.appendChild(views);
} catch (Exception e) {
e.printStackTrace();
overviewAsXML = null;
}
outputXMLtoFile(outputFile, overviewAsXML);
return true;
}
use of easik.model.edge.ModelEdge.Cascade in project fql by CategoricalData.
the class EdgeOptions method getOptions.
/**
* @return
*/
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<Option> getOptions() {
LinkedList<Option> opts = new LinkedList<>();
_edgeName = JUtils.textField((_edge != null) ? _edge.getName() : _theFrame.getMModel().getNewEdgeName(_type == Edge.INJECTIVE));
opts.add(new Option("Edge name", _edgeName));
if ((_edge == null) && (_type != Edge.SELF)) {
// A new edge, but not a
// self-referencing edge
_edgeDirection = new JComboBox(new String[] { _source.getName() + " to " + _target.getName(), _target.getName() + " to " + _source.getName() });
opts.add(new Option("Edge direction", _edgeDirection));
}
boolean partial = ((_type == Edge.SELF) || (_type == Edge.PARTIAL));
_cascadeMode = new JComboBox();
String cascadeTT = "This option affects how this edge is handled when exporting to a db.\n\n\"Cascade\" cause deletions in this table to trigger deletions of any rows in other tables that point to the row(s) being deleted.\n\n\"Restrict\" causes attempted deletions of referenced rows to fail.";
if (partial) {
_cascadeMode.addItem("Set null");
cascadeTT = "This option affects how this edge is handled when exporting to a db.\n\n\"Cascade\" cause deletions in this table to trigger deletions of any rows in other tables that point to the row(s) being deleted.\n\n\"Restrict\" cause attempted deletions of referenced rows to fail.\n\n\"Set null\" causes references to be set to NULL when the targeted row is deleted.";
}
_cascadeMode.addItem("Restrict");
_cascadeMode.addItem("Cascade");
cascadeTT = JUtils.tooltip(cascadeTT);
JLabel cascadeLabel = new JLabel("On deletion");
cascadeLabel.setToolTipText(cascadeTT);
_cascadeMode.setToolTipText(cascadeTT);
if (_edge != null) {
if (_edge.getCascading() == Cascade.CASCADE) {
_cascadeMode.setSelectedIndex(partial ? 2 : 1);
} else if (_edge.getCascading() == Cascade.RESTRICT) {
_cascadeMode.setSelectedIndex(partial ? 1 : 0);
} else {
_cascadeMode.setSelectedIndex(0);
}
} else {
if (partial) {
Cascade defCascade = _theFrame.getMModel().getDefaultPartialCascading();
// String cascade =
// Easik.getInstance().getSettings().getProperty("sql_cascade_partial",
// "set_null");
_cascadeMode.setSelectedIndex((defCascade == Cascade.CASCADE) ? 2 : (defCascade == Cascade.RESTRICT) ? 1 : 0);
} else {
Cascade defCascade = _theFrame.getMModel().getDefaultCascading();
// String cascade =
// Easik.getInstance().getSettings().getProperty("sql_cascade",
// "restrict");
_cascadeMode.setSelectedIndex((defCascade == Cascade.CASCADE) ? 1 : 0);
}
}
opts.add(new Option(cascadeLabel, _cascadeMode));
return opts;
}
Aggregations