Search in sources :

Example 1 with ViewDefinitionEdge

use of easik.overview.edge.ViewDefinitionEdge 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 ViewDefinitionEdge

use of easik.overview.edge.ViewDefinitionEdge in project fql by CategoricalData.

the class Overview method addNewView.

/**
 * Add a view to a given sketch node
 *
 * @param sketch
 * @param viewName
 *            The name of the new view. Assumes no naming naming conflict
 * @return The new view node
 */
public ViewNode addNewView(SketchNode sketch, String viewName) {
    Point newP = getNewViewPosition(sketch.getX(), sketch.getY(), 10);
    ViewFrame newFrame = new ViewFrame(this, sketch.getFrame().getMModel());
    ViewNode newNode = new ViewNode(viewName, (int) newP.getX(), (int) newP.getY(), newFrame);
    sketch.getFrame().getMModel().addView(newNode);
    // Add our ViewNode
    addVertex(newNode);
    // Add edge to out connected sketch
    addViewEdge(new ViewDefinitionEdge(newNode, sketch, getNewEdgeName()));
    return newNode;
}
Also used : ViewFrame(easik.ui.ViewFrame) ViewNode(easik.overview.vertex.ViewNode) Point(java.awt.Point) ViewDefinitionEdge(easik.overview.edge.ViewDefinitionEdge)

Example 3 with ViewDefinitionEdge

use of easik.overview.edge.ViewDefinitionEdge in project fql by CategoricalData.

the class Overview method removeView.

/**
 * Remove view and it's view edge from the overview.
 *
 * @param remove
 */
public void removeView(ViewNode remove) {
    // remove from sketch
    View toRemove = remove.getFrame().getMModel();
    toRemove.getSketch().removeView(toRemove.getName());
    for (ViewDefinitionEdge edge : _viewEdges.values()) {
        if (edge.getSourceNode().getName().equals(toRemove.getName())) {
            removeViewEdge(edge);
            break;
        }
    }
    // remove from overview graph
    _viewNodes.remove(toRemove.getName());
    getGraphLayoutCache().remove(new Object[] { remove });
    // remove from info tree
    _appFrame.getInfoTreeUI().removeView(toRemove.getFrame().getNode());
    // dispose of the frame
    remove.getFrame().dispose();
}
Also used : View(easik.view.View) ViewDefinitionEdge(easik.overview.edge.ViewDefinitionEdge)

Example 4 with ViewDefinitionEdge

use of easik.overview.edge.ViewDefinitionEdge in project fql by CategoricalData.

the class Overview method initializeFromData.

/**
 * Used to initialise a new sketch based on provided data (usually from the
 * Sketch loading methods).
 *
 * @param sketchNodes
 *            A Map of all of the sketches in the overview
 * @param viewNodes
 * @param viewDefinitionEdges
 * @param docInfo
 *            The document information to be stored along with this overview
 */
public void initializeFromData(Map<String, SketchNode> sketchNodes, Map<String, ViewNode> viewNodes, Map<String, ViewDefinitionEdge> viewDefinitionEdges, DocumentInfo docInfo) {
    initializeOverview();
    _sketchNodes = new HashMap<>();
    _viewNodes = new HashMap<>();
    _viewEdges = new HashMap<>();
    _docInfo = docInfo;
    for (SketchNode node : sketchNodes.values()) {
        if (node != null) {
            addVertex(node);
        }
    }
    for (ViewNode node : viewNodes.values()) {
        if (node != null) {
            addVertex(node);
        }
    }
    for (ViewDefinitionEdge edge : viewDefinitionEdges.values()) {
        if (edge != null) {
            addViewEdge(edge);
        }
    }
    refresh();
}
Also used : ViewNode(easik.overview.vertex.ViewNode) SketchNode(easik.overview.vertex.SketchNode) ViewDefinitionEdge(easik.overview.edge.ViewDefinitionEdge)

Example 5 with ViewDefinitionEdge

use of easik.overview.edge.ViewDefinitionEdge 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)

Aggregations

ViewDefinitionEdge (easik.overview.edge.ViewDefinitionEdge)6 ViewNode (easik.overview.vertex.ViewNode)5 SketchNode (easik.overview.vertex.SketchNode)4 DocumentInfo (easik.DocumentInfo)2 Cascade (easik.model.edge.ModelEdge.Cascade)2 ViewFrame (easik.ui.ViewFrame)2 Sketch (easik.sketch.Sketch)1 SketchEdge (easik.sketch.edge.SketchEdge)1 SketchFrame (easik.ui.SketchFrame)1 View (easik.view.View)1 InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)1 NormalViewEdge (easik.view.edge.NormalViewEdge)1 PartialViewEdge (easik.view.edge.PartialViewEdge)1 View_Edge (easik.view.edge.View_Edge)1 QueryException (easik.view.util.QueryException)1 QueryNode (easik.view.vertex.QueryNode)1 Color (java.awt.Color)1 Point (java.awt.Point)1 Border (javax.swing.border.Border)1 LineBorder (javax.swing.border.LineBorder)1