Search in sources :

Example 46 with FilteredTreeModel

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

the class ChangeVariable method apply.

public static void apply(List<String> path, String nameBefore, String nameAfter, MNode savedTree) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodeVariable nodeBefore = (NodeVariable) parent.child(nameBefore);
    if (nodeBefore == null)
        throw new CannotRedoException();
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    FontMetrics fm = nodeBefore.getFontMetrics(tree);
    NodeVariable nodeAfter;
    if (nameBefore.equals(nameAfter)) {
        nodeAfter = nodeBefore;
        // Same as valueAfter. Sub-tree is not relevant here.
        nodeAfter.source.set(savedTree.get());
    } else {
        // Update database
        MPart mparent = parent.source;
        mparent.clear(nameBefore);
        mparent.set(nameAfter, "").merge(savedTree);
        MPart newPart = (MPart) mparent.child(nameAfter);
        MPart oldPart = (MPart) mparent.child(nameBefore);
        // Update GUI
        nodeAfter = (NodeVariable) parent.child(nameAfter);
        if (oldPart == null) {
            if (nodeAfter == null) {
                nodeAfter = nodeBefore;
                nodeAfter.source = newPart;
            } else {
                model.removeNodeFromParent(nodeBefore);
            }
        } else {
            if (nodeAfter == null) {
                int index = parent.getIndex(nodeBefore);
                nodeAfter = new NodeVariable(newPart);
                model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
            }
            nodeBefore.build();
            nodeBefore.findConnections();
            if (nodeBefore.visible(model.filterLevel))
                model.nodeStructureChanged(nodeBefore);
            else
                parent.hide(nodeBefore, model, true);
        }
    }
    nodeAfter.build();
    nodeAfter.findConnections();
    nodeAfter.updateColumnWidths(fm);
    parent.updateTabStops(fm);
    parent.allNodesChanged(model);
    TreeNode[] nodePath = nodeAfter.getPath();
    mep.panelEquations.updateOrder(nodePath);
    mep.panelEquations.updateVisibility(nodePath);
}
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) FontMetrics(java.awt.FontMetrics) TreeNode(javax.swing.tree.TreeNode) CannotRedoException(javax.swing.undo.CannotRedoException) NodeVariable(gov.sandia.n2a.ui.eq.tree.NodeVariable) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Aggregations

FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)46 MPart (gov.sandia.n2a.eqset.MPart)34 TreeNode (javax.swing.tree.TreeNode)31 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)29 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)28 CannotRedoException (javax.swing.undo.CannotRedoException)21 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)18 TreePath (javax.swing.tree.TreePath)18 CannotUndoException (javax.swing.undo.CannotUndoException)15 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)14 PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)11 JTree (javax.swing.JTree)10 PanelEquationGraph (gov.sandia.n2a.ui.eq.PanelEquationGraph)9 NodeContainer (gov.sandia.n2a.ui.eq.tree.NodeContainer)9 Variable (gov.sandia.n2a.eqset.Variable)8 MNode (gov.sandia.n2a.db.MNode)7 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)6 NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)6 FontMetrics (java.awt.FontMetrics)6 Point (java.awt.Point)6