use of gov.sandia.n2a.ui.eq.tree.NodeVariable 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.ui.eq.tree.NodeVariable in project n2a by frothga.
the class AddVariable method create.
public static NodeBase create(List<String> path, int index, String name, MNode newPart, boolean nameIsGenerated) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodeBase n = parent.child(name);
// Should be blocked by GUI constraints, but this defends against ill-formed model on clipboard.
if (n != null && !(n instanceof NodeVariable))
throw new CannotRedoException();
NodeVariable createdNode = (NodeVariable) n;
// Update database
MPart createdPart = (MPart) parent.source.set(name, "");
createdPart.merge(newPart);
// Update GUI
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
boolean alreadyExists = createdNode != null;
if (!alreadyExists)
createdNode = new NodeVariable(createdPart);
// pure create, so about to go into edit mode. This should only happen on first application of the create action, and should only be possible if visibility is already correct.
if (nameIsGenerated)
createdNode.setUserObject("");
FontMetrics fm = createdNode.getFontMetrics(tree);
// preempt initialization
createdNode.updateColumnWidths(fm);
if (!alreadyExists)
model.insertNodeIntoUnfiltered(createdNode, parent, index);
TreeNode[] createdPath = createdNode.getPath();
if (!nameIsGenerated) {
createdNode.build();
createdNode.findConnections();
mep.panelEquations.updateOrder(createdPath);
parent.updateTabStops(fm);
parent.allNodesChanged(model);
}
mep.panelEquations.updateVisibility(createdPath);
return createdNode;
}
use of gov.sandia.n2a.ui.eq.tree.NodeVariable in project n2a by frothga.
the class AddVariable 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();
NodeVariable createdNode = (NodeVariable) 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--;
MPart mparent = parent.source;
mparent.clear(name);
if (// Node is fully deleted
mparent.child(name) == null) {
model.removeNodeFromParent(createdNode);
((NodePart) parent).findConnections();
} else // Just exposed an overridden node
{
createdNode.build();
createdNode.findConnections();
createdNode.updateColumnWidths(fm);
}
parent.updateTabStops(fm);
parent.allNodesChanged(model);
mep.panelEquations.updateOrder(createdPath);
// includes nodeStructureChanged(), if necessary
mep.panelEquations.updateVisibility(createdPath, index);
}
use of gov.sandia.n2a.ui.eq.tree.NodeVariable in project n2a by frothga.
the class ChangeVariable method apply.
public static void apply(List<String> path, String nameBefore, String nameAfter, MNode savedTree) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodeVariable nodeBefore = (NodeVariable) 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);
NodeVariable nodeAfter;
if (nameBefore.equals(nameAfter)) {
nodeAfter = nodeBefore;
// Same as valueAfter. Sub-tree is not relevant here.
nodeAfter.source.set(savedTree.get());
} else {
// Update database
MPart mparent = parent.source;
mparent.clear(nameBefore);
mparent.set(nameAfter, "").merge(savedTree);
MPart newPart = (MPart) mparent.child(nameAfter);
MPart oldPart = (MPart) mparent.child(nameBefore);
// Update GUI
nodeAfter = (NodeVariable) 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 NodeVariable(newPart);
model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
}
nodeBefore.build();
nodeBefore.findConnections();
if (nodeBefore.visible(model.filterLevel))
model.nodeStructureChanged(nodeBefore);
else
parent.hide(nodeBefore, model, true);
}
}
nodeAfter.build();
nodeAfter.findConnections();
nodeAfter.updateColumnWidths(fm);
parent.updateTabStops(fm);
parent.allNodesChanged(model);
TreeNode[] nodePath = nodeAfter.getPath();
mep.panelEquations.updateOrder(nodePath);
mep.panelEquations.updateVisibility(nodePath);
}
Aggregations