Search in sources :

Example 16 with FilteredTreeModel

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

the class ChangeOrder method apply.

public void apply(int indexBefore, int indexAfter, int indexMetadata, boolean createOrder, boolean destroyOrder) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
    NodeBase moveNode = (NodeBase) parent.getChildAt(indexBefore);
    model.removeNodeFromParent(moveNode);
    NodeAnnotations metadataNode = (NodeAnnotations) parent.child("$metadata");
    boolean needBuild = false;
    if (createOrder) {
        if (metadataNode == null) {
            metadataNode = new NodeAnnotations((MPart) parent.source.childOrCreate("$metadata"));
            model.insertNodeIntoUnfiltered(metadataNode, parent, indexMetadata);
        }
        metadataNode.source.childOrCreate("gui", "order");
        needBuild = true;
    }
    if (destroyOrder) {
        MNode mparent = metadataNode.source;
        mparent.clear("gui", "order");
        if (mparent.child("gui").size() == 0)
            mparent.clear("gui");
        if (mparent.size() == 0) {
            parent.source.clear("$metadata");
            model.removeNodeFromParent(metadataNode);
        } else {
            needBuild = true;
        }
    }
    if (needBuild) {
        List<String> expanded = AddAnnotation.saveExpandedNodes(pet.tree, metadataNode);
        metadataNode.build();
        metadataNode.filter();
        if (metadataNode.visible()) {
            model.nodeStructureChanged(metadataNode);
            AddAnnotation.restoreExpandedNodes(pet.tree, metadataNode, expanded);
        }
    }
    model.insertNodeIntoUnfiltered(moveNode, parent, indexAfter);
    TreeNode[] movePath = moveNode.getPath();
    if (!destroyOrder)
        pet.updateOrder(movePath);
    pet.updateVisibility(movePath);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) NodeAnnotations(gov.sandia.n2a.ui.eq.tree.NodeAnnotations) MPart(gov.sandia.n2a.eqset.MPart) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel) MNode(gov.sandia.n2a.db.MNode)

Example 17 with FilteredTreeModel

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

the class ChangeReference method apply.

public void apply(String nameBefore, String nameAfter, String valueAfter) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodeBase nodeBefore = parent.child(nameBefore);
    if (nodeBefore == null)
        throw new CannotRedoException();
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
    NodeBase nodeAfter;
    if (nameBefore.equals(nameAfter)) {
        nodeAfter = nodeBefore;
        nodeAfter.source.set(valueAfter);
    } else {
        // Update database
        MPart mparent;
        if (parent instanceof NodeVariable)
            mparent = (MPart) parent.source.child("$reference");
        else
            mparent = parent.source;
        // should directly change destinationNode if it exists
        MPart newPart = (MPart) mparent.set(valueAfter, nameAfter);
        mparent.clear(nameBefore);
        MPart oldPart = (MPart) mparent.child(nameBefore);
        // Update GUI
        nodeAfter = 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 NodeReference(newPart);
                model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
            }
        }
    }
    nodeAfter.setUserObject();
    parent.invalidateColumns(null);
    TreeNode[] nodePath = nodeAfter.getPath();
    pet.updateOrder(nodePath);
    pet.updateVisibility(nodePath);
    parent.allNodesChanged(model);
    pet.animate();
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) MPart(gov.sandia.n2a.eqset.MPart) NodeReference(gov.sandia.n2a.ui.eq.tree.NodeReference) TreeNode(javax.swing.tree.TreeNode) CannotRedoException(javax.swing.undo.CannotRedoException) NodeVariable(gov.sandia.n2a.ui.eq.tree.NodeVariable) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 18 with FilteredTreeModel

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

the class AddAnnotations method destroy.

public static void destroy(List<String> path, String blockName, boolean setSelected, boolean touchesPin, boolean touchesCategory) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    // The only way to paste a $metadata block is if the tree is visible.
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = (FilteredTreeModel) pet.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();
    }
    pet.updateVisibility(nodePath, index, setSelected);
    pet.animate();
    if (blockName.equals("$metadata"))
        AddAnnotation.update(parent, touchesPin, touchesCategory);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) MPart(gov.sandia.n2a.eqset.MPart) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) NodeContainer(gov.sandia.n2a.ui.eq.tree.NodeContainer) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 19 with FilteredTreeModel

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

the class AddInherit method create.

