Search in sources :

Example 6 with View_Edge

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();
}
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 7 with View_Edge

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();
}
Also used : View_Edge(easik.view.edge.View_Edge)

Example 8 with View_Edge

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;
    }
}
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)

Example 9 with View_Edge

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);
        }
    }
}
Also used : View(easik.view.View) View_Edge(easik.view.edge.View_Edge)

Example 10 with View_Edge

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()) {
			 * 
			 * }
			 */
    }
}
Also used : NormalViewEdge(easik.view.edge.NormalViewEdge) View(easik.view.View) View_Edge(easik.view.edge.View_Edge) InjectiveViewEdge(easik.view.edge.InjectiveViewEdge) PartialViewEdge(easik.view.edge.PartialViewEdge) EntityNode(easik.sketch.vertex.EntityNode) SketchEdge(easik.sketch.edge.SketchEdge) QueryNode(easik.view.vertex.QueryNode) Sketch(easik.sketch.Sketch)

Aggregations

View_Edge (easik.view.edge.View_Edge)10 QueryNode (easik.view.vertex.QueryNode)8 InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)5 PartialViewEdge (easik.view.edge.PartialViewEdge)5 ViewFrame (easik.ui.ViewFrame)4 SketchEdge (easik.sketch.edge.SketchEdge)3 View (easik.view.View)3 NormalViewEdge (easik.view.edge.NormalViewEdge)3 DocumentInfo (easik.DocumentInfo)2 Sketch (easik.sketch.Sketch)2 EntityNode (easik.sketch.vertex.EntityNode)2 ViewGraphModel (easik.view.util.graph.ViewGraphModel)2 ModelConstraint (easik.model.constraint.ModelConstraint)1 GuideEdge (easik.model.edge.GuideEdge)1 Cascade (easik.model.edge.ModelEdge.Cascade)1 TriangleEdge (easik.model.edge.TriangleEdge)1 GetPathState (easik.model.states.GetPathState)1 ViewDefinitionEdge (easik.overview.edge.ViewDefinitionEdge)1 SketchNode (easik.overview.vertex.SketchNode)1 ViewNode (easik.overview.vertex.ViewNode)1