Search in sources :

Example 1 with NodeContainer

use of gov.sandia.n2a.ui.eq.tree.NodeContainer 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 2 with NodeContainer

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

Aggregations

MPart (gov.sandia.n2a.eqset.MPart)2 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)2 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)2 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)2 NodeContainer (gov.sandia.n2a.ui.eq.tree.NodeContainer)2 JTree (javax.swing.JTree)2 TreeNode (javax.swing.tree.TreeNode)1 CannotRedoException (javax.swing.undo.CannotRedoException)1 CannotUndoException (javax.swing.undo.CannotUndoException)1