Search in sources :

Example 16 with ViewNode

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

the class DeleteFromSketchAction method actionPerformed.

/**
 * When the action is performed, selection is deleted if possible. Error is
 * displayed if no graph item is selected.
 *
 * @param e
 *            The action event
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void actionPerformed(ActionEvent e) {
    Sketch _ourSketch = _theFrame.getMModel();
    // The confirm delete message. If we're currently synced with a db, add
    // that to the message;
    String confirm = _ourSketch.isSynced() ? "Warning: this sketch is currently synced with a db; delete and break synchronization?" : "Are you sure you want to delete selected item(s)?";
    if (JOptionPane.showConfirmDialog(_theFrame, confirm, "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
        return;
    }
    Object[] currentSelection = _ourSketch.getSelectionCells();
    if (currentSelection.length == 0) {
        JOptionPane.showMessageDialog(_theFrame, "Operation must be performed with something selected", "Error", JOptionPane.ERROR_MESSAGE);
    } else {
        _ourSketch.getGraphModel().beginUpdate();
        // First, delete any constraints:
        for (Object o : currentSelection) {
            if (o instanceof ModelConstraint) {
                _ourSketch.removeConstraint((ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) o);
                for (ViewNode v : _ourSketch.getViews()) {
                    if (v.getMModel().getConstraints().containsKey(((ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) o).getID())) {
                        v.getMModel().removeConstraint(((ModelConstraint) o));
                    }
                }
            }
        }
        // THEN any edges:
        for (Object o : currentSelection) {
            if (o instanceof SketchEdge) {
                for (ViewNode v : _theFrame.getMModel().getViews()) {
                    if (v.getMModel().getEdges().containsKey(((SketchEdge) o).getName())) {
                        // put up a warning cause this exists in a View
                        if (JOptionPane.showConfirmDialog(_theFrame, "SketchEdge " + ((SketchEdge) o).getName() + " exists in a View. Continue and delete in view as well?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
                            return;
                        }
                        // if we want to proceed and delete it...
                        v.getMModel().removeEdge(v.getMModel().getEdges().get(((SketchEdge) o).getName()));
                    }
                }
                _ourSketch.removeEdge((SketchEdge) o);
            }
        }
        // Then finally, any entities.
        for (Object o : currentSelection) {
            if (o instanceof EntityNode) {
                for (ViewNode v : _theFrame.getMModel().getViews()) {
                    if (v.getMModel().getEntityNodePairs().containsKey((o))) {
                        // put up a warning cause this exists in a View
                        if (JOptionPane.showConfirmDialog(_theFrame, "EntityNode " + ((EntityNode) o).getName() + " is being queried by a View. Continue and delete in view as well?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
                            return;
                        }
                        // if we want to proceed and delete it...
                        v.getMModel().removeNode(v.getMModel().getEntityNodePairs().get(o));
                    }
                }
                _ourSketch.removeNode((EntityNode) o);
            }
        }
        _ourSketch.setDirty();
        _ourSketch.getGraphModel().endUpdate();
        _ourSketch.setSynced(false);
    }
    // Clear selection after things have been deleted
    _ourSketch.clearSelection();
}
Also used : SketchFrame(easik.ui.SketchFrame) ModelConstraint(easik.model.constraint.ModelConstraint) SketchEdge(easik.sketch.edge.SketchEdge) Sketch(easik.sketch.Sketch) ViewNode(easik.overview.vertex.ViewNode) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode)

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