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;
}
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());
}
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;
}
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;
}
Aggregations