use of gov.sandia.n2a.ui.eq.tree.NodeContainer in project n2a by frothga.
the class AddAnnotations method create.
public static void create(List<String> path, int index, MNode saved, NodeFactory factory) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
String blockName = saved.key();
NodeBase n = parent.child(blockName);
if (n != null && !(n instanceof NodeContainer))
throw new CannotRedoException();
NodeContainer node = (NodeContainer) n;
MPart block = (MPart) parent.source.childOrCreate(blockName);
block.merge(saved);
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
if (node == null) {
node = (NodeContainer) factory.create(block);
model.insertNodeIntoUnfiltered(node, parent, index);
}
// Replaces all nodes, so they are set to require tab initialization.
node.build();
node.filter(model.filterLevel);
mep.panelEquations.updateVisibility(node.getPath());
}
use of gov.sandia.n2a.ui.eq.tree.NodeContainer in project n2a by frothga.
the class AddAnnotations method destroy.
public static void destroy(List<String> path, String blockName) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
NodeContainer node = (NodeContainer) parent.child(blockName);
TreeNode[] nodePath = node.getPath();
int index = parent.getIndexFiltered(node);
MPart mparent = parent.source;
mparent.clear(blockName);
if (mparent.child(blockName) == null) {
model.removeNodeFromParent(node);
} else // Just exposed an overridden node
{
// Necessary to remove all overridden nodes
node.build();
node.filter(model.filterLevel);
}
mep.panelEquations.updateVisibility(nodePath, index);
}
Aggregations