use of gov.sandia.n2a.ui.eq.tree.NodeBase in project n2a by frothga.
the class PanelEquationTree method updateVisibility.
public void updateVisibility(TreeNode[] path) {
if (path.length < 2) {
updateVisibility(path, -1);
} else {
NodeBase c = (NodeBase) path[path.length - 1];
NodeBase p = (NodeBase) path[path.length - 2];
int index = p.getIndexFiltered(c);
updateVisibility(path, index);
}
}
use of gov.sandia.n2a.ui.eq.tree.NodeBase in project n2a by frothga.
the class StoredPath method restore.
public void restore(JTree tree) {
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
// goal is to find n closest to original selected node as possible
NodeBase n = (NodeBase) model.getRoot();
// First restore all previously expanded nodes
for (String[] stringPath : others) {
NodeBase c = n;
for (String key : stringPath) {
c = c.child(key);
if (c == null)
break;
}
if (c != null && c.visible(model.filterLevel))
tree.expandPath(new TreePath(c.getPath()));
}
// Second, locate the focused node and pay special attention to its visibility
for (String key : keys) {
int childCount = n.getChildCount();
int i;
for (i = 0; i < childCount; i++) {
NodeBase c = (NodeBase) n.getChildAt(i);
if (c.source.key().equals(key)) {
n = c;
break;
}
}
if (// The key was not found at all. n remains at parent node
i >= childCount) {
// Always expand the parent when a child is lost.
expanded = true;
break;
}
if (// The node we actually found is currently filtered out, so find nearest sibling
!n.visible(model.filterLevel)) {
// If nothing is found, n will remain at the parent.
n = (NodeBase) n.getParent();
// First walk forward
boolean found = false;
for (int j = i + 1; j < childCount; j++) {
NodeBase c = (NodeBase) n.getChildAt(j);
if (c.visible(model.filterLevel)) {
n = c;
found = true;
break;
}
}
if (found)
break;
// Then if needed, walk backward.
for (int j = i - 1; j >= 0; j--) {
NodeBase c = (NodeBase) n.getChildAt(j);
if (c.visible(model.filterLevel)) {
n = c;
found = true;
break;
}
}
if (!found)
expanded = true;
break;
}
}
TreePath path = new TreePath(n.getPath());
tree.setSelectionPath(path);
if (expanded)
tree.expandPath(path);
}
use of gov.sandia.n2a.ui.eq.tree.NodeBase in project n2a by frothga.
the class AddAnnotation method destroy.
public static void destroy(List<String> path, boolean canceled, String name, String blockName) {
// Retrieve created node
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
NodeBase container = parent;
if (parent instanceof NodePart)
container = parent.child(blockName);
NodeBase createdNode = container.child(name);
PanelEquationTree pet = PanelModel.instance.panelEquations;
JTree tree = pet.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
FontMetrics fm = createdNode.getFontMetrics(tree);
boolean containerIsVisible = true;
TreeNode[] createdPath = createdNode.getPath();
int index = container.getIndexFiltered(createdNode);
if (canceled)
index--;
MPart block = (MPart) parent.source.child(blockName);
block.clear(name);
if (// There is no overridden value, so this node goes away completely.
block.child(name) == null) {
model.removeNodeFromParent(createdNode);
if (block.size() == 0) {
// commit suicide
parent.source.clear(blockName);
if (parent instanceof NodePart) {
model.removeNodeFromParent(container);
// No need to update order, because we just destroyed $metadata, where order is stored.
// No need to update tab stops in grandparent, because block nodes don't offer any tab stops.
containerIsVisible = false;
}
}
} else // Just exposed an overridden value, so update display.
{
if (// We are always visible, but our parent could disappear.
container.visible(model.filterLevel)) {
createdNode.updateColumnWidths(fm);
} else {
containerIsVisible = false;
}
}
if (containerIsVisible) {
container.updateTabStops(fm);
container.allNodesChanged(model);
}
pet.updateVisibility(createdPath, index);
if (path.size() == 1 && name.equals("lock"))
pet.updateLock();
}
use of gov.sandia.n2a.ui.eq.tree.NodeBase 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.NodeBase 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