use of easik.view.edge.View_Edge in project fql by CategoricalData.
the class View method initialiseModel.
/**
* When we initialize the sketch, we flush out all the data concerning the
* sketch itself. Even the modelAdapter is reinitialized.
*
* This methods serves as a "new sketch" function.
*/
@Override
public void initialiseModel() {
clearSelection();
model = new ViewGraphModel(this);
final GraphLayoutCache glc = new GraphLayoutCache(model, new ModelViewFactory<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>());
setModel(model);
setGraphLayoutCache(glc);
_nodes = new LinkedHashMap<>();
_edges = new LinkedHashMap<>();
if (_Frame.getInfoTreeUI() != null) {
// Wipe
_Frame.setInfoTreeUI(new ModelInfoTreeUI<>(_Frame));
// Tree
_Frame.getInfoTreeUI().refreshTree();
}
_docInfo.reset();
model.discardUndo();
}
use of easik.view.edge.View_Edge in project fql by CategoricalData.
the class View method addEdge.
/**
* Adds a collection (set, list, etc.) of edges to the view.
*
* @param inEdges
* Collection of ViewEdges to add
*
* @author Sarah van der Laan 2013
*/
public void addEdge(Collection<View_Edge> inEdges) {
for (View_Edge edge : inEdges) {
// Add our edge to the graph
getGraphLayoutCache().insert(edge);
// System.out.println("SOURCE: " +
// edge.getSourceQueryNode().getName());
// System.out.println("TARGET: " +
// edge.getTargetQueryNode().getName());
_edges.put(edge.getName(), edge);
}
addConstraints();
refresh();
_theOverview.refresh();
}
use of easik.view.edge.View_Edge in project fql by CategoricalData.
the class OverviewFileIO method viewToElement.
/**
* Converts a view to an Element
*
* @param document
* The Document in which our information will be placed.
* @param view
* The view we're reading
* @return All of the information needed to rebuild the view contained in an
* Element. Returns null in the event that the element could not be
* created.
*
* @version 2014, Federico Mora
*/
public static Element viewToElement(Document document, View view) {
try {
Element rootElement = document.createElement("view");
Element header = document.createElement("header");
DocumentInfo d = view.getDocInfo();
Element name = document.createElement("title");
name.appendChild(document.createTextNode(d.getName()));
header.appendChild(name);
for (String aut : d.getAuthors()) {
Element author = document.createElement("author");
author.appendChild(document.createTextNode(aut));
header.appendChild(author);
}
Element desc = document.createElement("description");
desc.appendChild(document.createTextNode(d.getDesc()));
header.appendChild(desc);
Element creationDate = document.createElement("creationDate");
creationDate.appendChild(document.createTextNode(EasikConstants.XML_DATETIME.format(d.getCreationDate())));
header.appendChild(creationDate);
Element modDate = document.createElement("lastModificationDate");
modDate.appendChild(document.createTextNode(EasikConstants.XML_DATETIME.format(d.getModificationDate())));
header.appendChild(modDate);
rootElement.appendChild(header);
Element queryNodes = document.createElement("queryNodes");
// Loop through query nodes, add them to the document
for (QueryNode currentNode : view.getEntities()) {
if (currentNode == null) {
continue;
}
Element thisNode = document.createElement("queryNode");
thisNode.setAttribute("name", currentNode.toString());
thisNode.setAttribute("x", currentNode.getX() + "");
thisNode.setAttribute("y", currentNode.getY() + "");
String query = currentNode.getQuery();
thisNode.setAttribute("query", (query == null) ? "" : query);
queryNodes.appendChild(thisNode);
}
rootElement.appendChild(queryNodes);
Element edges = document.createElement("ViewEdges");
for (View_Edge currentEdge : view.getEdges().values()) {
Element thisEdge = document.createElement("ViewEdge");
thisEdge.setAttribute("id", currentEdge.getName());
thisEdge.setAttribute("source", currentEdge.getSourceQueryNode().getName());
thisEdge.setAttribute("target", currentEdge.getTargetQueryNode().getName());
thisEdge.setAttribute("type", (currentEdge instanceof PartialViewEdge) ? "partial" : (currentEdge instanceof InjectiveViewEdge) ? "injective" : "normal");
thisEdge.setAttribute("cascade", (currentEdge.getCascading() == View_Edge.Cascade.SET_NULL) ? "set_null" : (currentEdge.getCascading() == View_Edge.Cascade.CASCADE) ? "cascade" : "restrict");
edges.appendChild(thisEdge);
}
rootElement.appendChild(edges);
return rootElement;
} catch (Exception e) {
return null;
}
}
use of easik.view.edge.View_Edge in project fql by CategoricalData.
the class EditViewEdgeAction method actionPerformed.
/**
* Called when clicked upon, will popup the edge UI and, if accepted, update
* the name and cascade option.
*
* @param e
* The action event
*/
@Override
public void actionPerformed(ActionEvent e) {
View _ourView = _theFrame.getMModel();
Object[] currentSelection = _ourView.getSelectionCells();
// non-edges which might be selected
if ((currentSelection.length == 1) && (currentSelection[0] instanceof View_Edge)) {
// cancel operation
if (_ourView.getSketch().isSynced()) {
if (JOptionPane.showConfirmDialog(_theFrame, "Warning: this sketch is currently synced with a db; delete and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
return;
}
}
View_Edge edge = (View_Edge) currentSelection[0];
ViewEdgeOptions opts = new ViewEdgeOptions(_theFrame, edge);
if (opts.isAccepted()) {
if (!opts.getName().equals(edge.getName())) {
edge.setName(opts.getName());
}
// edge.setCascading(opts.getCascadeMode());
_theFrame.getInfoTreeUI().refreshTree();
_ourView.getGraphLayoutCache().reload();
_ourView.clearSelection();
_ourView.repaint();
_ourView.setDirty();
// _ourView.getMModel().setSynced(false);
}
}
}
use of easik.view.edge.View_Edge 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