use of easik.model.states.LoadingState in project fql by CategoricalData.
the class RenameEntityAction method actionPerformed.
/**
* Called when clicked upon, will rename an article.
*
* @param e
* The action event
*/
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) {
// If there is nothing seleceted then just do nothing
if (_theFrame.getInfoTreeUI().getInfoTree().isSelectionEmpty()) {
return;
}
// Get M object
M _ourModel = _theFrame.getMModel();
// cancel operation
if (_ourModel.isSynced()) {
int choice = JOptionPane.showConfirmDialog(_theFrame, "Warning: this sketch is currently synced with a db; continue and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (choice == JOptionPane.CANCEL_OPTION) {
return;
}
}
// Get currently selected object
DefaultMutableTreeNode curSelected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree().getSelectionPath().getLastPathComponent();
N nodeToRename;
String originalName = "";
// Check what is currently selected
if (curSelected instanceof ModelVertex) {
nodeToRename = (N) curSelected;
originalName = nodeToRename.getName();
} else {
return;
}
String s = (String) JOptionPane.showInputDialog(_ourModel.getParent(), "New name:", "Rename", JOptionPane.QUESTION_MESSAGE, null, null, originalName);
if (s != null) {
s = s.trim();
if (s.equals("")) {
JOptionPane.showMessageDialog(_theFrame, "Entity name is empty", "Error", JOptionPane.ERROR_MESSAGE);
} else if (_ourModel.isNameUsed(s)) {
JOptionPane.showMessageDialog(_theFrame, "Entity name is already in use", "Error", JOptionPane.ERROR_MESSAGE);
} else {
// Push loading state
_ourModel.getStateManager().pushState(new LoadingState<>(_ourModel));
nodeToRename.setName(s);
_theFrame.getInfoTreeUI().refreshTree();
_theFrame.getMModel().getGraphLayoutCache().reload();
// Pop state
_ourModel.getStateManager().popState();
_ourModel.repaint();
_ourModel.setDirty();
_ourModel.setSynced(false);
}
}
_ourModel.clearSelection();
}
Aggregations