Search in sources :

Example 61 with EntityNode

use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.

the class RenameInSketchAction method actionPerformed.

/**
 * Called when clicked upon, will rename an article.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    Sketch _ourSketch = _theFrame.getMModel();
    // If we're currently synced, let user cancel operation.
    if (_ourSketch.isSynced()) {
        if (JOptionPane.showConfirmDialog(_theFrame, "Warning: this sketch is currently synced with a db; continue and break synchronization?", "Caution!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
            return;
        }
    }
    Object[] currentSelection = _ourSketch.getSelectionCells();
    EntityNode nodeToRename = null;
    // If only one entity is selected, then we allow this. We will ignore
    // any
    // non-entities which might be selected
    String originalName = "";
    if ((currentSelection.length == 1) && (currentSelection[0] instanceof EntityNode)) {
        nodeToRename = (EntityNode) currentSelection[0];
        originalName = nodeToRename.getName();
    }
    if (nodeToRename == null) {
        JOptionPane.showMessageDialog(_ourSketch.getParent(), "Operation must be performed with a single entity selected", "Error", JOptionPane.ERROR_MESSAGE);
    } else {
        String s = (String) JOptionPane.showInputDialog(_ourSketch.getParent(), "New name:", "Rename entity", JOptionPane.QUESTION_MESSAGE, null, null, originalName);
        if (s != null) {
            s = s.trim();
            if (s.equals("")) {
                JOptionPane.showMessageDialog(_ourSketch.getParent(), "Entity name is empty", "Error", JOptionPane.ERROR_MESSAGE);
            } else if (_ourSketch.isNameUsed(s) && !nodeToRename.getName().equals(s)) {
                JOptionPane.showMessageDialog(_ourSketch.getParent(), "Entity name is already in use", "Error", JOptionPane.ERROR_MESSAGE);
            } else if (s.equals(originalName)) {
                // no need to do anything
                ;
            } else {
                // Push loading state
                _ourSketch.getStateManager().pushState(new LoadingState<>(_ourSketch));
                nodeToRename.setName(s);
                _theFrame.getInfoTreeUI().refreshTree();
                _ourSketch.getGraphLayoutCache().reload();
                // Pop state
                _ourSketch.getStateManager().popState();
                _ourSketch.repaint();
                _ourSketch.setDirty();
                _ourSketch.setSynced(false);
            }
        }
        _ourSketch.clearSelection();
    }
}
Also used : Sketch(easik.sketch.Sketch) EntityNode(easik.sketch.vertex.EntityNode)

Example 62 with EntityNode

use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.

the class ViewDeleteAction method actionPerformed.

/**
 * @param e
 *            The action event
 * @author Sarah van der Laan
 */
@Override
public void actionPerformed(ActionEvent e) {
    Object[] currentSelection = _ourView.getSelectionCells();
    QueryNode currNode = (QueryNode) currentSelection[0];
    String queryString = currNode.getQuery();
    String entityNodeName = null;
    // find corresponding entity node name
    String[] tokens = queryString.split("\\s+");
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i].equalsIgnoreCase("from")) {
            entityNodeName = tokens[i + 1];
        }
    }
    EntityNode _ourEntityNode = null;
    // set corresponding node in order to use
    for (EntityNode node : _ourSketch.getEntities()) {
        if (node.getName().equalsIgnoreCase(entityNodeName)) {
            _ourEntityNode = node;
        }
    }
    if (!_ourSketch.hasDatabase()) {
        JOptionPane.showMessageDialog(null, "Not currently connected to a database.");
        return;
    } else {
        UpdateMonitor um = _ourSketch.getDatabase().newUpdateMonitor();
        if (um == null) {
            JOptionPane.showMessageDialog(null, "Could not perform update: problem accessing db driver");
            return;
        }
        if (_ourEntityNode != null)
            um.deleteFrom(_ourEntityNode);
    }
}
Also used : UpdateMonitor(easik.ui.datamanip.UpdateMonitor) QueryNode(easik.view.vertex.QueryNode) EntityNode(easik.sketch.vertex.EntityNode)

Aggregations

EntityNode (easik.sketch.vertex.EntityNode)62 SketchEdge (easik.sketch.edge.SketchEdge)45 Sketch (easik.sketch.Sketch)30 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)30 SketchFrame (easik.ui.SketchFrame)29 LinkedList (java.util.LinkedList)21 LimitConstraint (easik.model.constraint.LimitConstraint)16 ProductConstraint (easik.model.constraint.ProductConstraint)15 PullbackConstraint (easik.model.constraint.PullbackConstraint)15 SumConstraint (easik.model.constraint.SumConstraint)15 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)12 ModelConstraint (easik.model.constraint.ModelConstraint)12 ArrayList (java.util.ArrayList)12 ModelPath (easik.model.path.ModelPath)8 InjectiveEdge (easik.sketch.edge.InjectiveEdge)7 UpdateMonitor (easik.ui.datamanip.UpdateMonitor)6 SQLException (java.sql.SQLException)6 LinkedHashSet (java.util.LinkedHashSet)6 QueryNode (easik.view.vertex.QueryNode)5 XSDAnnotation (easik.xml.xsd.nodes.XSDAnnotation)5