Search in sources :

Example 1 with View_Edge

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

the class ViewFrame method setPopMenu.

/**
 * Figures out which popup menu should be displayed, based on the editing
 * mode of the sketch on which this is a view. Ensures the the appropriate
 * menu items are enabled based on the current selection.
 *
 * @return The popup menu that should be displayed. (i.e. the editing popup
 *         if the sketch of which this view in on is in edit mode and the
 *         manipulate option otherwise.)
 */
public JPopupMenu setPopMenu() {
    Object[] currentSelection = _ourView.getSelectionCells();
    _ViewAddPopItem.setToolTipText("Add a row to the view table refrenced by this query node");
    if (_ourView.getSketch().getFrame().getMode() == SketchFrame.Mode.MANIPULATE) {
        boolean enableViewQuery = currentSelection.length == 1;
        _ViewQueryPopItem.setEnabled(enableViewQuery);
        // Disable all elements
        for (final Component c : _manipModePopMenu.getComponents()) {
            c.setEnabled(false);
        }
        if (currentSelection.length == 0) {
            return null;
        }
        final Object selected = currentSelection[0];
        if (selected instanceof QueryNode) {
            setQueryPopItems((QueryNode) selected);
            return _manipModePopMenu;
        }
        return null;
    }
    // Disable all elements
    for (final Component c : _editModePopMenu.getComponents()) {
        c.setEnabled(false);
    }
    if (currentSelection.length == 0) {
        _AddQueryNodePopItem.setEnabled(true);
        return _editModePopMenu;
    }
    // check for mixed selection
    final Object selected1 = currentSelection[0];
    for (final Object o : currentSelection) {
        if (o.getClass() != selected1.getClass()) {
            // Disable all elements
            for (final Component c : _editModePopMenu.getComponents()) {
                c.setEnabled(false);
            }
            // We always want delete
            _DeletePopItem.setEnabled(true);
            return _editModePopMenu;
        }
    }
    if (selected1 instanceof QueryNode) {
        _DefineQueryNodePopItem.setEnabled(true);
        _DeletePopItem.setEnabled(true);
        return _editModePopMenu;
    } else if (selected1 instanceof View_Edge) {
        return null;
    }
    return null;
}
Also used : QueryNode(easik.view.vertex.QueryNode) Component(java.awt.Component) View_Edge(easik.view.edge.View_Edge)

Example 2 with View_Edge

use of easik.view.edge.View_Edge 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 3 with View_Edge

use of easik.view.edge.View_Edge 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 4 with View_Edge

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

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

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