Search in sources :

Example 1 with PanelSearch

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();
}
Also used : NodeAnnotations(gov.sandia.n2a.ui.eq.tree.NodeAnnotations) PanelSearch(gov.sandia.n2a.ui.eq.PanelSearch) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) PanelEquations(gov.sandia.n2a.ui.eq.PanelEquations) MNode(gov.sandia.n2a.db.MNode) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Aggregations

MNode (gov.sandia.n2a.db.MNode)1 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)1 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)1 PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)1 PanelSearch (gov.sandia.n2a.ui.eq.PanelSearch)1 NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)1 TreeNode (javax.swing.tree.TreeNode)1 CannotUndoException (javax.swing.undo.CannotUndoException)1