Search in sources :

Example 1 with UpdateMonitor

use of easik.ui.datamanip.UpdateMonitor in project fql by CategoricalData.

the class UpdateRowAction method actionPerformed.

/**
 * Triggers JDBCUpdateMonitor to update a row in the selected table
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    Object[] currentSelection = _theSketch.getSelectionCells();
    if (!(currentSelection[0] instanceof EntityNode)) {
        return;
    }
    EntityNode node = (EntityNode) currentSelection[0];
    UpdateMonitor um = _theSketch.getDatabase().newUpdateMonitor();
    if (um == null) {
        JOptionPane.showMessageDialog(null, "Could not perform update: problem accessing db driver");
        return;
    }
    um.updateRow(node);
}
Also used : UpdateMonitor(easik.ui.datamanip.UpdateMonitor) EntityNode(easik.sketch.vertex.EntityNode)

Example 2 with UpdateMonitor

use of easik.ui.datamanip.UpdateMonitor in project fql by CategoricalData.

the class ViewUpdateAction 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.updateRow(_ourEntityNode);
    }
}
Also used : UpdateMonitor(easik.ui.datamanip.UpdateMonitor) QueryNode(easik.view.vertex.QueryNode) EntityNode(easik.sketch.vertex.EntityNode)

Example 3 with UpdateMonitor

use of easik.ui.datamanip.UpdateMonitor in project fql by CategoricalData.

the class AddRowAction method actionPerformed.

/**
 * Checks that our sketch has a db driver, and sends the selected entity
 * node off to the sketch's update monitor.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    Object[] currentSelection = _theSketch.getSelectionCells();
    if (!(currentSelection[0] instanceof EntityNode) || !_theSketch.hasDatabase()) {
        return;
    }
    UpdateMonitor um = _theSketch.getDatabase().newUpdateMonitor();
    um.insert((EntityNode) currentSelection[0]);
}
Also used : UpdateMonitor(easik.ui.datamanip.UpdateMonitor) EntityNode(easik.sketch.vertex.EntityNode)

Example 4 with UpdateMonitor

use of easik.ui.datamanip.UpdateMonitor in project fql by CategoricalData.

the class ViewAddAction 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];
    EntityNode _ourEntityNode = currNode.getQueriedEntity();
    if (!_ourSketch.hasDatabase()) {
        JOptionPane.showMessageDialog(null, "Not currently connected to a database.");
        return;
    } else {
        // final JDBCDriver dbd = _ourSketch.getDatabase().getJDBCDriver();
        UpdateMonitor um = _ourSketch.getDatabase().newUpdateMonitor();
        if (um == null) {
            JOptionPane.showMessageDialog(null, "Could not perform update: problem accessing db driver");
            return;
        }
        if (_ourEntityNode != null)
            um.insert(_ourEntityNode);
    }
}
Also used : UpdateMonitor(easik.ui.datamanip.UpdateMonitor) QueryNode(easik.view.vertex.QueryNode) EntityNode(easik.sketch.vertex.EntityNode)

Example 5 with UpdateMonitor

use of easik.ui.datamanip.UpdateMonitor in project fql by CategoricalData.

the class DeleteRowAction method actionPerformed.

/**
 * Create the new entity and set up its name
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    Object[] currentSelection = _theSketch.getSelectionCells();
    Object selected = currentSelection[0];
    if (!(selected instanceof EntityNode)) {
        System.err.println("Action only available on entity nodes: easik.ui.menu.popup.DeleteRowAction");
        return;
    }
    EntityNode table = (EntityNode) selected;
    ArrayList<String> domains = new ArrayList<>();
    // warn user about possible cascades
    for (SketchEdge sk : _theSketch.getEdges().values()) {
        if (sk.getTargetEntity().getName().equals(table.getName()) && sk.getCascading() == Cascade.CASCADE) {
            domains.add(sk.getSourceEntity().getName());
        }
    }
    if (domains.size() > 0) {
        if (JOptionPane.showConfirmDialog(_theSketch, "Warning: Rows in this table may have foreign rows in " + domains.toString() + " which will be deleted on cascade", "Warning", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
            return;
        }
    }
    UpdateMonitor um = _theSketch.getDatabase().newUpdateMonitor();
    um.deleteFrom(table);
}
Also used : SketchEdge(easik.sketch.edge.SketchEdge) UpdateMonitor(easik.ui.datamanip.UpdateMonitor) ArrayList(java.util.ArrayList) EntityNode(easik.sketch.vertex.EntityNode)

Aggregations

EntityNode (easik.sketch.vertex.EntityNode)6 UpdateMonitor (easik.ui.datamanip.UpdateMonitor)6 QueryNode (easik.view.vertex.QueryNode)3 SketchEdge (easik.sketch.edge.SketchEdge)1 ArrayList (java.util.ArrayList)1