Search in sources :

Example 11 with QueryNode

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();
}
Also used : AbstractUndoableEdit(javax.swing.undo.AbstractUndoableEdit) AttributeMap(org.jgraph.graph.AttributeMap) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) QueryNode(easik.view.vertex.QueryNode) Rectangle2D(java.awt.geom.Rectangle2D)

Example 12 with QueryNode

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();
}
Also used : ViewGraphModel(easik.view.util.graph.ViewGraphModel) ViewFrame(easik.ui.ViewFrame) QueryNode(easik.view.vertex.QueryNode) ArrayList(java.util.ArrayList) View_Edge(easik.view.edge.View_Edge)

Example 13 with QueryNode

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();
    }
}
Also used : QueryException(easik.view.util.QueryException) QueryNode(easik.view.vertex.QueryNode)

Example 14 with QueryNode

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();
}
Also used : ViewGraphModel(easik.view.util.graph.ViewGraphModel) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) ViewFrame(easik.ui.ViewFrame) QueryNode(easik.view.vertex.QueryNode) View_Edge(easik.view.edge.View_Edge)

Example 15 with QueryNode

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;
    }
}
Also used : QueryNode(easik.view.vertex.QueryNode) Element(org.w3c.dom.Element) View_Edge(easik.view.edge.View_Edge) InjectiveViewEdge(easik.view.edge.InjectiveViewEdge) PartialViewEdge(easik.view.edge.PartialViewEdge) DocumentInfo(easik.DocumentInfo)

Aggregations

QueryNode (easik.view.vertex.QueryNode)18 View_Edge (easik.view.edge.View_Edge)8 EntityNode (easik.sketch.vertex.EntityNode)5 InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)5 PartialViewEdge (easik.view.edge.PartialViewEdge)5 ViewFrame (easik.ui.ViewFrame)4 SketchEdge (easik.sketch.edge.SketchEdge)3 UpdateMonitor (easik.ui.datamanip.UpdateMonitor)3 NormalViewEdge (easik.view.edge.NormalViewEdge)3 QueryException (easik.view.util.QueryException)3 DocumentInfo (easik.DocumentInfo)2 Sketch (easik.sketch.Sketch)2 View (easik.view.View)2 ViewGraphModel (easik.view.util.graph.ViewGraphModel)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 AttributeMap (org.jgraph.graph.AttributeMap)2 GraphLayoutCache (org.jgraph.graph.GraphLayoutCache)2 ModelConstraint (easik.model.constraint.ModelConstraint)1 GuideEdge (easik.model.edge.GuideEdge)1 Cascade (easik.model.edge.ModelEdge.Cascade)1