use of gov.sandia.n2a.ui.eq.PanelSearch in project n2a by frothga.
the class ChangeCategory method apply.
public void apply(String key, List<String> selectionBefore, String categoryAfter, List<String> selectionAfter) {
MNode doc = AppData.models.child(key);
if (doc == null)
throw new CannotUndoException();
// Graph focus
PanelSearch ps = PanelModel.instance.panelSearch;
ps.lastSelection = selectionBefore;
ps.takeFocus();
// Update DB, and possibly equation tree.
PanelEquations pe = PanelModel.instance.panelEquations;
if (// direct to db
doc != pe.record) {
doc.set(categoryAfter, "$metadata", "gui", "category");
} else // got through MPart
{
MNode source = pe.root.source;
if (categoryAfter.isEmpty())
source.clear("$metadata", "gui", "category");
else
source.set(categoryAfter, "$metadata", "gui", "category");
PanelEquationTree pet = pe.root.getTree();
FilteredTreeModel model = null;
if (pet != null)
model = (FilteredTreeModel) pet.tree.getModel();
// See ChangeAnnotations for more general code.
// To simplify things, we always rebuild the metadata block, even though that is often overkill.
// For simplicity, assume this exists. DB models should always some metadata, such as "id". It is possible for the $metadata node to be deleted by user, so this is not guaranteed.
NodeAnnotations metadataNode = (NodeAnnotations) pe.root.child("$metadata");
List<String> expanded = null;
if (model != null)
expanded = AddAnnotation.saveExpandedNodes(pet.tree, metadataNode);
metadataNode.build();
metadataNode.filter();
if (model != null && metadataNode.visible()) {
model.nodeStructureChanged(metadataNode);
AddAnnotation.restoreExpandedNodes(pet.tree, metadataNode, expanded);
}
if (pet != null) {
TreeNode[] path = metadataNode.getPath();
pet.updateVisibility(path, -2, false);
pet.animate();
}
}
// Update search panel.
ps.lastSelection = selectionAfter;
// This will apply lastSelection when done.
ps.search();
}
Aggregations