use of easik.overview.edge.ViewDefinitionEdge 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.overview.edge.ViewDefinitionEdge in project fql by CategoricalData.
the class Overview method addNewView.
/**
* Add a view to a given sketch node
*
* @param sketch
* @param viewName
* The name of the new view. Assumes no naming naming conflict
* @return The new view node
*/
public ViewNode addNewView(SketchNode sketch, String viewName) {
Point newP = getNewViewPosition(sketch.getX(), sketch.getY(), 10);
ViewFrame newFrame = new ViewFrame(this, sketch.getFrame().getMModel());
ViewNode newNode = new ViewNode(viewName, (int) newP.getX(), (int) newP.getY(), newFrame);
sketch.getFrame().getMModel().addView(newNode);
// Add our ViewNode
addVertex(newNode);
// Add edge to out connected sketch
addViewEdge(new ViewDefinitionEdge(newNode, sketch, getNewEdgeName()));
return newNode;
}
use of easik.overview.edge.ViewDefinitionEdge in project fql by CategoricalData.
the class Overview method removeView.
/**
* Remove view and it's view edge from the overview.
*
* @param remove
*/
public void removeView(ViewNode remove) {
// remove from sketch
View toRemove = remove.getFrame().getMModel();
toRemove.getSketch().removeView(toRemove.getName());
for (ViewDefinitionEdge edge : _viewEdges.values()) {
if (edge.getSourceNode().getName().equals(toRemove.getName())) {
removeViewEdge(edge);
break;
}
}
// remove from overview graph
_viewNodes.remove(toRemove.getName());
getGraphLayoutCache().remove(new Object[] { remove });
// remove from info tree
_appFrame.getInfoTreeUI().removeView(toRemove.getFrame().getNode());
// dispose of the frame
remove.getFrame().dispose();
}
use of easik.overview.edge.ViewDefinitionEdge in project fql by CategoricalData.
the class Overview method initializeFromData.
/**
* Used to initialise a new sketch based on provided data (usually from the
* Sketch loading methods).
*
* @param sketchNodes
* A Map of all of the sketches in the overview
* @param viewNodes
* @param viewDefinitionEdges
* @param docInfo
* The document information to be stored along with this overview
*/
public void initializeFromData(Map<String, SketchNode> sketchNodes, Map<String, ViewNode> viewNodes, Map<String, ViewDefinitionEdge> viewDefinitionEdges, DocumentInfo docInfo) {
initializeOverview();
_sketchNodes = new HashMap<>();
_viewNodes = new HashMap<>();
_viewEdges = new HashMap<>();
_docInfo = docInfo;
for (SketchNode node : sketchNodes.values()) {
if (node != null) {
addVertex(node);
}
}
for (ViewNode node : viewNodes.values()) {
if (node != null) {
addVertex(node);
}
}
for (ViewDefinitionEdge edge : viewDefinitionEdges.values()) {
if (edge != null) {
addViewEdge(edge);
}
}
refresh();
}
use of easik.overview.edge.ViewDefinitionEdge 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;
}
Aggregations