use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class AddEquation method destroy.
public static void destroy(List<String> path, int equationCount, boolean canceled, String name, String combinerBefore) {
// Retrieve created node
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
NodeBase createdNode = parent.child(name);
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
FontMetrics fm = createdNode.getFontMetrics(tree);
TreeNode[] createdPath = createdNode.getPath();
int index = parent.getIndexFiltered(createdNode);
if (canceled)
index--;
// Update database
MPart mparent = parent.source;
mparent.clear(name);
boolean parentChanged = false;
if (!mparent.get().equals(combinerBefore)) {
// This value may be replaced below if we switch back to single-line.
mparent.set(combinerBefore);
parentChanged = true;
}
if (// There is no overridden value, so this node goes away completely.
mparent.child(name) == null) {
model.removeNodeFromParent(createdNode);
if (// The node used to be single-line, so fold the last equation back into it.
equationCount == 0) {
NodeEquation lastEquation = null;
// unfiltered
Enumeration<?> i = parent.children();
while (i.hasMoreElements()) {
Object o = i.nextElement();
if (o instanceof NodeEquation) {
lastEquation = (NodeEquation) o;
break;
}
}
String lastCondition = lastEquation.source.key();
String lastExpression = lastEquation.source.get();
mparent.clear(lastCondition);
if (lastCondition.equals("@"))
mparent.set(combinerBefore + lastExpression);
else
mparent.set(combinerBefore + lastExpression + lastCondition);
parentChanged = true;
model.removeNodeFromParent(lastEquation);
}
} else // Just exposed an overridden value, so update display.
{
createdNode.updateColumnWidths(fm);
}
if (// Update tabs among this variable's siblings
parentChanged) {
parent.updateColumnWidths(fm);
NodeBase grandparent = (NodeBase) parent.getParent();
grandparent.updateTabStops(fm);
grandparent.allNodesChanged(model);
}
parent.updateTabStops(fm);
parent.allNodesChanged(model);
mep.panelEquations.updateOrder(createdPath);
mep.panelEquations.updateVisibility(createdPath, index);
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class AddPart method destroy.
public static void destroy(List<String> path, boolean canceled, String name) {
// Retrieve created node
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
NodePart createdNode = (NodePart) parent.child(name);
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
TreeNode[] createdPath = createdNode.getPath();
int index = parent.getIndexFiltered(createdNode);
if (canceled)
index--;
MPart mparent = parent.source;
mparent.clear(name);
if (// Node is fully deleted
mparent.child(name) == null) {
model.removeNodeFromParent(createdNode);
} else // Just exposed an overridden node
{
createdNode.build();
createdNode.findConnections();
createdNode.filter(model.filterLevel);
}
mep.panelEquations.updateOrder(createdPath);
// includes nodeStructureChanged(), if necessary
mep.panelEquations.updateVisibility(createdPath, index);
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class ChangeAnnotation method apply.
public static void apply(List<String> path, String nameBefore, String nameAfter, String valueAfter, String blockName, NodeFactory factory) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodeBase nodeBefore = parent.child(nameBefore);
if (nodeBefore == null)
throw new CannotRedoException();
PanelEquationTree pet = PanelModel.instance.panelEquations;
JTree tree = pet.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
FontMetrics fm = nodeBefore.getFontMetrics(tree);
NodeBase nodeAfter;
if (nameBefore.equals(nameAfter)) {
nodeAfter = nodeBefore;
nodeAfter.source.set(valueAfter);
} else {
// Update database
MPart mparent;
if (parent instanceof NodeVariable)
mparent = (MPart) parent.source.child(blockName);
else
mparent = parent.source;
// should directly change destinationNode if it exists
MPart newPart = (MPart) mparent.set(nameAfter, valueAfter);
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 = factory.create(newPart);
model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
}
}
}
nodeAfter.updateColumnWidths(fm);
parent.updateTabStops(fm);
parent.allNodesChanged(model);
TreeNode[] nodePath = nodeAfter.getPath();
pet.updateOrder(nodePath);
pet.updateVisibility(nodePath);
// Only an inherited lock node can be touched by editing. It is possible to activate (make local) if the user assigns a specific value to it.
if (path.size() == 2 && path.get(1).equals("$metadata") && (nameBefore.equals("lock") || nameAfter.equals("lock")))
pet.updateLock();
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class ChangeAnnotation method undo.
public void undo() {
super.undo();
apply(path, nameAfter, nameBefore, valueBefore, "$metadata", new NodeFactory() {
public NodeBase create(MPart part) {
return new NodeAnnotation(part);
}
});
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class ChangeEquation method apply.
public static void apply(List<String> path, String nameBefore, String nameAfter, String combinerAfter, String valueAfter) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodeBase nodeBefore = parent.child(nameBefore);
if (nodeBefore == null)
throw new CannotRedoException();
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
FontMetrics fm = nodeBefore.getFontMetrics(tree);
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(nameAfter, valueAfter);
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.filterLevel))
model.nodeChanged(nodeBefore);
else
parent.hide(nodeBefore, model, true);
}
}
if (parent.getChildCount() > 0) {
NodeBase firstChild = (NodeBase) parent.getChildAt(0);
if (firstChild.needsInitTabs())
firstChild.initTabs(fm);
}
if (!parent.source.get().equals(combinerAfter)) {
parent.source.set(combinerAfter);
parent.updateColumnWidths(fm);
NodeBase grandparent = (NodeBase) parent.getParent();
grandparent.updateTabStops(fm);
grandparent.allNodesChanged(model);
}
nodeAfter.updateColumnWidths(fm);
parent.updateTabStops(fm);
parent.allNodesChanged(model);
mep.panelEquations.updateVisibility(nodeAfter.getPath());
}
Aggregations