Search in sources :

Example 1 with InjectiveViewEdge

use of easik.view.edge.InjectiveViewEdge in project fql by CategoricalData.

the class OverviewHandler 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;
    // call
    if (_sketchParser != null) {
        _sketchParser.startElement(namespace, localName, qName, atts);
    } else // Initialize a sketch handler, and note this sketch's attributes
    if (qName.equals("easketch")) {
        String sketchName = atts.getValue("name");
        int sketchX = Integer.parseInt(atts.getValue("x"));
        int sketchY = Integer.parseInt(atts.getValue("y"));
        String cascade = atts.getValue("cascade"), pCascade = atts.getValue("partial-cascade");
        if (cascade == null) {
            cascade = Easik.getInstance().getSettings().getProperty("sql_cascade", "restrict");
        }
        if (pCascade == null) {
            pCascade = Easik.getInstance().getSettings().getProperty("sql_cascade_partial", "set_null");
        }
        Cascade c = cascade.equals("cascade") ? Cascade.CASCADE : Cascade.RESTRICT;
        Cascade cp = pCascade.equals("cascade") ? Cascade.CASCADE : pCascade.equals("restrict") ? Cascade.RESTRICT : Cascade.SET_NULL;
        _sketchParser = SketchFileIO.getNewSketchHandler(_theFrame.getOverview());
        SketchFrame frame = _sketchParser.getFrame();
        Sketch sketch = frame.getMModel();
        sketch.setDefaultCascading(c);
        sketch.setDefaultPartialCascading(cp);
        _newSketchNode = new SketchNode(sketchName, sketchX, sketchY, frame);
        _sketchNodes.put(sketchName, _newSketchNode);
    } else // know not to override the overview's
    if (qName.equals("view")) {
        _parsingView = true;
        _queryNodes = new HashMap<>();
        String viewName = atts.getValue("name");
        int x = Integer.parseInt(atts.getValue("x"));
        int y = Integer.parseInt(atts.getValue("y"));
        String edgeLabel = atts.getValue("viewDefinitionEdge");
        String sketchName = atts.getValue("on_sketch");
        ViewFrame viewFrame = new ViewFrame(_theFrame.getOverview(), _sketchNodes.get(sketchName).getFrame().getMModel());
        _newViewNode = new ViewNode(viewName, x, y, viewFrame);
        _viewDefEdge.put(edgeLabel, new ViewDefinitionEdge(_newViewNode, _sketchNodes.get(sketchName), edgeLabel));
        _viewDocInfo = new DocumentInfo(viewFrame);
        _viewNodes.put(viewName, _newViewNode);
        _sketchNodes.get(sketchName).getFrame().getMModel().addView(_newViewNode);
    } else if (qName.equals("queryNode")) {
        String name = atts.getValue("name");
        int x = Integer.parseInt(atts.getValue("x"));
        int y = Integer.parseInt(atts.getValue("y"));
        String query = atts.getValue("query");
        // exception so they can't be saved
        try {
            _queryNodes.put(name, new QueryNode(name, x, y, _newViewNode.getFrame().getMModel(), query));
        } catch (QueryException e) {
            e.printStackTrace();
        }
    } else if (qName.equals("View_Edge")) {
        View_Edge newEdge;
        String edgeType = atts.getValue("type");
        QueryNode source = _queryNodes.get(atts.getValue("source"));
        QueryNode target = _queryNodes.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);
        }
        @SuppressWarnings("unused") 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 InjectiveViewEdge(source, target, id);
        } else if (edgeType.equals("partial")) {
            newEdge = new PartialViewEdge(source, target, id);
        } else {
            newEdge = new NormalViewEdge(source, target, id);
        }
        _viewEdges.put(id, newEdge);
    }
}
Also used : NormalViewEdge(easik.view.edge.NormalViewEdge) ViewFrame(easik.ui.ViewFrame) SketchNode(easik.overview.vertex.SketchNode) ViewDefinitionEdge(easik.overview.edge.ViewDefinitionEdge) View_Edge(easik.view.edge.View_Edge) InjectiveViewEdge(easik.view.edge.InjectiveViewEdge) PartialViewEdge(easik.view.edge.PartialViewEdge) SketchFrame(easik.ui.SketchFrame) QueryException(easik.view.util.QueryException) SketchEdge(easik.sketch.edge.SketchEdge) QueryNode(easik.view.vertex.QueryNode) Sketch(easik.sketch.Sketch) ViewNode(easik.overview.vertex.ViewNode) Cascade(easik.model.edge.ModelEdge.Cascade) DocumentInfo(easik.DocumentInfo)

Example 2 with InjectiveViewEdge

use of easik.view.edge.InjectiveViewEdge in project fql by CategoricalData.

the class ViewGraphModel method getAttributes.

/**
 * Overridden method to get cell attributes; we make sure the appropriate
 * attributes are applied to the Easik objects before returning them.
 *
 * @see DefaultGraphModel.getAttributes(Object)
 *
 * @param o
 *
 * @return
 */
