Search in sources :

Example 1 with DocumentInfo

use of easik.DocumentInfo 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 DocumentInfo

use of easik.DocumentInfo in project fql by CategoricalData.

the class SketchFileIO method sketchToElement.

/**
 * Converts a sketch to an Element.
 *
 * @param document
 *            The Document in which our information is being placed.
 * @param sketch
 * @return All of the information needed to rebuild our sketch containted in
 *         an Element. Returns null in the event that the element could not
 *         be created.
 */
public static Element sketchToElement(Document document, Sketch sketch) {
    try {
        Element rootElement = document.createElement("easketch");
        Element header = document.createElement("header");
        // Add Header info to document
        DocumentInfo d = sketch.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);
        Map<String, String> connParams = sketch.getConnectionParams();
        for (String key : connParams.keySet()) {
            Element connParam = document.createElement("connectionParam");
            connParam.setAttribute("name", key);
            connParam.setAttribute("value", connParams.get(key));
            header.appendChild(connParam);
        }
        if (sketch.isSynced()) {
            header.appendChild(document.createElement("synchronized"));
        }
        rootElement.appendChild(header);
        Element entities = document.createElement("entities");
        // Loop through entities, add them to the document
        for (EntityNode currentEntity : sketch.getEntities()) {
            if (currentEntity == null) {
                continue;
            }
            Element thisEntity = document.createElement("entity");
            thisEntity.setAttribute("name", currentEntity.toString());
            thisEntity.setAttribute("x", currentEntity.getX() + "");
            thisEntity.setAttribute("y", currentEntity.getY() + "");
            entities.appendChild(thisEntity);
            // Loop through attributes, add them to the document
            for (EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> curAttribute : currentEntity.getEntityAttributes()) {
                Element attributeElmt = document.createElement("attribute");
                attributeElmt.setAttribute("name", curAttribute.getName());
                EasikType attType = curAttribute.getType();
                attributeElmt.setAttribute("attributeTypeClass", attType.getClass().getName());
                Map<String, String> typeAttribs = attType.attributes();
                for (String key : typeAttribs.keySet()) {
                    attributeElmt.setAttribute(key, typeAttribs.get(key));
                }
                thisEntity.appendChild(attributeElmt);
            }
        // We can't go through unique keys yet: they have to come
        // *after* edges
        }
        rootElement.appendChild(entities);
        Element edges = document.createElement("edges");
        for (SketchEdge currentEdge : sketch.getEdges().values()) {
            Element thisEdge = document.createElement("edge");
            thisEdge.setAttribute("id", currentEdge.getName());
            thisEdge.setAttribute("source", currentEdge.getSourceEntity().getName());
            thisEdge.setAttribute("target", currentEdge.getTargetEntity().getName());
            thisEdge.setAttribute("type", (currentEdge instanceof PartialEdge) ? "partial" : (currentEdge instanceof InjectiveEdge) ? "injective" : "normal");
            thisEdge.setAttribute("cascade", (currentEdge.getCascading() == SketchEdge.Cascade.SET_NULL) ? "set_null" : (currentEdge.getCascading() == SketchEdge.Cascade.CASCADE) ? "cascade" : "restrict");
            edges.appendChild(thisEdge);
        }
        rootElement.appendChild(edges);
        Element keys = document.createElement("keys");
        // Loop through unique keys for every node, add them to the document
        for (EntityNode currentEntity : sketch.getEntities()) {
            for (UniqueKey<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> curKey : currentEntity.getUniqueKeys()) {
                Element uniqueKeyElmt = document.createElement("uniqueKey");
                uniqueKeyElmt.setAttribute("name", curKey.getKeyName());
                uniqueKeyElmt.setAttribute("noderef", currentEntity.toString());
                keys.appendChild(uniqueKeyElmt);
                for (UniqueIndexable curElem : curKey.getElements()) {
                    if (curElem instanceof EntityAttribute) {
                        Element attributeElmt = document.createElement("attref");
                        attributeElmt.setAttribute("name", curElem.getName());
                        uniqueKeyElmt.appendChild(attributeElmt);
                    } else if (curElem instanceof SketchEdge) {
                        Element edgeElmt = document.createElement("edgekeyref");
                        edgeElmt.setAttribute("id", curElem.getName());
                        uniqueKeyElmt.appendChild(edgeElmt);
                    } else {
                        System.err.println("Unknown unique key item encountered: element '" + curElem.getName() + "' is neither EntityAttribute nor SketchEdge");
                    }
                }
            }
        }
        rootElement.appendChild(keys);
        Element constraints = document.createElement("constraints");
        // Now add the constraints
        for (ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> curConstraint : sketch.getConstraints().values()) {
            Element thisConstraint = document.createElement(curConstraint.getType());
            thisConstraint.setAttribute("x", curConstraint.getX() + "");
            thisConstraint.setAttribute("y", curConstraint.getY() + "");
            thisConstraint.setAttribute("isVisible", curConstraint.isVisible() ? "true" : "false");
            if (curConstraint instanceof LimitConstraint) {
                LimitConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> lc = (LimitConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) curConstraint;
                // TODO A better way? really long
                // cone - AB
                Element pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getCone().AB.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getCone().AB.getCoDomain().getName());
                for (SketchEdge edge : lc.getCone().AB.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // cone - BC
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getCone().BC.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getCone().BC.getCoDomain().getName());
                for (SketchEdge edge : lc.getCone().BC.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // cone - AC
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getCone().AC.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getCone().AC.getCoDomain().getName());
                for (SketchEdge edge : lc.getCone().AC.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // limit cone 1 - AB
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getLimitCone1().AB.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getLimitCone1().AB.getCoDomain().getName());
                for (SketchEdge edge : lc.getLimitCone1().AB.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // limit cone 1 - BC
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getLimitCone1().BC.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getLimitCone1().BC.getCoDomain().getName());
                for (SketchEdge edge : lc.getLimitCone1().BC.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // limit cone 1 - AC
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getLimitCone1().AC.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getLimitCone1().AC.getCoDomain().getName());
                for (SketchEdge edge : lc.getLimitCone1().AC.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // limit cone 2 - AB
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getLimitCone2().AB.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getLimitCone2().AB.getCoDomain().getName());
                for (SketchEdge edge : lc.getLimitCone2().AB.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // limit cone 2 - BC
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getLimitCone2().BC.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getLimitCone2().BC.getCoDomain().getName());
                for (SketchEdge edge : lc.getLimitCone2().BC.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // limit cone 2 - AC
                pathElem = document.createElement("path");
                pathElem.setAttribute("domain", lc.getLimitCone2().AC.getDomain().getName());
                pathElem.setAttribute("codomain", lc.getLimitCone2().AC.getCoDomain().getName());
                for (SketchEdge edge : lc.getLimitCone2().AC.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
                // Add constraint to constraints
                constraints.appendChild(thisConstraint);
                continue;
            }
            for (ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : curConstraint.getPaths()) {
                // Add pathref to constraint
                Element pathElem = document.createElement("path");
                pathElem.setAttribute("domain", path.getDomain().getName());
                pathElem.setAttribute("codomain", path.getCoDomain().getName());
                for (SketchEdge edge : path.getEdges()) {
                    Element edgeElem = document.createElement("edgeref");
                    edgeElem.setAttribute("id", edge.getName());
                    pathElem.appendChild(edgeElem);
                }
                thisConstraint.appendChild(pathElem);
            }
            // Add constraint to constraints
            constraints.appendChild(thisConstraint);
        }
        rootElement.appendChild(constraints);
        return rootElement;
    } catch (Exception e) {
        return null;
    }
}
Also used : LimitConstraint(easik.model.constraint.LimitConstraint) EntityAttribute(easik.model.attribute.EntityAttribute) Element(org.w3c.dom.Element) PartialEdge(easik.sketch.edge.PartialEdge) EntityNode(easik.sketch.vertex.EntityNode) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) SketchFrame(easik.ui.SketchFrame) InjectiveEdge(easik.sketch.edge.InjectiveEdge) SketchEdge(easik.sketch.edge.SketchEdge) Sketch(easik.sketch.Sketch) EasikType(easik.database.types.EasikType) DocumentInfo(easik.DocumentInfo) UniqueIndexable(easik.model.keys.UniqueIndexable)

