Search in sources :

Example 1 with MDoc

use of gov.sandia.n2a.db.MDoc in project n2a by frothga.

the class AddDoc method destroy.

public static int destroy(String name, boolean fromSearchPanel) {
    MNode doc = AppData.models.child(name);
    PanelModel mep = PanelModel.instance;
    mep.panelEquations.recordDeleted(doc);
    mep.panelMRU.removeDoc(doc);
    int result = mep.panelSearch.removeDoc(doc);
    String id = doc.get("$metadata", "id");
    if (!id.isEmpty())
        AppData.set(id, null);
    ((MDoc) doc).delete();
    mep.panelSearch.lastSelection = Math.min(mep.panelSearch.model.size() - 1, result);
    if (fromSearchPanel) {
        mep.panelSearch.list.setSelectedIndex(mep.panelSearch.lastSelection);
        mep.panelSearch.list.requestFocusInWindow();
    } else {
        mep.panelEquations.tree.requestFocusInWindow();
    }
    return result;
}
Also used : PanelModel(gov.sandia.n2a.ui.eq.PanelModel) MNode(gov.sandia.n2a.db.MNode) MDoc(gov.sandia.n2a.db.MDoc)

Example 2 with MDoc

use of gov.sandia.n2a.db.MDoc in project n2a by frothga.

the class PanelRun method delete.

public void delete() {
    TreePath[] paths = tree.getSelectionPaths();
    if (paths.length < 1)
        return;
    boolean nextSelectionIsParent = false;
    NodeBase firstSelection = (NodeBase) paths[0].getLastPathComponent();
    NodeBase lastSelection = (NodeBase) paths[paths.length - 1].getLastPathComponent();
    NodeBase nextSelection = (NodeBase) lastSelection.getNextSibling();
    if (nextSelection == null)
        nextSelection = (NodeBase) firstSelection.getPreviousSibling();
    if (nextSelection == null) {
        nextSelection = (NodeBase) firstSelection.getParent();
        nextSelectionIsParent = true;
    }
    for (TreePath path : paths) {
        final NodeBase node = (NodeBase) path.getLastPathComponent();
        model.removeNodeFromParent(node);
        if (displayNode == node) {
            synchronized (displayText) {
                displayText.setText("");
            }
            if (displayPane.getViewport().getView() != displayText)
                displayPane.setViewportView(displayText);
        }
        new Thread("PanelRun Delete") {

            public void run() {
                if (node instanceof NodeJob) {
                    NodeJob job = (NodeJob) node;
                    synchronized (running) {
                        running.remove(job);
                    }
                    MDoc doc = (MDoc) job.source;
                    HostSystem env = HostSystem.get(doc.getOrDefault("$metadata", "host", "localhost"));
                    String jobName = doc.key();
                    try {
                        if (job.complete < 1)
                            job.stop();
                        env.deleteJob(jobName);
                    } catch (Exception e) {
                    }
                    doc.delete();
                } else if (node instanceof NodeFile) {
                    ((NodeFile) node).path.delete();
                }
            }
        }.start();
    }
    if (nextSelectionIsParent) {
        if (nextSelection.getChildCount() > 0)
            tree.setSelectionPath(new TreePath(((NodeBase) nextSelection.getChildAt(0)).getPath()));
        else if (nextSelection != root)
            tree.setSelectionPath(new TreePath(nextSelection.getPath()));
    } else {
        tree.setSelectionPath(new TreePath(nextSelection.getPath()));
    }
    tree.paintImmediately(treePane.getViewport().getViewRect());
}
Also used : TreePath(javax.swing.tree.TreePath) HostSystem(gov.sandia.n2a.execenvs.HostSystem) ExpandVetoException(javax.swing.tree.ExpandVetoException) IOException(java.io.IOException) MDoc(gov.sandia.n2a.db.MDoc)

Example 3 with MDoc

use of gov.sandia.n2a.db.MDoc in project n2a by frothga.

the class AddEntry method destroy.

public static int destroy(String id, boolean fromSearchPanel) {
    MNode doc = AppData.references.child(id);
    PanelReference mep = PanelReference.instance;
    mep.panelEntry.recordDeleted(doc);
    mep.panelMRU.removeDoc(doc);
    int result = mep.panelSearch.removeDoc(doc);
    ((MDoc) doc).delete();
    mep.panelSearch.lastSelection = Math.min(mep.panelSearch.model.size() - 1, result);
    if (fromSearchPanel) {
        mep.panelSearch.list.setSelectedIndex(mep.panelSearch.lastSelection);
        mep.panelSearch.list.requestFocusInWindow();
    } else {
        mep.panelEntry.table.requestFocusInWindow();
    }
    return result;
}
Also used : PanelReference(gov.sandia.n2a.ui.ref.PanelReference) MNode(gov.sandia.n2a.db.MNode) MDoc(gov.sandia.n2a.db.MDoc)

Example 4 with MDoc

use of gov.sandia.n2a.db.MDoc in project n2a by frothga.

the class AddDoc method create.

public static int create(String name, MNode saved, int index, boolean fromSearchPanel, boolean wasShowing) {
    MDoc doc = (MDoc) AppData.models.set(name, "");
    doc.merge(saved);
    new MPart(doc).clearRedundantOverrides();
    AppData.set(doc.get("$metadata", "id"), doc);
    PanelModel mep = PanelModel.instance;
    mep.panelMRU.insertDoc(doc);
    int result = mep.panelSearch.insertDoc(doc, index);
    if (wasShowing)
        mep.panelEquations.loadRootFromDB(doc);
    mep.panelSearch.lastSelection = index;
    if (fromSearchPanel) {
        if (wasShowing)
            mep.panelEquations.tree.clearSelection();
        mep.panelSearch.list.setSelectedIndex(result);
        mep.panelSearch.list.requestFocusInWindow();
    } else {
        mep.panelEquations.tree.requestFocusInWindow();
    }
    return result;
}
Also used : PanelModel(gov.sandia.n2a.ui.eq.PanelModel) MPart(gov.sandia.n2a.eqset.MPart) MDoc(gov.sandia.n2a.db.MDoc)

Aggregations

MDoc (gov.sandia.n2a.db.MDoc)4 MNode (gov.sandia.n2a.db.MNode)2 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)2 MPart (gov.sandia.n2a.eqset.MPart)1 HostSystem (gov.sandia.n2a.execenvs.HostSystem)1 PanelReference (gov.sandia.n2a.ui.ref.PanelReference)1 IOException (java.io.IOException)1 ExpandVetoException (javax.swing.tree.ExpandVetoException)1 TreePath (javax.swing.tree.TreePath)1