Search in sources :

Example 6 with PanelModel

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

the class ChangeDoc method rename.

public void rename(String A, String B) {
    // Update database
    AppData.models.move(A, B);
    MNode doc = AppData.models.child(B);
    String id = doc.get("$metadata", "id");
    if (!id.isEmpty())
        AppData.set(id, doc);
    if (AppData.state.get("PanelModel", "lastUsed").equals(A))
        AppData.state.set(B, "PanelModel", "lastUsed");
    // Update GUI
    PanelModel pm = PanelModel.instance;
    PanelEquations container = pm.panelEquations;
    if (wasShowing) {
        // lazy; only loads if not already loaded
        container.load(doc);
        // If it was already loaded, then need to directly update doc name.
        container.root.setUserObject();
    }
    // Because the change in document name does not directly notify the list model.
    pm.panelMRU.renamed();
    if (fromSearchPanel) {
        selection.set(selection.size() - 1, B);
        pm.panelSearch.forceSelection(selection);
    } else if (wasShowing)
        container.breadcrumbRenderer.requestFocusInWindow();
// else we don't care where focus is
}
Also used : PanelModel(gov.sandia.n2a.ui.eq.PanelModel) PanelEquations(gov.sandia.n2a.ui.eq.PanelEquations) MNode(gov.sandia.n2a.db.MNode)

Example 7 with PanelModel

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

the class DeleteDoc method undo.

public void undo() {
    super.undo();
    PanelModel mep = PanelModel.instance;
    mep.panelMRU.dontInsert = !wasInMRU;
    AddDoc.create(saved.key(), saved, pathAfter, fromSearchPanel, wasShowing);
}
Also used : PanelModel(gov.sandia.n2a.ui.eq.PanelModel)

Example 8 with PanelModel

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

the class AddAnnotations method create.

public static void create(List<String> path, int index, MNode saved, NodeFactory factory) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    String blockName = saved.key();
    NodeBase n = parent.child(blockName);
    if (n != null && !(n instanceof NodeContainer))
        throw new CannotRedoException();
    NodeContainer node = (NodeContainer) n;
    MPart block = (MPart) parent.source.childOrCreate(blockName);
    block.merge(saved);
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    if (node == null) {
        node = (NodeContainer) factory.create(block);
        model.insertNodeIntoUnfiltered(node, parent, index);
    }
    // Replaces all nodes, so they are set to require tab initialization.
    node.build();
    node.filter(model.filterLevel);
    mep.panelEquations.updateVisibility(node.getPath());
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) MPart(gov.sandia.n2a.eqset.MPart) JTree(javax.swing.JTree) CannotRedoException(javax.swing.undo.CannotRedoException) NodeContainer(gov.sandia.n2a.ui.eq.tree.NodeContainer) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 9 with PanelModel

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

the class AddAnnotations method destroy.

public static void destroy(List<String> path, String blockName) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    NodeContainer node = (NodeContainer) parent.child(blockName);
    TreeNode[] nodePath = node.getPath();
    int index = parent.getIndexFiltered(node);
    MPart mparent = parent.source;
    mparent.clear(blockName);
    if (mparent.child(blockName) == null) {
        model.removeNodeFromParent(node);
    } else // Just exposed an overridden node
    {
        // Necessary to remove all overridden nodes
        node.build();
        node.filter(model.filterLevel);
    }
    mep.panelEquations.updateVisibility(nodePath, index);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) JTree(javax.swing.JTree) MPart(gov.sandia.n2a.eqset.MPart) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) NodeContainer(gov.sandia.n2a.ui.eq.tree.NodeContainer) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 10 with PanelModel

use of gov.sandia.n2a.ui.eq.PanelModel 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

PanelModel (gov.sandia.n2a.ui.eq.PanelModel)13 MPart (gov.sandia.n2a.eqset.MPart)8 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)6 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)6 JTree (javax.swing.JTree)6 MNode (gov.sandia.n2a.db.MNode)4 FontMetrics (java.awt.FontMetrics)4 CannotRedoException (javax.swing.undo.CannotRedoException)4 MDoc (gov.sandia.n2a.db.MDoc)3 TreeNode (javax.swing.tree.TreeNode)3 NodeContainer (gov.sandia.n2a.ui.eq.tree.NodeContainer)2 NodeEquation (gov.sandia.n2a.ui.eq.tree.NodeEquation)2 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)2 CannotUndoException (javax.swing.undo.CannotUndoException)2 Variable (gov.sandia.n2a.eqset.Variable)1 PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)1 NodeAnnotation (gov.sandia.n2a.ui.eq.tree.NodeAnnotation)1 NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)1