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