use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class NodeBase method locateNode.
public static NodeBase locateNode(List<String> path) {
MNode doc = AppData.models.child(path.get(0));
PanelModel mep = PanelModel.instance;
// lazy; only loads if not already loaded
mep.panelEquations.loadRootFromDB(doc);
// likewise, focus only moves if it is not already on equation tree
mep.panelEquations.tree.requestFocusInWindow();
NodeBase parent = mep.panelEquations.root;
for (int i = 1; i < path.size(); i++) {
// not filtered, because we are concerned with maintaining the model, not the view
parent = (NodeBase) parent.child(path.get(i));
if (parent == null)
break;
}
return parent;
}
use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class NodeInherit method copy.
@Override
public void copy(MNode result) {
MNode n = result.set(source.key(), "");
n.merge(source);
}
use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class NodePart method applyEdit.
@Override
public void applyEdit(JTree tree) {
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
String input = (String) getUserObject();
String[] pieces = input.split("=", 2);
String name = pieces[0].trim();
String oldKey = source.key();
if (name.equals(oldKey)) {
setUserObject();
model.nodeChanged(this);
return;
}
PanelModel mep = PanelModel.instance;
if (// Edits to root cause a rename of the document on disk
isRoot()) {
if (name.isEmpty()) {
setUserObject();
model.nodeChanged(this);
return;
}
name = MDir.validFilenameFrom(name);
// In addition to filename constraints, we also forbid comma, because these names are used in list expressions.
name = name.replace(",", "-");
String stem = name;
int suffix = 0;
MNode models = AppData.models;
MNode existingDocument = models.child(name);
while (existingDocument != null) {
suffix++;
name = stem + " " + suffix;
existingDocument = models.child(name);
}
mep.undoManager.add(new ChangeDoc(oldKey, name));
// MDir promises to maintain object identity during the move, so "source" is still valid.
return;
}
if (input.isEmpty()) {
delete(tree, true);
return;
}
name = validIdentifierFrom(name);
NodeBase parent = (NodeBase) getParent();
NodeBase sibling = parent.child(name);
if (// the name already exists in top document, so reject rename
sibling != null && (sibling.source.isFromTopDocument() || !(sibling instanceof NodePart))) {
setUserObject();
model.nodeChanged(this);
return;
}
mep.undoManager.add(new ChangePart(this, oldKey, name));
}
use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class NodePart method build.
@Override
public void build() {
setUserObject();
removeAllChildren();
String order = source.get("$metadata", "gui.order");
Set<String> sorted = new HashSet<String>();
// comma-separated list
String[] subkeys = order.split(",");
for (String k : subkeys) {
MNode c = source.child(k);
if (c != null) {
buildTriage((MPart) c);
sorted.add(k);
}
}
// Build everything else. Sort all subparts to the end.
ArrayList<MNode> subparts = new ArrayList<MNode>();
for (MNode c : source) {
if (sorted.contains(c.key()))
continue;
if (MPart.isPart(c))
subparts.add(c);
else
buildTriage((MPart) c);
}
for (MNode c : subparts) buildTriage((MPart) c);
}
use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class NodeVariable method copy.
@Override
public void copy(MNode result) {
MNode n = result.set(source.key(), source.get());
Enumeration<?> cf = childrenFiltered();
while (cf.hasMoreElements()) {
NodeBase child = (NodeBase) cf.nextElement();
if (child instanceof NodeAnnotation)
n.set("$metadata", child.source.key(), child.source.get());
else if (child instanceof NodeReference)
n.set("$reference", child.source.key(), child.source.get());
else
child.copy(n);
}
}
Aggregations