@Override
@SuppressWarnings("unchecked")
public AttributeMap getAttributes(Object o) {
    _mode = (_view.getSketch().getFrame().getMode() == Mode.EDIT) ? "edit_" : "manip_";
    if (o instanceof GraphCell) {
        GraphCell cell = (GraphCell) o;
        AttributeMap attribs = cell.getAttributes();
        AttributeMap easikAttribs = null;
        if (cell instanceof View_Edge) {
            easikAttribs = (cell instanceof InjectiveViewEdge) ? injectiveEdgeAttributes() : (cell instanceof PartialViewEdge) ? partialEdgeAttributes() : normalEdgeAttributes();
        } else if (cell instanceof TriangleEdge) {
            easikAttribs = triangleEdgeAttributes((TriangleEdge<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>) cell);
        } else if (cell instanceof GuideEdge) {
            easikAttribs = ((GuideEdge<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>) cell).isHighlighted() ? virtualHighlightedEdgeAttributes() : virtualEdgeAttributes();
        } else if (cell instanceof ModelConstraint) {
            easikAttribs = virtualVertexAttributes();
        } else if (cell instanceof QueryNode) {
            easikAttribs = vertexAttributes();
        }
        if (easikAttribs != null) {
            if (_view.isCellSelected(cell)) {
                Color selColor;
                float lineWidth;
                if (_view.getStateManager().peekState() instanceof GetPathState) {
                    selColor = getColor("path_selection");
                    lineWidth = getWidth("path_selection", 2);
                } else {
                    selColor = getColor("selection");
                    lineWidth = getWidth("selection", 3);
                }
                int borderWidth = getIntWidth(_mode + ((cell instanceof ModelConstraint) ? "constraint" : "entity") + "_border", 1);
                GraphConstants.setBorder(easikAttribs, BorderFactory.createLineBorder(selColor, borderWidth));
                GraphConstants.setForeground(easikAttribs, selColor);
                GraphConstants.setLineColor(easikAttribs, selColor);
                GraphConstants.setLineWidth(easikAttribs, lineWidth);
            }
            if (attribs == null) {
                cell.setAttributes(easikAttribs);
                attribs = easikAttribs;
            } else {
                attribs.applyMap(easikAttribs);
            }
            return attribs;
        }
    }
    return super.getAttributes(o);
}
Also used : ModelConstraint(easik.model.constraint.ModelConstraint) GraphCell(org.jgraph.graph.GraphCell) ViewFrame(easik.ui.ViewFrame) Color(java.awt.Color) TriangleEdge(easik.model.edge.TriangleEdge) View_Edge(easik.view.edge.View_Edge) InjectiveViewEdge(easik.view.edge.InjectiveViewEdge) View(easik.view.View) PartialViewEdge(easik.view.edge.PartialViewEdge) ModelConstraint(easik.model.constraint.ModelConstraint) AttributeMap(org.jgraph.graph.AttributeMap) QueryNode(easik.view.vertex.QueryNode) GetPathState(easik.model.states.GetPathState) GuideEdge(easik.model.edge.GuideEdge)

Example 3 with InjectiveViewEdge

use of easik.view.edge.InjectiveViewEdge in project fql by CategoricalData.

the class View method autoAddExistingEdges.

/**
 * Call this method when a new QueryNode or Edge is created to automatically
 * add whatever existing edges It has in the underlying sketch with other
 * existing QueryNodes.
 *
 * @author Federico Mora
 */
public void autoAddExistingEdges() {
    Collection<SketchEdge> sketchEdges = _ourSketch.getEdges().values();
    HashMap<EntityNode, QueryNode> nodeMatches = getEntityNodePairs();
    for (SketchEdge se : sketchEdges) {
        if (nodeMatches.containsKey(se.getTargetEntity()) && nodeMatches.containsKey(se.getSourceEntity()) && !_edges.containsKey(se.getName())) {
            View_Edge vEdge;
            // need to move down??
            if (se.isPartial()) {
                vEdge = new PartialViewEdge(nodeMatches.get(se.getSourceEntity()), nodeMatches.get(se.getTargetEntity()), se.getName());
            } else if (se.isInjective()) {
                // System.out.println("Edge is injective");
                // **NEED TO FIGURE OUT CASCADING
                vEdge = new InjectiveViewEdge(nodeMatches.get(se.getSourceEntity()), nodeMatches.get(se.getTargetEntity()), se.getName(), Cascade.RESTRICT);
            } else {
                vEdge = new NormalViewEdge(nodeMatches.get(se.getSourceEntity()), nodeMatches.get(se.getTargetEntity()), se.getName());
            }
            this.addEdge(vEdge);
        }
    }
}
Also used : SketchEdge(easik.sketch.edge.SketchEdge) NormalViewEdge(easik.view.edge.NormalViewEdge) QueryNode(easik.view.vertex.QueryNode) View_Edge(easik.view.edge.View_Edge) InjectiveViewEdge(easik.view.edge.InjectiveViewEdge) PartialViewEdge(easik.view.edge.PartialViewEdge) EntityNode(easik.sketch.vertex.EntityNode)

Example 4 with InjectiveViewEdge

use of easik.view.edge.InjectiveViewEdge 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 5 with InjectiveViewEdge

use of easik.view.edge.InjectiveViewEdge 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

InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)5 PartialViewEdge (easik.view.edge.PartialViewEdge)5 View_Edge (easik.view.edge.View_Edge)5 QueryNode (easik.view.vertex.QueryNode)5 SketchEdge (easik.sketch.edge.SketchEdge)3 NormalViewEdge (easik.view.edge.NormalViewEdge)3 DocumentInfo (easik.DocumentInfo)2 Sketch (easik.sketch.Sketch)2 EntityNode (easik.sketch.vertex.EntityNode)2 ViewFrame (easik.ui.ViewFrame)2 View (easik.view.View)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 SketchFrame (easik.ui.SketchFrame)1