Search in sources :

Example 6 with MNode

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;
}
Also used : PanelModel(gov.sandia.n2a.ui.eq.PanelModel) MNode(gov.sandia.n2a.db.MNode)

Example 7 with MNode

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);
}
Also used : MNode(gov.sandia.n2a.db.MNode)

Example 8 with MNode

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));
}
Also used : PanelModel(gov.sandia.n2a.ui.eq.PanelModel) ChangeDoc(gov.sandia.n2a.ui.eq.undo.ChangeDoc) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel) MNode(gov.sandia.n2a.db.MNode) ChangePart(gov.sandia.n2a.ui.eq.undo.ChangePart)

Example 9 with MNode

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);
}
Also used : MPart(gov.sandia.n2a.eqset.MPart) ArrayList(java.util.ArrayList) MNode(gov.sandia.n2a.db.MNode) HashSet(java.util.HashSet)

Example 10 with MNode

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);
    }
}
Also used : MNode(gov.sandia.n2a.db.MNode)

Aggregations

MNode (gov.sandia.n2a.db.MNode)63 Node (org.w3c.dom.Node)11 NameMap (gov.sandia.n2a.backend.neuroml.PartMap.NameMap)9 MVolatile (gov.sandia.n2a.db.MVolatile)5 MPart (gov.sandia.n2a.eqset.MPart)5 ArrayList (java.util.ArrayList)5 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)4 MPersistent (gov.sandia.n2a.db.MPersistent)3 EquationSet (gov.sandia.n2a.eqset.EquationSet)3 Variable (gov.sandia.n2a.eqset.Variable)3 AccessVariable (gov.sandia.n2a.language.AccessVariable)3 PanelReference (gov.sandia.n2a.ui.ref.PanelReference)3 Element (org.w3c.dom.Element)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 MDoc (gov.sandia.n2a.db.MDoc)2 ParseException (gov.sandia.n2a.language.ParseException)2 AddDoc (gov.sandia.n2a.ui.eq.undo.AddDoc)2 IOException (java.io.IOException)2 TreeMap (java.util.TreeMap)2 IncommensurableException (javax.measure.IncommensurableException)2