Search in sources :

Example 6 with NodePart

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

the class ChangePart method apply.

public void apply(String nameBefore, String nameAfter) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodeBase temp = parent.child(nameBefore);
    if (!(temp instanceof NodePart))
        throw new CannotRedoException();
    NodePart nodeBefore = (NodePart) temp;
    // Update the database: move the subtree.
    MPart mparent = parent.source;
    mparent.clear(nameBefore);
    mparent.set(nameAfter, "").merge(savedTree);
    ;
    MPart oldPart = (MPart) mparent.child(nameBefore);
    MPart newPart = (MPart) mparent.child(nameAfter);
    // Update GUI
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    // It's either a NodePart or it's null. Any other case should be blocked by GUI constraints.
    NodePart nodeAfter = (NodePart) 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 NodePart(newPart);
            model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
        }
        nodeBefore.build();
        nodeBefore.findConnections();
        nodeBefore.filter(model.filterLevel);
        if (nodeBefore.visible(model.filterLevel))
            model.nodeStructureChanged(nodeBefore);
        else
            parent.hide(nodeBefore, model, true);
    }
    nodeAfter.build();
    nodeBefore.findConnections();
    nodeAfter.filter(model.filterLevel);
    TreeNode[] nodePath = nodeAfter.getPath();
    mep.panelEquations.updateOrder(nodePath);
    // Will include nodeStructureChanged(), if necessary.
    mep.panelEquations.updateVisibility(nodePath);
}
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) TreeNode(javax.swing.tree.TreeNode) CannotRedoException(javax.swing.undo.CannotRedoException) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 7 with NodePart

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

the class ChangeVariableToInherit method undo.

public void undo() {
    super.undo();
    NodePart parent = (NodePart) NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    // Update the database
    MPart mparent = parent.source;
    mparent.clear("$inherit");
    String nameBefore = treeBefore.key();
    mparent.set(nameBefore, "").merge(treeBefore);
    // Update the GUI
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    parent.build();
    parent.findConnections();
    parent.filter(model.filterLevel);
    if (parent.visible(model.filterLevel))
        model.nodeStructureChanged(parent);
    TreeNode[] nodePath = parent.child(nameBefore).getPath();
    mep.panelEquations.updateOrder(nodePath);
    mep.panelEquations.updateVisibility(nodePath);
}
Also used : PanelModel(gov.sandia.n2a.ui.eq.PanelModel) MPart(gov.sandia.n2a.eqset.MPart) JTree(javax.swing.JTree) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 8 with NodePart

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

the class Outsource method apply.

public void apply(MNode subtree) {
    // Retrieve created node
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodePart node = (NodePart) parent.child(name);
    if (node == null)
        throw new CannotRedoException();
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    // Update database
    // remove all children
    node.source.clear();
    node.source.merge(subtree);
    // Update GUI
    node.build();
    node.findConnections();
    node.filter(model.filterLevel);
    // The caller of this Undoable promises to only use it on top-level nodes.
    // Thus, node retains exactly the same visibility as before, so no need for full update.
    // There are some obscure cases in which this doesn't hold (node was inherited, and the
    // new value of $inherit matches the inherited value of node.$inherit, so node ceases to be top-level),
    // but we won't worry about that.
    model.nodeStructureChanged(node);
    TreePath nodePath = new TreePath(node.getPath());
    tree.setSelectionPath(nodePath);
    if (wasExpanded)
        tree.expandPath(nodePath);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) CannotRedoException(javax.swing.undo.CannotRedoException) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 9 with NodePart

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

the class FilteredTreeModel method setFilterLevel.

public void setFilterLevel(int value, JTree tree) {
    filterLevel = value;
    if (root == null)
        return;
    NodePart r = (NodePart) root;
    r.filter(filterLevel);
    StoredPath path = new StoredPath(tree);
    reload(root);
    path.restore(tree);
}
Also used : NodePart(gov.sandia.n2a.ui.eq.tree.NodePart)

Example 10 with NodePart

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

the class AddAnnotation method destroy.

public static void destroy(List<String> path, boolean canceled, String name, String blockName) {
    // Retrieve created node
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    NodeBase container = parent;
    if (parent instanceof NodePart)
        container = parent.child(blockName);
    NodeBase createdNode = container.child(name);
    PanelEquationTree pet = PanelModel.instance.panelEquations;
    JTree tree = pet.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    FontMetrics fm = createdNode.getFontMetrics(tree);
    boolean containerIsVisible = true;
    TreeNode[] createdPath = createdNode.getPath();
    int index = container.getIndexFiltered(createdNode);
    if (canceled)
        index--;
    MPart block = (MPart) parent.source.child(blockName);
    block.clear(name);
    if (// There is no overridden value, so this node goes away completely.
    block.child(name) == null) {
        model.removeNodeFromParent(createdNode);
        if (block.size() == 0) {
            // commit suicide
            parent.source.clear(blockName);
            if (parent instanceof NodePart) {
                model.removeNodeFromParent(container);
                // No need to update order, because we just destroyed $metadata, where order is stored.
                // No need to update tab stops in grandparent, because block nodes don't offer any tab stops.
                containerIsVisible = false;
            }
        }
    } else // Just exposed an overridden value, so update display.
    {
        if (// We are always visible, but our parent could disappear.
        container.visible(model.filterLevel)) {
            createdNode.updateColumnWidths(fm);
        } else {
            containerIsVisible = false;
        }
    }
    if (containerIsVisible) {
        container.updateTabStops(fm);
        container.allNodesChanged(model);
    }
    pet.updateVisibility(createdPath, index);
    if (path.size() == 1 && name.equals("lock"))
        pet.updateLock();
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) JTree(javax.swing.JTree) MPart(gov.sandia.n2a.eqset.MPart) FontMetrics(java.awt.FontMetrics) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Aggregations

NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)17 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)12 JTree (javax.swing.JTree)12 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)11 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)11 TreeNode (javax.swing.tree.TreeNode)11 MPart (gov.sandia.n2a.eqset.MPart)10 CannotRedoException (javax.swing.undo.CannotRedoException)7 CannotUndoException (javax.swing.undo.CannotUndoException)6 FontMetrics (java.awt.FontMetrics)4 ExtensionPoint (gov.sandia.n2a.plugins.ExtensionPoint)2 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)2 TreePath (javax.swing.tree.TreePath)2 MNode (gov.sandia.n2a.db.MNode)1 NodeAnnotation (gov.sandia.n2a.ui.eq.tree.NodeAnnotation)1 NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)1 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)1 Move (gov.sandia.n2a.ui.eq.undo.Move)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1