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);
}
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);
}
}
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]);
}
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);
}
}
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);
}
Aggregations