use of gov.sandia.n2a.ui.eq.StoredPath in project n2a by frothga.
the class ChangeReferences method apply.
public void apply(MNode add, MNode remove) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = null;
StoredPath sp = null;
if (pet != null) {
model = (FilteredTreeModel) pet.tree.getModel();
sp = new StoredPath(pet.tree);
}
// The immediate container of reference items in the tree.
NodeContainer referenceNode;
// The $reference node under which all changes are made.
MNode referenceSource = null;
if (parent instanceof NodeVariable) {
referenceNode = (NodeContainer) parent;
referenceSource = referenceNode.source.child("$reference");
} else // NodePart is the default case
{
referenceNode = (NodeContainer) parent.child("$reference");
if (referenceNode != null)
referenceSource = referenceNode.source;
}
boolean needBuild = true;
if (// This is an undo, and $reference did not exist before, so remove it.
add == null) {
// We can safely assume that referenceSource is non-null, since we only get here during an undo.
referenceSource.parent().clear("$reference");
if (parent instanceof NodePart) {
if (model == null)
FilteredTreeModel.removeNodeFromParentStatic(referenceNode);
else
model.removeNodeFromParent(referenceNode);
needBuild = false;
}
} else // Update $reference node. Create if it doesn't exist.
{
if (referenceSource == null)
referenceSource = parent.source.childOrCreate("$reference");
if (// only happens when parent is NodePart
referenceNode == null) {
referenceNode = new NodeReferences((MPart) referenceSource);
if (model == null)
FilteredTreeModel.insertNodeIntoUnfilteredStatic(referenceNode, parent, index);
else
model.insertNodeIntoUnfiltered(referenceNode, parent, index);
}
if (remove != null)
referenceSource.uniqueNodes(remove);
referenceSource.merge(add);
}
if (needBuild) {
referenceNode.build();
referenceNode.filter();
if (model != null && referenceNode.visible()) {
model.nodeStructureChanged(referenceNode);
}
}
PanelEquationTree.updateVisibility(pet, referenceNode.getPath(), -1, false);
// This forces focus back to original location.
if (!multi && sp != null)
sp.restore(pet.tree, true);
if (pet != null)
pet.animate();
}
use of gov.sandia.n2a.ui.eq.StoredPath in project n2a by frothga.
the class ChangeAnnotations method apply.
public void apply(MNode add, MNode remove) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = null;
StoredPath sp = null;
if (pet != null) {
model = (FilteredTreeModel) pet.tree.getModel();
sp = new StoredPath(pet.tree);
}
// The immediate container of metadata items in the tree.
NodeContainer metadataNode;
// The $metadata node under which all changes are made.
MNode metadataSource = null;
if (parent instanceof NodeVariable) {
metadataNode = (NodeContainer) parent;
metadataSource = metadataNode.source.child("$metadata");
} else // NodePart is the default case
{
metadataNode = (NodeContainer) parent.child("$metadata");
if (metadataNode != null)
metadataSource = metadataNode.source;
}
boolean needBuild = true;
if (// This is an undo, and $metadata did not exist before, so remove it.
add == null) {
// We can safely assume that metadataSource is non-null, since we only get here during an undo.
metadataSource.parent().clear("$metadata");
if (parent instanceof NodePart) {
if (model == null)
FilteredTreeModel.removeNodeFromParentStatic(metadataNode);
else
model.removeNodeFromParent(metadataNode);
needBuild = false;
}
} else // Update $metadata node. Create if it doesn't exist.
{
if (metadataSource == null)
metadataSource = parent.source.childOrCreate("$metadata");
if (// only happens when parent is NodePart
metadataNode == null) {
metadataNode = new NodeAnnotations((MPart) metadataSource);
if (model == null)
FilteredTreeModel.insertNodeIntoUnfilteredStatic(metadataNode, parent, index);
else
model.insertNodeIntoUnfiltered(metadataNode, parent, index);
}
if (remove != null)
metadataSource.uniqueNodes(remove);
metadataSource.merge(add);
}
if (needBuild) {
List<String> expanded = null;
if (model != null)
expanded = AddAnnotation.saveExpandedNodes(pet.tree, metadataNode);
metadataNode.build();
metadataNode.filter();
if (model != null && metadataNode.visible()) {
model.nodeStructureChanged(metadataNode);
AddAnnotation.restoreExpandedNodes(pet.tree, metadataNode, expanded);
}
}
if (pet != null) {
TreeNode[] path = metadataNode.getPath();
PanelEquationTree.updateVisibility(pet, path, -2, !multi && !graph);
if (// We only care about viewing metadata tree if edit happened in the tree, not graphically.
!graph) {
if (multi)
pet.tree.addSelectionPath(new TreePath(path));
else
// This forces focus back to original location.
sp.restore(pet.tree, true);
}
pet.animate();
}
if (multi && parent instanceof NodePart) {
NodePart np = (NodePart) parent;
if (np.graph != null)
np.graph.setSelected(true);
}
AddAnnotation.update(parent, touchesPin, touchesCategory);
}
Aggregations