Search in sources :

Example 1 with AddDoc

use of gov.sandia.n2a.ui.eq.undo.AddDoc in project n2a by frothga.

the class ImportNeuroML method addModel.

public void addModel(MNode m, MNode models, UndoManager um) {
    String key = m.key();
    models.clear(key);
    // model files frequently repeat equations that should be inherited.
    for (MNode c : m) {
        String inherit = "";
        if (c.key().equals("$inherit")) {
            inherit = c.get().replace("\"", "");
        } else if (c.child("$inherit") != null) {
            inherit = c.get("$inherit").replace("\"", "");
        }
        MNode d = models.child(inherit);
        if (d != null)
            addModel(d, models, um);
    }
    AddDoc add = new AddDoc(key, m);
    add.wasShowing = false;
    um.add(add);
}
Also used : MNode(gov.sandia.n2a.db.MNode) AddDoc(gov.sandia.n2a.ui.eq.undo.AddDoc)

Example 2 with AddDoc

use of gov.sandia.n2a.ui.eq.undo.AddDoc in project n2a by frothga.

the class ImportNative method process.

@Override
public void process(File source) {
    try (BufferedReader reader = new BufferedReader(new FileReader(source))) {
        // dispose of schema line
        reader.readLine();
        MVolatile doc = new MVolatile();
        doc.read(reader);
        PanelModel.instance.undoManager.add(new AddDoc(source.getName(), doc));
    } catch (IOException e) {
    }
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) AddDoc(gov.sandia.n2a.ui.eq.undo.AddDoc) MVolatile(gov.sandia.n2a.db.MVolatile)

Example 3 with AddDoc

use of gov.sandia.n2a.ui.eq.undo.AddDoc in project n2a by frothga.

the class PanelEquationTree method addAtSelected.

public void addAtSelected(String type) {
    if (locked)
        return;
    NodeBase selected = getSelected();
    if (// only happens when root is null
    selected == null) {
        PanelModel.instance.undoManager.add(new AddDoc());
        // Since root is itself a Part, don't create another one. For anything else, fall through and add it to the newly-created model.
        if (type.equals("Part"))
            return;
        selected = root;
    }
    NodeBase editMe = selected.add(type, tree, null);
    if (editMe != null) {
        TreePath path = new TreePath(editMe.getPath());
        tree.scrollPathToVisible(path);
        tree.setSelectionPath(path);
        tree.startEditingAtPath(path);
    }
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) TreePath(javax.swing.tree.TreePath) AddDoc(gov.sandia.n2a.ui.eq.undo.AddDoc)

Example 4 with AddDoc

use of gov.sandia.n2a.ui.eq.undo.AddDoc in project n2a by frothga.

the class ImportNeuroML method process.

@Override
public void process(File source) {
    if (PluginNeuroML.partMap == null)
        PluginNeuroML.partMap = new PartMap();
    ImportJob job = new ImportJob(PluginNeuroML.partMap);
    job.process(source);
    job.postprocess();
    MNode mainModel = job.models.child(job.modelName);
    job.models.clear(job.modelName);
    UndoManager um = PanelModel.instance.undoManager;
    um.addEdit(new CompoundEdit());
    while (job.models.size() > 0) addModel(job.models.iterator().next(), job.models, um);
    // after all add operations are completed.
    if (mainModel != null)
        um.add(new AddDoc(job.modelName, mainModel));
    um.endCompoundEdit();
}
Also used : UndoManager(gov.sandia.n2a.ui.UndoManager) CompoundEdit(gov.sandia.n2a.ui.CompoundEdit) MNode(gov.sandia.n2a.db.MNode) AddDoc(gov.sandia.n2a.ui.eq.undo.AddDoc)

Aggregations

AddDoc (gov.sandia.n2a.ui.eq.undo.AddDoc)4 MNode (gov.sandia.n2a.db.MNode)2 MVolatile (gov.sandia.n2a.db.MVolatile)1 CompoundEdit (gov.sandia.n2a.ui.CompoundEdit)1 UndoManager (gov.sandia.n2a.ui.UndoManager)1 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 TreePath (javax.swing.tree.TreePath)1