Search in sources :

Example 6 with MPart

use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.

the class AddEquation method destroy.

public static void destroy(List<String> path, int equationCount, boolean canceled, String name, String combinerBefore) {
    // Retrieve created node
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    NodeBase createdNode = parent.child(name);
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    FontMetrics fm = createdNode.getFontMetrics(tree);
    TreeNode[] createdPath = createdNode.getPath();
    int index = parent.getIndexFiltered(createdNode);
    if (canceled)
        index--;
    // Update database
    MPart mparent = parent.source;
    mparent.clear(name);
    boolean parentChanged = false;
    if (!mparent.get().equals(combinerBefore)) {
        // This value may be replaced below if we switch back to single-line.
        mparent.set(combinerBefore);
        parentChanged = true;
    }
    if (// There is no overridden value, so this node goes away completely.
    mparent.child(name) == null) {
        model.removeNodeFromParent(createdNode);
        if (// The node used to be single-line, so fold the last equation back into it.
        equationCount == 0) {
            NodeEquation lastEquation = null;
            // unfiltered
            Enumeration<?> i = parent.children();
            while (i.hasMoreElements()) {
                Object o = i.nextElement();
                if (o instanceof NodeEquation) {
                    lastEquation = (NodeEquation) o;
                    break;
                }
            }
            String lastCondition = lastEquation.source.key();
            String lastExpression = lastEquation.source.get();
            mparent.clear(lastCondition);
            if (lastCondition.equals("@"))
                mparent.set(combinerBefore + lastExpression);
            else
                mparent.set(combinerBefore + lastExpression + lastCondition);
            parentChanged = true;
            model.removeNodeFromParent(lastEquation);
        }
    } else // Just exposed an overridden value, so update display.
    {
        createdNode.updateColumnWidths(fm);
    }
    if (// Update tabs among this variable's siblings
    parentChanged) {
        parent.updateColumnWidths(fm);
        NodeBase grandparent = (NodeBase) parent.getParent();
        grandparent.updateTabStops(fm);
        grandparent.allNodesChanged(model);
    }
    parent.updateTabStops(fm);
    parent.allNodesChanged(model);
    mep.panelEquations.updateOrder(createdPath);
    mep.panelEquations.updateVisibility(createdPath, index);
}
Also used : MPart(gov.sandia.n2a.eqset.MPart) NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) NodeEquation(gov.sandia.n2a.ui.eq.tree.NodeEquation) JTree(javax.swing.JTree) FontMetrics(java.awt.FontMetrics) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 7 with MPart

use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.

the class AddPart method destroy.

public static void destroy(List<String> path, boolean canceled, String name) {
    // Retrieve created node
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    NodePart createdNode = (NodePart) parent.child(name);
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    TreeNode[] createdPath = createdNode.getPath();
    int index = parent.getIndexFiltered(createdNode);
    if (canceled)
        index--;
    MPart mparent = parent.source;
    mparent.clear(name);
    if (// Node is fully deleted
    mparent.child(name) == null) {
        model.removeNodeFromParent(createdNode);
    } else // Just exposed an overridden node
    {
        createdNode.build();
        createdNode.findConnections();
        createdNode.filter(model.filterLevel);
    }
    mep.panelEquations.updateOrder(createdPath);
    // includes nodeStructureChanged(), if necessary
    mep.panelEquations.updateVisibility(createdPath, 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) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 8 with MPart

use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.

the class ChangeAnnotation method apply.

public static void apply(List<String> path, String nameBefore, String nameAfter, String valueAfter, String blockName, NodeFactory factory) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodeBase nodeBefore = parent.child(nameBefore);
    if (nodeBefore == null)
        throw new CannotRedoException();
    PanelEquationTree pet = PanelModel.instance.panelEquations;
    JTree tree = pet.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    FontMetrics fm = nodeBefore.getFontMetrics(tree);
    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(blockName);
        else
            mparent = parent.source;
        // should directly change destinationNode if it exists
        MPart newPart = (MPart) mparent.set(nameAfter, valueAfter);
        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 = factory.create(newPart);
                model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
            }
        }
    }
    nodeAfter.updateColumnWidths(fm);
    parent.updateTabStops(fm);
    parent.allNodesChanged(model);
    TreeNode[] nodePath = nodeAfter.getPath();
    pet.updateOrder(nodePath);
    pet.updateVisibility(nodePath);
    // Only an inherited lock node can be touched by editing. It is possible to activate (make local) if the user assigns a specific value to it.
    if (path.size() == 2 && path.get(1).equals("$metadata") && (nameBefore.equals("lock") || nameAfter.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) 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 9 with MPart

use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.

the class ChangeAnnotation method undo.

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

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

Example 10 with MPart

use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.

the class ChangeEquation method apply.

public static void apply(List<String> path, String nameBefore, String nameAfter, String combinerAfter, String valueAfter) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodeBase nodeBefore = 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);
    NodeBase nodeAfter;
    if (nameBefore.equals(nameAfter)) {
        nodeAfter = nodeBefore;
        nodeAfter.source.set(valueAfter);
    } else {
        // Update the database
        MPart mparent = parent.source;
        MPart newPart = (MPart) mparent.set(nameAfter, valueAfter);
        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 NodeEquation(newPart);
                model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
            }
            if (nodeBefore.visible(model.filterLevel))
                model.nodeChanged(nodeBefore);
            else
                parent.hide(nodeBefore, model, true);
        }
    }
    if (parent.getChildCount() > 0) {
        NodeBase firstChild = (NodeBase) parent.getChildAt(0);
        if (firstChild.needsInitTabs())
            firstChild.initTabs(fm);
    }
    if (!parent.source.get().equals(combinerAfter)) {
        parent.source.set(combinerAfter);
        parent.updateColumnWidths(fm);
        NodeBase grandparent = (NodeBase) parent.getParent();
        grandparent.updateTabStops(fm);
        grandparent.allNodesChanged(model);
    }
    nodeAfter.updateColumnWidths(fm);
    parent.updateTabStops(fm);
    parent.allNodesChanged(model);
    mep.panelEquations.updateVisibility(nodeAfter.getPath());
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) NodeEquation(gov.sandia.n2a.ui.eq.tree.NodeEquation) JTree(javax.swing.JTree) MPart(gov.sandia.n2a.eqset.MPart) FontMetrics(java.awt.FontMetrics) CannotRedoException(javax.swing.undo.CannotRedoException) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Aggregations

MPart (gov.sandia.n2a.eqset.MPart)37 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)21 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)20 JTree (javax.swing.JTree)18 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)16 TreeNode (javax.swing.tree.TreeNode)15 FontMetrics (java.awt.FontMetrics)13 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)10 CannotRedoException (javax.swing.undo.CannotRedoException)10 CannotUndoException (javax.swing.undo.CannotUndoException)9 MNode (gov.sandia.n2a.db.MNode)5 EquationSet (gov.sandia.n2a.eqset.EquationSet)5 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)5 Variable (gov.sandia.n2a.eqset.Variable)4 ArrayList (java.util.ArrayList)4 ParseException (gov.sandia.n2a.language.ParseException)3 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)3 NodeAnnotation (gov.sandia.n2a.ui.eq.tree.NodeAnnotation)3 NodeEquation (gov.sandia.n2a.ui.eq.tree.NodeEquation)3 IncommensurableException (javax.measure.IncommensurableException)3