use of gov.sandia.n2a.ui.eq.undo.ChangeEquation in project n2a by frothga.
the class NodeEquation method applyEdit.
@Override
public void applyEdit(JTree tree) {
String input = (String) getUserObject();
if (input.isEmpty()) {
boolean canceled = MainFrame.instance.undoManager.getPresentationName().equals("AddEquation");
delete(canceled);
return;
}
// There are three possible outcomes of the edit:
// 1) Nothing changed
// 2) The name was not allowed to change
// 3) Arbitrary change
Variable.ParsedValue piecesBefore = new Variable.ParsedValue(source.get() + source.key());
Variable.ParsedValue piecesAfter = new Variable.ParsedValue(input);
NodeVariable parent = (NodeVariable) getParent();
if (!piecesBefore.condition.equals(piecesAfter.condition)) {
MPart partAfter = (MPart) parent.source.child("@" + piecesAfter.condition);
if (// Can't overwrite another top-document node, unless it is a revocation ...
partAfter != null && partAfter.isFromTopDocument()) {
String value = partAfter.get();
boolean revoked = value.isEmpty() || value.startsWith("$kill");
// reject key change
if (!revoked)
piecesAfter.condition = piecesBefore.condition;
}
}
if (piecesBefore.equals(piecesAfter)) {
setUserObject();
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
model.nodeChanged(this);
return;
}
// The fact that we are modifying an existing equation node indicates that the variable (parent) should only contain a combiner.
piecesBefore.combiner = parent.source.get();
if (piecesAfter.combiner.isEmpty())
piecesAfter.combiner = piecesBefore.combiner;
MainFrame.instance.undoManager.apply(new ChangeEquation(parent, piecesBefore.condition, piecesBefore.combiner, piecesBefore.expression, piecesAfter.condition, piecesAfter.combiner, piecesAfter.expression));
}
Aggregations