Search in sources :

Example 1 with NodeReference

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

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

the class ChangeReference method undo.

public void undo() {
    super.undo();
    ChangeAnnotation.apply(path, nameAfter, nameBefore, valueBefore, "$reference", new NodeFactory() {

        public NodeBase create(MPart part) {
            return new NodeReference(part);
        }
    });
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) MPart(gov.sandia.n2a.eqset.MPart) NodeReference(gov.sandia.n2a.ui.eq.tree.NodeReference)

Example 3 with NodeReference

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

the class ChangeReference method redo.

public void redo() {
    super.redo();
    ChangeAnnotation.apply(path, nameBefore, nameAfter, valueAfter, "$reference", new NodeFactory() {

        public NodeBase create(MPart part) {
            return new NodeReference(part);
        }
    });
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) MPart(gov.sandia.n2a.eqset.MPart) NodeReference(gov.sandia.n2a.ui.eq.tree.NodeReference)

Example 4 with NodeReference

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

the class AddReference method create.

public static NodeBase create(List<String> path, int index, String name, String value, boolean multi) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    MPart block = (MPart) parent.source.childOrCreate("$reference");
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
    // If this is a variable, then mix metadata with equations and references
    NodeBase container = parent;
    if (// If this is a part, then display special block
    parent instanceof NodePart) {
        if (// empty implies the node is absent
        block.size() == 0) {
            container = new NodeReferences(block);
            model.insertNodeIntoUnfiltered(container, parent, index);
            index = 0;
        } else // the node is present, so retrieve it
        {
            container = parent.child("$reference");
        }
    }
    NodeBase createdNode = container.child(name);
    boolean alreadyExists = createdNode != null;
    MPart createdPart = (MPart) block.set(value, name);
    if (!alreadyExists)
        createdNode = new NodeReference(createdPart);
    // pure create, so about to go into edit mode. This should only happen on first application of the create action, and should only be possible if visibility is already correct.
    if (value == null)
        createdNode.setUserObject("");
    if (!alreadyExists)
        model.insertNodeIntoUnfiltered(createdNode, container, index);
    if (// create was merged with change name/value
    value != null) {
        container.invalidateColumns(null);
        TreeNode[] createdPath = createdNode.getPath();
        pet.updateOrder(createdPath);
        pet.updateVisibility(createdPath, -2, !multi);
        if (multi)
            pet.tree.addSelectionPath(new TreePath(createdPath));
        container.allNodesChanged(model);
        pet.animate();
    }
    return createdNode;
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) MPart(gov.sandia.n2a.eqset.MPart) TreePath(javax.swing.tree.TreePath) NodeReference(gov.sandia.n2a.ui.eq.tree.NodeReference) TreeNode(javax.swing.tree.TreeNode) CannotRedoException(javax.swing.undo.CannotRedoException) NodeReferences(gov.sandia.n2a.ui.eq.tree.NodeReferences) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Aggregations

MPart (gov.sandia.n2a.eqset.MPart)4 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)4 NodeReference (gov.sandia.n2a.ui.eq.tree.NodeReference)4 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)2 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)2 TreeNode (javax.swing.tree.TreeNode)2 CannotRedoException (javax.swing.undo.CannotRedoException)2 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)1 NodeReferences (gov.sandia.n2a.ui.eq.tree.NodeReferences)1 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)1 TreePath (javax.swing.tree.TreePath)1