Example 3 with DocumentInfo

use of easik.DocumentInfo in project fql by CategoricalData.

the class Overview method initializeOverview.

/**
 * When we initialise the overview, we flush out all the data concerning the
 * sketch itself.
 *
 * This methods serves as a "new overview" function.
 */
public void initializeOverview() {
    clearSelection();
    if (_sketchNodes != null) {
        for (SketchNode node : _sketchNodes.values()) {
            node.getFrame().dispose();
        }
    }
    if (_viewNodes != null) {
        for (ViewNode node : _viewNodes.values()) {
            node.getFrame().dispose();
        }
    }
    setFile(null);
    _sketchNodes = new HashMap<>();
    _viewNodes = new HashMap<>();
    _viewEdges = new HashMap<>();
    _docInfo = new DocumentInfo(_appFrame);
    if (_appFrame.getInfoTreeUI() != null) {
        _appFrame.setInfoTreeUI(new OverviewInfoTreeUI(_appFrame));
        _appFrame.getInfoTreeUI().refreshTree();
    }
    OverviewGraphModel model = new OverviewGraphModel(this);
    GraphLayoutCache glc = new GraphLayoutCache(model, new DefaultCellViewFactory());
    setModel(model);
    setGraphLayoutCache(glc);
}
Also used : DefaultCellViewFactory(org.jgraph.graph.DefaultCellViewFactory) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) ViewNode(easik.overview.vertex.ViewNode) OverviewGraphModel(easik.overview.util.graph.OverviewGraphModel) OverviewInfoTreeUI(easik.ui.tree.OverviewInfoTreeUI) SketchNode(easik.overview.vertex.SketchNode) DocumentInfo(easik.DocumentInfo)