public static void create(List<String> path, String value) {
    NodePart parent = (NodePart) NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodePart grandparent = (NodePart) parent.getTrueParent();
    PanelEquations pe = PanelModel.instance.panelEquations;
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
    PanelEquationGraph peg = pe.panelEquationGraph;
    parent.source.set(value, "$inherit");
    parent.build();
    if (grandparent == null)
        parent.findConnections();
    else
        grandparent.findConnections();
    parent.rebuildPins();
    parent.filter();
    if (parent == pe.part) {
        peg.reloadPart();
        parent.filter();
    }
    // Since $inherit is being added, parent will almost certainly become visible, if it's not already.
    model.nodeStructureChanged(parent);
    TreeNode[] createdPath = parent.child("$inherit").getPath();
    pet.updateOrder(createdPath);
    pet.updateVisibility(createdPath);
    pet.animate();
    if (parent != pe.part) {
        peg.updatePins();
        peg.reconnect();
        peg.repaint();
    }
    if (// root node, so update categories in search list
    parent.getTrueParent() == null) {
        PanelModel.instance.panelSearch.search();
    }
}
Also used : PanelEquationGraph(gov.sandia.n2a.ui.eq.PanelEquationGraph) TreeNode(javax.swing.tree.TreeNode) CannotRedoException(javax.swing.undo.CannotRedoException) PanelEquations(gov.sandia.n2a.ui.eq.PanelEquations) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 20 with FilteredTreeModel

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

the class ChangeAnnotations method apply.

public void apply(MNode add, MNode remove) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = null;
    StoredPath sp = null;
    if (pet != null) {
        model = (FilteredTreeModel) pet.tree.getModel();
        sp = new StoredPath(pet.tree);
    }
    // The immediate container of metadata items in the tree.
    NodeContainer metadataNode;
    // The $metadata node under which all changes are made.
    MNode metadataSource = null;
    if (parent instanceof NodeVariable) {
        metadataNode = (NodeContainer) parent;
        metadataSource = metadataNode.source.child("$metadata");
    } else // NodePart is the default case
    {
        metadataNode = (NodeContainer) parent.child("$metadata");
        if (metadataNode != null)
            metadataSource = metadataNode.source;
    }
    boolean needBuild = true;
    if (// This is an undo, and $metadata did not exist before, so remove it.
    add == null) {
        // We can safely assume that metadataSource is non-null, since we only get here during an undo.
        metadataSource.parent().clear("$metadata");
        if (parent instanceof NodePart) {
            if (model == null)
                FilteredTreeModel.removeNodeFromParentStatic(metadataNode);
            else
                model.removeNodeFromParent(metadataNode);
            needBuild = false;
        }
    } else // Update $metadata node. Create if it doesn't exist.
    {
        if (metadataSource == null)
            metadataSource = parent.source.childOrCreate("$metadata");
        if (// only happens when parent is NodePart
        metadataNode == null) {
            metadataNode = new NodeAnnotations((MPart) metadataSource);
            if (model == null)
                FilteredTreeModel.insertNodeIntoUnfilteredStatic(metadataNode, parent, index);
            else
                model.insertNodeIntoUnfiltered(metadataNode, parent, index);
        }
        if (remove != null)
            metadataSource.uniqueNodes(remove);
        metadataSource.merge(add);
    }
    if (needBuild) {
        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();
        PanelEquationTree.updateVisibility(pet, path, -2, !multi && !graph);
        if (// We only care about viewing metadata tree if edit happened in the tree, not graphically.
        !graph) {
            if (multi)
                pet.tree.addSelectionPath(new TreePath(path));
            else
                // This forces focus back to original location.
                sp.restore(pet.tree, true);
        }
        pet.animate();
    }
    if (multi && parent instanceof NodePart) {
        NodePart np = (NodePart) parent;
        if (np.graph != null)
            np.graph.setSelected(true);
    }
    AddAnnotation.update(parent, touchesPin, touchesCategory);
}
Also used : NodeAnnotations(gov.sandia.n2a.ui.eq.tree.NodeAnnotations) MPart(gov.sandia.n2a.eqset.MPart) NodeVariable(gov.sandia.n2a.ui.eq.tree.NodeVariable) NodeContainer(gov.sandia.n2a.ui.eq.tree.NodeContainer) MNode(gov.sandia.n2a.db.MNode) NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) StoredPath(gov.sandia.n2a.ui.eq.StoredPath) TreePath(javax.swing.tree.TreePath) 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

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