use of easik.sketch.edge.NormalEdge in project fql by CategoricalData.
the class KosarajuSCC method transposeDFS.
/**
* Depth first search of the transpose
*
* @param v
*/
public void transposeDFS(EntityNode v) {
visited.add(v);
sccList.add(v);
for (SketchEdge sk : graph.getEdges().values()) {
if (sk instanceof NormalEdge || sk instanceof InjectiveEdge) {
if (sk.getTargetEntity().equals(v)) {
EntityNode t = sk.getSourceEntity();
if (!visited.contains(t)) {
transposeDFS(t);
}
}
}
}
}
use of easik.sketch.edge.NormalEdge in project fql by CategoricalData.
the class KosarajuSCC method dfs.
/**
* Depth first search
*/
public void dfs(EntityNode v) {
visited.add(v);
for (SketchEdge sk : v.getOutgoingEdges()) {
if (sk instanceof NormalEdge || sk instanceof InjectiveEdge) {
EntityNode t = sk.getTargetEntity();
if (!visited.contains(t)) {
dfs(t);
}
}
}
stack.push(v);
}
use of easik.sketch.edge.NormalEdge in project fql by CategoricalData.
the class SketchHandler 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;
if (qName.equals("entity")) {
String name = atts.getValue("name");
int x = Integer.parseInt(atts.getValue("x"));
int y = Integer.parseInt(atts.getValue("y"));
if (_entityNodes.containsKey(name)) {
System.err.println("Duplicate nodes found in XML");
return;
}
_newNode = new EntityNode(name, x, y, _theFrame.getMModel());
_entityNodes.put(name, _newNode);
_curNodeAtts = new LinkedHashMap<>();
} else if (qName.equals("attribute")) {
EasikType type;
// attributeType was created by old Easik versions, and is the SQL
// type signature
// (such as "VARCHAR(255)"). Easik now uses attributeTypeClass,
// containing the
// class name, and any number of extra attributes which
// EasikType.newType() uses to
// recreate the appropriate EasikType object.
String typesig = atts.getValue("attributeType");
if (typesig != null) {
type = EasikType.typeFromSignature(typesig);
} else {
String typename = atts.getValue("attributeTypeClass");
try {
type = EasikType.newType(typename, attributeMap(atts, "attributeType", "attributeTypeClass", "name"));
} catch (ClassNotFoundException e) {
System.err.println("Invalid type found in XML: '" + typename + "' (" + e.getMessage() + ")");
return;
}
}
EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> myAtt = new EntityAttribute<>(atts.getValue("name"), type, _newNode);
_curNodeAtts.put(atts.getValue("name"), myAtt);
_newNode.addEntityAttribute(myAtt);
} else if (qName.equals("uniqueKey")) {
// New EASIK has noderef, telling us what we refer to. In old easik,
// uniqueKey is under
// the node itself (but as a result, cannot contain edge
// references).
String noderef = atts.getValue("noderef");
if (noderef != null) {
// Restore _newNode and _curNodeAtts, since we're going to need
// them:
_newNode = _entityNodes.get(noderef);
_curNodeAtts = new LinkedHashMap<>();
for (EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> att : _newNode.getEntityAttributes()) {
_curNodeAtts.put(att.getName(), att);
}
}
_curUniqueKeyName = atts.getValue("name");
_curUniqueKeyElems = new LinkedList<>();
} else if (qName.equals("attref")) {
_curUniqueKeyElems.add(_curNodeAtts.get(atts.getValue("name")));
} else if (qName.equals("edgekeyref")) {
SketchEdge e = _edges.get(atts.getValue("id"));
if (e instanceof UniqueIndexable) {
_curUniqueKeyElems.add((UniqueIndexable) e);
} else {
System.err.println("Encountered an non-unique-indexable <edgekeyref> " + e);
}
} else if (qName.equals("edge")) {
SketchEdge newEdge;
String edgeType = atts.getValue("type");
// injective is an old EASIK attribute:
String injective = atts.getValue("injective");
if (injective != null) {
edgeType = atts.getValue("injective").equals("true") ? "injective" : "normal";
}
EntityNode source = _entityNodes.get(atts.getValue("source"));
EntityNode target = _entityNodes.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);
}
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 InjectiveEdge(source, target, id, cascade);
} else if (edgeType.equals("partial")) {
newEdge = new PartialEdge(source, target, id, cascade);
} else {
newEdge = new NormalEdge(source, target, id, cascade);
}
_edges.put(id, newEdge);
} else if (qName.equals("path")) {
_curPath = new LinkedList<>();
_curPathId = atts.getValue("id");
_curDomain = _entityNodes.get(atts.getValue("domain"));
} else if (qName.equals("edgeref")) {
_curPath.add(_edges.get(atts.getValue("id")));
} else if (// TRIANGLES
qName.equals("sumconstraint") || qName.equals("pullbackconstraint") || qName.equals("productconstraint") || qName.equals("commutativediagram") || qName.equals("equalizerconstraint") || qName.equals("limitconstraint")) // CF2012
{
_curConstraintX = Integer.parseInt(atts.getValue("x"));
_curConstraintY = Integer.parseInt(atts.getValue("y"));
_curConstraintVisible = atts.getValue("isVisible").equals("true");
_curConstraintPaths = new ArrayList<>();
_allConstraintsVisible = atts.getValue("isVisible").equals("true");
} else if (qName.equals("pathref")) {
// This is for compatibility with old versions of Easik (pre-2.0);
// new versions
// put <path> elements directly inside the various constraint
// elements.
_curConstraintPaths.add(_allPaths.get(atts.getValue("id")));
} else if (qName.equals("connectionParam")) {
_connParams.put(atts.getValue("name"), atts.getValue("value"));
} else if (qName.equals("synchronized")) {
// The existance of this tag tells us the sketch is synchronized
_curSketchSync = true;
}
}
use of easik.sketch.edge.NormalEdge in project fql by CategoricalData.
the class NewSketchEdgeAction 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) {
Sketch _ourSketch = _theFrame.getMModel();
// 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 = _ourSketch.getSelectionCells();
EntityNode[] node = new EntityNode[(_edgeType == Edge.SELF) ? 1 : 2];
if (currentSelection.length == node.length) {
for (int i = 0; i < node.length; i++) {
node[i] = null;
if (currentSelection[i] instanceof EntityNode) {
node[i] = (EntityNode) currentSelection[i];
}
}
}
if ((_edgeType == Edge.SELF) && (node[0] == null)) {
JOptionPane.showMessageDialog(_theFrame, "Operation must be performed with one entity selected", "Error", JOptionPane.ERROR_MESSAGE);
} else if ((_edgeType != Edge.SELF) && ((node[0] == null) || (node[1] == null))) {
JOptionPane.showMessageDialog(_theFrame, "Operation must be performed with two entities selected", "Error", JOptionPane.ERROR_MESSAGE);
} else {
EdgeOptions opts = new EdgeOptions(_theFrame, _edgeType, node[0], (_edgeType == Edge.SELF) ? null : node[1]);
if (opts.isAccepted()) {
SketchEdge edge;
if (_edgeType == Edge.SELF) {
edge = new PartialEdge(node[0], node[0], opts.getName(), opts.getCascadeMode());
} else {
// UI:
if (opts.isReversed()) {
node = new EntityNode[] { node[1], node[0] };
}
if (_edgeType == Edge.PARTIAL) {
edge = new PartialEdge(node[0], node[1], opts.getName(), opts.getCascadeMode());
} else if (_edgeType == Edge.INJECTIVE) {
edge = new InjectiveEdge(node[0], node[1], opts.getName(), opts.getCascadeMode());
} else {
edge = new NormalEdge(node[0], node[1], opts.getName(), opts.getCascadeMode());
}
}
_ourSketch.addEdge(edge);
_ourSketch.setDirty();
_ourSketch.setSynced(false);
}
}
}
Aggregations