Search in sources :

Example 11 with NodePart

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

the class AddInherit method destroy.

public static void destroy(List<String> path, boolean canceled) {
    NodePart parent = (NodePart) NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    NodeBase node = parent.child("$inherit");
    TreeNode[] nodePath = node.getPath();
    int index = parent.getIndexFiltered(node);
    if (canceled)
        index--;
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    MPart mparent = parent.source;
    // Complex restructuring happens here.
    mparent.clear("$inherit");
    // Handles all cases (complete deletion or exposed hidden node)
    parent.build();
    parent.findConnections();
    parent.filter(model.filterLevel);
    if (parent.visible(model.filterLevel))
        model.nodeStructureChanged(parent);
    mep.panelEquations.updateOrder(nodePath);
    mep.panelEquations.updateVisibility(nodePath, 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 12 with NodePart

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

the class AddPart 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 NodePart))
        throw new CannotUndoException();
    NodePart createdNode = (NodePart) 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();
    if (createdNode == null) {
        createdNode = new NodePart(createdPart);
        model.insertNodeIntoUnfiltered(createdNode, parent, index);
    }
    createdNode.build();
    createdNode.findConnections();
    createdNode.filter(model.filterLevel);
    TreeNode[] createdPath = createdNode.getPath();
    if (// 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.
    nameIsGenerated)
        // 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.
        createdNode.setUserObject("");
    else
        mep.panelEquations.updateOrder(createdPath);
    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) TreeNode(javax.swing.tree.TreeNode) CannotRedoException(javax.swing.undo.CannotRedoException) CannotUndoException(javax.swing.undo.CannotUndoException) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 13 with NodePart

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

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

the class ChangeInherit method apply.

public void apply(String value) {
    NodeBase node = NodeBase.locateNode(path);
    if (node == null)
        throw new CannotRedoException();
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    // Complex restructuring happens here.
    node.source.set(value);
    NodePart parent = (NodePart) node.getParent();
    parent.build();
    parent.findConnections();
    parent.filter(model.filterLevel);
    if (parent.visible(model.filterLevel))
        model.nodeStructureChanged(parent);
    TreeNode[] nodePath = parent.child("$inherit").getPath();
    mep.panelEquations.updateOrder(nodePath);
    mep.panelEquations.updateVisibility(nodePath);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) 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 15 with NodePart

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

the class ChangeVariableToInherit method redo.

public void redo() {
    super.redo();
    NodePart parent = (NodePart) NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    // Update database
    MPart mparent = parent.source;
    mparent.clear(treeBefore.key());
    mparent.set("$inherit", valueAfter);
    // Update GUI
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    parent.build();
    parent.findConnections();
    parent.filter(model.filterLevel);
    model.nodeStructureChanged(parent);
    TreeNode[] nodePath = parent.child("$inherit").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) CannotRedoException(javax.swing.undo.CannotRedoException) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) 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