Search in sources :

Example 26 with MPart

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

the class AddVariable method create.

public static NodeBase create(List<String> path, int index, String name, MNode newPart, boolean nameIsGenerated) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodeBase n = parent.child(name);
    // Should be blocked by GUI constraints, but this defends against ill-formed model on clipboard.
    if (n != null && !(n instanceof NodeVariable))
        throw new CannotRedoException();
    NodeVariable createdNode = (NodeVariable) n;
    // Update database
    MPart createdPart = (MPart) parent.source.set(name, "");
    createdPart.merge(newPart);
    // Update GUI
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    boolean alreadyExists = createdNode != null;
    if (!alreadyExists)
        createdNode = new NodeVariable(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 (nameIsGenerated)
        createdNode.setUserObject("");
    FontMetrics fm = createdNode.getFontMetrics(tree);
    // preempt initialization
    createdNode.updateColumnWidths(fm);
    if (!alreadyExists)
        model.insertNodeIntoUnfiltered(createdNode, parent, index);
    TreeNode[] createdPath = createdNode.getPath();
    if (!nameIsGenerated) {
        createdNode.build();
        createdNode.findConnections();
        mep.panelEquations.updateOrder(createdPath);
        parent.updateTabStops(fm);
        parent.allNodesChanged(model);
    }
    mep.panelEquations.updateVisibility(createdPath);
    return createdNode;
}
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) 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)

Example 27 with MPart

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

the class AddVariable 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();
    NodeVariable createdNode = (NodeVariable) 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--;
    MPart mparent = parent.source;
    mparent.clear(name);
    if (// Node is fully deleted
    mparent.child(name) == null) {
        model.removeNodeFromParent(createdNode);
        ((NodePart) parent).findConnections();
    } else // Just exposed an overridden node
    {
        createdNode.build();
        createdNode.findConnections();
        createdNode.updateColumnWidths(fm);
    }
    parent.updateTabStops(fm);
    parent.allNodesChanged(model);
    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) FontMetrics(java.awt.FontMetrics) TreeNode(javax.swing.tree.TreeNode) NodeVariable(gov.sandia.n2a.ui.eq.tree.NodeVariable) CannotUndoException(javax.swing.undo.CannotUndoException) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 28 with MPart

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

the class ChangeAnnotation method redo.

public void redo() {
    super.redo();
    apply(path, nameBefore, nameAfter, valueAfter, "$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 29 with MPart

use of gov.sandia.n2a.eqset.MPart 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 30 with MPart

use of gov.sandia.n2a.eqset.MPart 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)

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