Search in sources :

Example 1 with ViewNode

use of easik.overview.vertex.ViewNode in project fql by CategoricalData.

the class RenameInOverviewAction method actionPerformed.

/**
 * Called when clicked upon, will rename an article.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    Object[] currentSelection = _theOverview.getSelectionCells();
    if (!((currentSelection.length == 1) && (currentSelection[0] instanceof OverviewVertex))) {
        return;
    }
    OverviewVertex nodeToRename = (OverviewVertex) currentSelection[0];
    String originalName = nodeToRename.getName();
    if (nodeToRename instanceof SketchNode) {
        if (((SketchNode) nodeToRename).getMModel().isSynced() && (JOptionPane.showConfirmDialog(_theOverview.getFrame(), "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;
        }
    } else if (nodeToRename instanceof ViewNode) {
        if (((ViewNode) nodeToRename).getMModel().getSketch().isSynced() && (JOptionPane.showConfirmDialog(_theOverview.getFrame(), "Warning: this view is of a sketch that is currently synced with a db; continue and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION)) {
            return;
        }
    } else {
        return;
    }
    String s = (String) JOptionPane.showInputDialog(_theOverview.getParent(), "New name:", "Rename", JOptionPane.QUESTION_MESSAGE, null, null, originalName);
    if (s != null) {
        s = s.trim();
        if (s.equals("")) {
            JOptionPane.showMessageDialog(_theOverview.getParent(), "Sketch name is empty", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (nodeToRename instanceof SketchNode) {
            if (_theOverview.isNameUsed(s) && !nodeToRename.getName().equals(s)) {
                JOptionPane.showMessageDialog(_theOverview.getParent(), "Sketch name is already in use", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
        } else if (nodeToRename instanceof ViewNode) {
            if (_theOverview.isNameUsed(s) && !nodeToRename.getName().equals(s)) {
                JOptionPane.showMessageDialog(_theOverview.getParent(), "View name is already in use", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
        if (!s.equals(originalName)) {
            nodeToRename.setName(s);
            _theOverview.getFrame().getInfoTreeUI().storeExpansion();
            _theOverview.getFrame().getInfoTreeUI().refreshTree();
            _theOverview.getGraphLayoutCache().reload();
            _theOverview.getFrame().getInfoTreeUI().revertExpansion();
            if (nodeToRename instanceof SketchNode) {
                ((SketchNode) nodeToRename).getFrame().getMModel().setDirty();
                ((SketchNode) nodeToRename).getFrame().getMModel().setSynced(false);
            } else if (nodeToRename instanceof ViewNode) {
                ((ViewNode) nodeToRename).getFrame().getMModel().setDirty();
                ((ViewNode) nodeToRename).getFrame().getMModel().getSketch().setSynced(false);
            } else {
                _theOverview.setDirty(true);
            }
            _theOverview.repaint();
        }
    }
    _theOverview.clearSelection();
}
Also used : ViewNode(easik.overview.vertex.ViewNode) OverviewVertex(easik.overview.vertex.OverviewVertex) SketchNode(easik.overview.vertex.SketchNode)

Example 2 with ViewNode

use of easik.overview.vertex.ViewNode 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 ViewNode

use of easik.overview.vertex.ViewNode 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 ViewNode

use of easik.overview.vertex.ViewNode 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 5 with ViewNode

use of easik.overview.vertex.ViewNode in project fql by CategoricalData.

the class Overview method removeSketch.

/**
 * Removes a sketch from both the tree representation, and the graphical.
 *
 * @param toRemove
 *            The entity about to be removed
 */
public void removeSketch(SketchNode toRemove) {
    ArrayList<ViewNode> removeViews = new ArrayList<>(toRemove.getFrame().getMModel().getViews());
    for (ViewNode v : removeViews) {
        removeView(v);
    }
    // dispose of the sketch's frame
    toRemove.getFrame().dispose();
    _sketchNodes.remove(toRemove.toString());
    getGraphLayoutCache().remove(new Object[] { toRemove });
    _appFrame.getInfoTreeUI().removeSketch(toRemove);
}
Also used : ArrayList(java.util.ArrayList) ViewNode(easik.overview.vertex.ViewNode)

Aggregations

ViewNode (easik.overview.vertex.ViewNode)16 SketchNode (easik.overview.vertex.SketchNode)11 ViewDefinitionEdge (easik.overview.edge.ViewDefinitionEdge)5 DocumentInfo (easik.DocumentInfo)3 Sketch (easik.sketch.Sketch)3 Cascade (easik.model.edge.ModelEdge.Cascade)2 OverviewVertex (easik.overview.vertex.OverviewVertex)2 SketchEdge (easik.sketch.edge.SketchEdge)2 SketchFrame (easik.ui.SketchFrame)2 ViewFrame (easik.ui.ViewFrame)2 Point (java.awt.Point)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 AttributeMap (org.jgraph.graph.AttributeMap)2 ModelConstraint (easik.model.constraint.ModelConstraint)1 OverviewGraphModel (easik.overview.util.graph.OverviewGraphModel)1 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)1 EntityNode (easik.sketch.vertex.EntityNode)1 OverviewInfoTreeUI (easik.ui.tree.OverviewInfoTreeUI)1 View (easik.view.View)1 InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)1