Example 4 with DocumentInfo

use of easik.DocumentInfo in project fql by CategoricalData.

the class OverviewFileIO method overviewToXML.

/**
 * Converts an overview to an XML file. Returns the success of the save.
 *
 * @param outputFile
 *            The file we will output to
 * @param overview
 *            The sketch we're reading to
 * @return True if successful, false otherwise
 */
public static boolean overviewToXML(File outputFile, Overview overview) {
    Document overviewAsXML;
    try {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = docBuilderFactory.newDocumentBuilder();
        overviewAsXML = db.newDocument();
        Element rootElement = overviewAsXML.createElement("easketch_overview");
        Element header = overviewAsXML.createElement("header");
        Element sketches = overviewAsXML.createElement("sketches");
        Element views = overviewAsXML.createElement("views");
        // Add Header info to document
        DocumentInfo d = overview.getDocInfo();
        Element name = overviewAsXML.createElement("title");
        name.appendChild(overviewAsXML.createTextNode(d.getName()));
        header.appendChild(name);
        for (String aut : d.getAuthors()) {
            Element author = overviewAsXML.createElement("author");
            author.appendChild(overviewAsXML.createTextNode(aut));
            header.appendChild(author);
        }
        Element desc = overviewAsXML.createElement("description");
        desc.appendChild(overviewAsXML.createTextNode(d.getDesc()));
        header.appendChild(desc);
        Element creationDate = overviewAsXML.createElement("creationDate");
        creationDate.appendChild(overviewAsXML.createTextNode(EasikConstants.XML_DATETIME.format(d.getCreationDate())));
        header.appendChild(creationDate);
        Element modDate = overviewAsXML.createElement("lastModificationDate");
        modDate.appendChild(overviewAsXML.createTextNode(EasikConstants.XML_DATETIME.format(d.getModificationDate())));
        header.appendChild(modDate);
        // Loop through sketches, add them to the document
        for (SketchNode currentSketch : overview.getSketches()) {
            if (currentSketch != null) {
                Element thisSketch = SketchFileIO.sketchToElement(overviewAsXML, currentSketch.getFrame().getMModel());
                thisSketch.setAttribute("name", currentSketch.toString());
                thisSketch.setAttribute("x", currentSketch.getX() + "");
                thisSketch.setAttribute("y", currentSketch.getY() + "");
                Cascade c = currentSketch.getFrame().getMModel().getDefaultCascading();
                Cascade cp = currentSketch.getFrame().getMModel().getDefaultPartialCascading();
                thisSketch.setAttribute("cascade", (c == Cascade.CASCADE) ? "cascade" : "restrict");
                thisSketch.setAttribute("partial-cascade", (cp == Cascade.CASCADE) ? "cascade" : (cp == Cascade.RESTRICT) ? "restrict" : "set_null");
                sketches.appendChild(thisSketch);
            }
        }
        for (ViewNode currentView : overview.getViews()) {
            if (currentView != null) {
                Element thisView = viewToElement(overviewAsXML, currentView.getFrame().getMModel());
                thisView.setAttribute("name", currentView.toString());
                thisView.setAttribute("x", currentView.getX() + "");
                thisView.setAttribute("y", currentView.getY() + "");
                ViewDefinitionEdge thisViewEdge = overview.getViewEdge(currentView.getFrame().getMModel());
                thisView.setAttribute("viewDefinitionEdge", thisViewEdge.getName());
                thisView.setAttribute("on_sketch", thisViewEdge.getTargetNode().getName());
                views.appendChild(thisView);
            }
        }
        // Add root elements to document
        overviewAsXML.appendChild(rootElement);
        rootElement.appendChild(header);
        rootElement.appendChild(sketches);
        rootElement.appendChild(views);
    } catch (Exception e) {
        e.printStackTrace();
        overviewAsXML = null;
    }
    outputXMLtoFile(outputFile, overviewAsXML);
    return true;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) ViewNode(easik.overview.vertex.ViewNode) Document(org.w3c.dom.Document) SketchNode(easik.overview.vertex.SketchNode) ViewDefinitionEdge(easik.overview.edge.ViewDefinitionEdge) Cascade(easik.model.edge.ModelEdge.Cascade) DocumentInfo(easik.DocumentInfo)

Example 5 with DocumentInfo

use of easik.DocumentInfo 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

DocumentInfo (easik.DocumentInfo)5 SketchNode (easik.overview.vertex.SketchNode)3 ViewNode (easik.overview.vertex.ViewNode)3 Element (org.w3c.dom.Element)3 Cascade (easik.model.edge.ModelEdge.Cascade)2 ViewDefinitionEdge (easik.overview.edge.ViewDefinitionEdge)2 Sketch (easik.sketch.Sketch)2 SketchEdge (easik.sketch.edge.SketchEdge)2 SketchFrame (easik.ui.SketchFrame)2 InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)2 PartialViewEdge (easik.view.edge.PartialViewEdge)2 View_Edge (easik.view.edge.View_Edge)2 QueryNode (easik.view.vertex.QueryNode)2 EasikType (easik.database.types.EasikType)1 EntityAttribute (easik.model.attribute.EntityAttribute)1 LimitConstraint (easik.model.constraint.LimitConstraint)1 UniqueIndexable (easik.model.keys.UniqueIndexable)1 OverviewGraphModel (easik.overview.util.graph.OverviewGraphModel)1 InjectiveEdge (easik.sketch.edge.InjectiveEdge)1 PartialEdge (easik.sketch.edge.PartialEdge)1