use of gov.sandia.n2a.ui.eq.tree.NodeEquation in project n2a by frothga.
the class AddEquation method create.
public static NodeBase create(List<String> path, int equationCount, int index, String name, String combinerAfter, String value, boolean multi) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
// Update the database
String parentValueBefore = parent.source.get();
Variable.ParsedValue parentPiecesBefore = new Variable.ParsedValue(parentValueBefore);
// The minimum number of equations is 2. There should never be exactly 1 equation, because that is single-line form, which should have no child equations at all.
if (// We are about to switch from single-line form to multi-conditional, so make a tree node for the existing equation.
equationCount == 0) {
MPart equation = (MPart) parent.source.set(parentPiecesBefore.expression, "@" + parentPiecesBefore.condition);
model.insertNodeIntoUnfiltered(new NodeEquation(equation), parent, 0);
}
MPart createdPart = (MPart) parent.source.set(value == null ? "0" : value, name);
boolean parentChanged = false;
if (!combinerAfter.equals(parentValueBefore)) {
parent.source.set(combinerAfter);
parentChanged = true;
}
// Update the GUI
NodeBase createdNode = parent.child(name);
boolean alreadyExists = createdNode != null;
if (!alreadyExists)
createdNode = new NodeEquation(createdPart);
if (value == null)
createdNode.setUserObject("");
if (!alreadyExists)
model.insertNodeIntoUnfiltered(createdNode, parent, index);
if (parentChanged) {
parent.setUserObject();
NodeBase grandparent = (NodeBase) parent.getParent();
grandparent.invalidateColumns(model);
}
if (// create was merged with change name/value
value != null) {
parent.invalidateColumns(null);
TreeNode[] createdPath = createdNode.getPath();
pet.updateVisibility(createdPath, -2, !multi);
if (multi)
pet.tree.addSelectionPath(new TreePath(createdPath));
parent.allNodesChanged(model);
pet.animate();
}
return createdNode;
}
use of gov.sandia.n2a.ui.eq.tree.NodeEquation in project n2a by frothga.
the class ChangeEquation method apply.
public void apply(String nameBefore, String nameAfter, String combinerAfter, String valueAfter, boolean multi, boolean multiLast) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodeBase nodeBefore = parent.child(nameBefore);
if (nodeBefore == null)
throw new CannotRedoException();
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
NodeBase nodeAfter;
if (nameBefore.equals(nameAfter)) {
nodeAfter = nodeBefore;
nodeAfter.source.set(valueAfter);
} else {
// Update the database
MPart mparent = parent.source;
MPart newPart = (MPart) mparent.set(valueAfter, nameAfter);
mparent.clear(nameBefore);
MPart oldPart = (MPart) mparent.child(nameBefore);
// Update GUI
nodeAfter = parent.child(nameAfter);
if (oldPart == null) {
if (nodeAfter == null) {
nodeAfter = nodeBefore;
nodeAfter.source = newPart;
} else {
model.removeNodeFromParent(nodeBefore);
}
} else {
if (nodeAfter == null) {
int index = parent.getIndex(nodeBefore);
nodeAfter = new NodeEquation(newPart);
model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
}
if (nodeBefore.visible())
model.nodeChanged(nodeBefore);
else
parent.hide(nodeBefore, model);
}
}
if (!parent.source.get().equals(combinerAfter)) {
parent.source.set(combinerAfter);
parent.setUserObject();
NodeBase grandparent = (NodeBase) parent.getParent();
grandparent.invalidateColumns(model);
}
nodeAfter.setUserObject();
parent.invalidateColumns(null);
TreeNode[] afterPath = nodeAfter.getPath();
boolean killed = valueAfter.isEmpty();
boolean setSelection;
if (// Revoke, which hides the node, so like delete.
killed)
// Revoke, which hides the node, so like delete.
setSelection = !multi || multiLast;
else
setSelection = !multi;
pet.updateVisibility(afterPath, -2, setSelection);
if (multi && !killed)
pet.tree.addSelectionPath(new TreePath(afterPath));
parent.allNodesChanged(model);
pet.animate();
}
Aggregations