use of easik.view.vertex.QueryNode in project fql by CategoricalData.
the class View method addEntity.
/**
* Adds a collection (set, list, etc.) of QueryNodes to the graph.
*
* @param theEntities
* the collection of entities to be added.
*/
public void addEntity(final Collection<QueryNode> theEntities) {
// Push loading state
_stateManager.pushState(new LoadingState<>(this));
final GraphLayoutCache glc = getGraphLayoutCache();
model.beginUpdate();
for (final QueryNode node : theEntities) {
// Set the on-screen position of our entity to the attributes of the
// entity
final AttributeMap nAttribs = node.getAttributes();
GraphConstants.setAutoSize(nAttribs, true);
GraphConstants.setBounds(nAttribs, new Rectangle2D.Double(node.getX(), node.getY(), 0, 0));
if (_nodes.containsKey(node.getName())) {
node.setName(node.getName());
}
// Add our entity to the graph
glc.insert(node);
// Add our entity to our table of entities
_nodes.put(node.toString(), node);
// Add Entity to tree
_Frame.getInfoTreeUI().addNode(node);
}
model.postEdit(new AbstractUndoableEdit() {
/**
*/
private static final long serialVersionUID = -74767611415529681L;
@Override
public void undo() {
super.undo();
for (final QueryNode node : theEntities) {
_nodes.remove(node.toString());
}
}
@Override
public void redo() {
super.redo();
for (final QueryNode node : theEntities) {
_nodes.put(node.toString(), node);
}
}
});
model.endUpdate();
autoAddExistingEdges();
// Reload the graph to respect the new changes
glc.reload();
// Pop state
_stateManager.popState();
}
use of easik.view.vertex.QueryNode in project fql by CategoricalData.
the class View method removeNode.
/**
* Removes an entity, and also cascades to remove all the arrows involved
* with it.
*
* @param toRemove
* The entity about to be removed
*/
@Override
public void removeNode(final QueryNode toRemove) {
// So we don't get a ConcurrentModificationException
final ArrayList<View_Edge> removeEdges = new ArrayList<>();
for (final View_Edge edge : _edges.values()) {
if (edge.getSourceQueryNode().equals(toRemove) || edge.getTargetQueryNode().equals(toRemove)) {
// add the edge to a list of edges to remove
removeEdges.add(edge);
}
}
model.beginUpdate();
// Remove the edges
for (final View_Edge e : removeEdges) {
removeEdge(e);
}
// remove the constraints this queryNode is a part of
for (ModelConstraint<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge> c : toRemove.getConstraints()) {
if (_constraints.containsKey(c.getID())) {
this.removeConstraint(c);
}
}
_nodes.remove(toRemove.toString());
getGraphLayoutCache().remove(new Object[] { toRemove });
// Remove Entity from tree
_Frame.getInfoTreeUI().removeNode(toRemove);
model.endUpdate();
}
use of easik.view.vertex.QueryNode in project fql by CategoricalData.
the class View method addNewNode.
/**
* Add a new, empty entity at point X, Y
*
* @param name
* The name of the new entity being added
* @param x
* X Coordinate of new entity
* @param y
* Y Coordinate of new entity
*/
@Override
public void addNewNode(final String name, final double x, final double y) {
final QueryNode newEntity;
// this won't throw exception because query is blank
try {
newEntity = new QueryNode(name, (int) x, (int) y, this, "");
addEntity(newEntity);
} catch (QueryException e) {
e.printStackTrace();
}
}
use of easik.view.vertex.QueryNode 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.vertex.QueryNode 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;
}
}
Aggregations