use of gov.sandia.n2a.ui.eq.PanelEquationTree in project n2a by frothga.
the class Outsource method apply.
public void apply(MNode subtree) {
// Retrieve created node
NodePart node = (NodePart) NodeBase.locateNode(path);
if (node == null)
throw new CannotRedoException();
PanelEquationTree pet = node.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
// Update database
// remove all children
node.source.clear();
node.source.merge(subtree);
// Update GUI
node.build();
node.findConnections();
node.rebuildPins();
node.filter();
// The caller of this Undoable promises to only use it on top-level nodes.
// Thus, node retains exactly the same visibility as before, so no need for full update.
// There are some obscure cases in which this doesn't hold (node was inherited, and the
// new value of $inherit matches the inherited value of node.$inherit, so node ceases to be top-level),
// but we won't worry about that.
model.nodeStructureChanged(node);
if (node.graph == null) {
TreePath nodePath = new TreePath(node.getPath());
pet.tree.setSelectionPath(nodePath);
if (wasExpanded)
pet.tree.expandPath(nodePath);
} else {
PanelEquations pe = PanelModel.instance.panelEquations;
if (pe.view == PanelEquations.NODE)
node.graph.setOpen(wasExpanded);
node.graph.takeFocusOnTitle();
// Because changes to inherit can change how a part's title is displayed.
node.graph.updateTitle();
}
pet.animate();
// Not necessary to update the graph, since exactly the same connections exist.
// findConnections() would merely re-establish them.
}
use of gov.sandia.n2a.ui.eq.PanelEquationTree in project n2a by frothga.
the class AddPart method destroy.
public static void destroy(List<String> path, boolean canceled, String name, boolean setSelected, boolean multiShared, boolean touchesPin) {
// Retrieve created node
NodePart parent = (NodePart) NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
NodePart createdNode = (NodePart) parent.child(name);
PanelEquations pe = PanelModel.instance.panelEquations;
boolean graphParent = parent == pe.part;
// Only use tree if it is not the graph parent, since graph parent hides its sub-parts.
PanelEquationTree pet = graphParent ? null : parent.getTree();
FilteredTreeModel model = null;
if (pet != null)
model = (FilteredTreeModel) pet.tree.getModel();
// only used if graphParent is true
PanelEquationGraph peg = pe.panelEquationGraph;
TreeNode[] createdPath = createdNode.getPath();
// returns -1 if createdNode is filtered out of parent
int index = parent.getIndexFiltered(createdNode);
if (canceled)
index--;
MPart mparent = parent.source;
mparent.clear(name);
if (// Node is fully deleted
mparent.child(name) == null) {
pe.deleteFocus(createdNode);
if (model == null)
FilteredTreeModel.removeNodeFromParentStatic(createdNode);
else
model.removeNodeFromParent(createdNode);
if (graphParent)
peg.removePart(createdNode, setSelected && !multiShared);
parent.findConnections();
parent.updatePins();
} else // Just exposed an overridden node
{
// Does not change the fake-root status of this node.
createdNode.build();
parent.findConnections();
createdNode.rebuildPins();
createdNode.filter();
if (// Need to update entire model under fake root.
graphParent) {
PanelEquationTree subpet = createdNode.getTree();
if (subpet != null) {
FilteredTreeModel submodel = (FilteredTreeModel) subpet.tree.getModel();
submodel.nodeStructureChanged(createdNode);
subpet.animate();
}
// Implicitly, the title of the node was focused when the part was deleted, so ensure it gets the focus back.
if (setSelected && !multiShared)
createdNode.graph.takeFocusOnTitle();
}
}
pe.resetBreadcrumbs();
if (pet == null) {
PanelEquationTree.updateOrder(null, createdPath);
PanelEquationTree.updateVisibility(null, createdPath, index, false);
} else {
pet.updateOrder(createdPath);
// includes nodeStructureChanged(), if necessary
pet.updateVisibility(createdPath, index, setSelected);
pet.animate();
}
if (graphParent || touchesPin) {
peg.updatePins();
peg.reconnect();
peg.repaint();
}
if (graphParent) {
if (pe.view == PanelEquations.NODE && peg.isEmpty())
pe.panelParent.setOpen(true);
if (setSelected && multiShared)
pe.switchFocus(false, false);
}
}
use of gov.sandia.n2a.ui.eq.PanelEquationTree 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, boolean setSelection) {
// Retrieve created node
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
NodeBase createdNode = parent.child(name);
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
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) {
// The one remaining equation.
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.
{
createdNode.setUserObject();
}
if (// Update tabs among this variable's siblings
parentChanged) {
parent.setUserObject();
NodeBase grandparent = (NodeBase) parent.getParent();
grandparent.invalidateColumns(model);
}
parent.invalidateColumns(null);
pet.updateOrder(createdPath);
pet.updateVisibility(createdPath, index, setSelection);
parent.allNodesChanged(model);
pet.animate();
}
use of gov.sandia.n2a.ui.eq.PanelEquationTree in project n2a by frothga.
the class ChangeOrder method apply.
public void apply(int indexBefore, int indexAfter, int indexMetadata, boolean createOrder, boolean destroyOrder) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
NodeBase moveNode = (NodeBase) parent.getChildAt(indexBefore);
model.removeNodeFromParent(moveNode);
NodeAnnotations metadataNode = (NodeAnnotations) parent.child("$metadata");
boolean needBuild = false;
if (createOrder) {
if (metadataNode == null) {
metadataNode = new NodeAnnotations((MPart) parent.source.childOrCreate("$metadata"));
model.insertNodeIntoUnfiltered(metadataNode, parent, indexMetadata);
}
metadataNode.source.childOrCreate("gui", "order");
needBuild = true;
}
if (destroyOrder) {
MNode mparent = metadataNode.source;
mparent.clear("gui", "order");
if (mparent.child("gui").size() == 0)
mparent.clear("gui");
if (mparent.size() == 0) {
parent.source.clear("$metadata");
model.removeNodeFromParent(metadataNode);
} else {
needBuild = true;
}
}
if (needBuild) {
List<String> expanded = AddAnnotation.saveExpandedNodes(pet.tree, metadataNode);
metadataNode.build();
metadataNode.filter();
if (metadataNode.visible()) {
model.nodeStructureChanged(metadataNode);
AddAnnotation.restoreExpandedNodes(pet.tree, metadataNode, expanded);
}
}
model.insertNodeIntoUnfiltered(moveNode, parent, indexAfter);
TreeNode[] movePath = moveNode.getPath();
if (!destroyOrder)
pet.updateOrder(movePath);
pet.updateVisibility(movePath);
}
use of gov.sandia.n2a.ui.eq.PanelEquationTree in project n2a by frothga.
the class ChangeReference method apply.
public void apply(String nameBefore, String nameAfter, String valueAfter) {
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 database
MPart mparent;
if (parent instanceof NodeVariable)
mparent = (MPart) parent.source.child("$reference");
else
mparent = parent.source;
// should directly change destinationNode if it exists
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 NodeReference(newPart);
model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
}
}
}
nodeAfter.setUserObject();
parent.invalidateColumns(null);
TreeNode[] nodePath = nodeAfter.getPath();
pet.updateOrder(nodePath);
pet.updateVisibility(nodePath);
parent.allNodesChanged(model);
pet.animate();
}
Aggregations