Search in sources :

Example 1 with SketchNode

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

the class DeleteFromOverviewFromTreeAction method actionPerformed.

/**
 * Called when clicked upon, will delete entity.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    // If there is nothing seleceted then just do nothing
    if (_theFrame.getInfoTreeUI().getInfoTree().isSelectionEmpty()) {
        return;
    }
    int op = JOptionPane.showConfirmDialog(_theFrame, "Are you sure you want to delete the selected items?", "Confirm Deletion", JOptionPane.YES_NO_OPTION);
    if (op == JOptionPane.YES_OPTION) {
        // Get currently selected object
        DefaultMutableTreeNode curSelected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree().getSelectionPath().getLastPathComponent();
        if (curSelected.getUserObject() instanceof SketchNode) {
            _theFrame.getOverview().removeSketch((SketchNode) curSelected.getUserObject());
            _theFrame.getOverview().setDirty(true);
        } else {
            _theFrame.getOverview().removeView((ViewNode) curSelected.getUserObject());
            _theFrame.getOverview().setDirty(true);
        }
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SketchNode(easik.overview.vertex.SketchNode)

Example 2 with SketchNode

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

the class SketchExportAction method actionPerformed.

/**
 * Display a dialog prompting the user for the name under which to save the
 * current sketch.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(final ActionEvent e) {
    final Sketch sketch;
    if (_theFrame instanceof SketchFrame) {
        sketch = ((SketchFrame) _theFrame).getMModel();
    } else {
        final Object[] currentSelection = ((ApplicationFrame) _theFrame).getOverview().getSelectionCells();
        if (!((currentSelection.length == 1) && (currentSelection[0] instanceof SketchNode))) {
            System.err.println("Sketch export via overview popup should only be enabled when " + "selection size is 1, and it is a sketch node");
            return;
        }
        sketch = ((SketchNode) currentSelection[0]).getFrame().getMModel();
    }
    final File selFile = FileChooser.saveFile("Save EASIK Sketch", FileFilter.EASIK_SKETCH, "sketch");
    if (selFile != null) {
        sketch.getDocInfo().updateModificationDate();
        sketch.saveToXML(selFile);
    }
}
Also used : SketchFrame(easik.ui.SketchFrame) Sketch(easik.sketch.Sketch) SketchNode(easik.overview.vertex.SketchNode) File(java.io.File)

Example 3 with SketchNode

use of easik.overview.vertex.SketchNode 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 4 with SketchNode

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

the class ImportSketchAction method actionPerformed0.

public void actionPerformed0(File selFile) {
    Point p = (_newPoint != null) ? _newPoint : _theOverview.getNewSketchPosition(10);
    _theOverview.getFrame().getInfoTreeUI().storeExpansion();
    SketchNode newNode = _theOverview.addNewSketch(_theOverview.getNewName("ImportedSketch0"), p.getX(), p.getY());
    _theOverview.getFrame().getInfoTreeUI().storeExpansion();
    SketchFrame newFrame = newNode.getFrame();
    Sketch sk = newFrame.getMModel();
    if (!sk.loadFromXML(selFile)) {
        return;
    }
    newNode.updateName();
    sk.updateThumb();
    _theOverview.getFrame().getInfoTreeUI().revertExpansion();
    _theOverview.setDirty(true);
    // Updates gui
    _theOverview.refresh();
}
Also used : SketchFrame(easik.ui.SketchFrame) Sketch(easik.sketch.Sketch) Point(java.awt.Point) SketchNode(easik.overview.vertex.SketchNode)

Example 5 with SketchNode

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

Aggregations

SketchNode (easik.overview.vertex.SketchNode)18 ViewNode (easik.overview.vertex.ViewNode)11 ViewDefinitionEdge (easik.overview.edge.ViewDefinitionEdge)4 Sketch (easik.sketch.Sketch)4 SketchFrame (easik.ui.SketchFrame)4 DocumentInfo (easik.DocumentInfo)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 Cascade (easik.model.edge.ModelEdge.Cascade)2 OverviewVertex (easik.overview.vertex.OverviewVertex)2 Component (java.awt.Component)2 Point (java.awt.Point)2 JMenuItem (javax.swing.JMenuItem)2 AttributeMap (org.jgraph.graph.AttributeMap)2 OverviewGraphModel (easik.overview.util.graph.OverviewGraphModel)1 SketchEdge (easik.sketch.edge.SketchEdge)1 ViewFrame (easik.ui.ViewFrame)1 AboutAction (easik.ui.menu.AboutAction)1 ExportDatabaseAction (easik.ui.menu.ExportDatabaseAction)1 FileNewOverviewAction (easik.ui.menu.FileNewOverviewAction)1 FileOpenAction (easik.ui.menu.FileOpenAction)1