Search in sources :

Example 21 with PanelEquationTree

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

the class AddReference method destroy.

public static void destroy(List<String> path, boolean canceled, String name, boolean setSelection) {
    // Retrieve created node
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    NodeBase container = parent;
    if (parent instanceof NodePart)
        container = parent.child("$reference");
    NodeBase createdNode = container.child(name);
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
    boolean containerIsVisible = true;
    TreeNode[] createdPath = createdNode.getPath();
    int index = container.getIndexFiltered(createdNode);
    if (canceled)
        index--;
    MPart block = (MPart) parent.source.child("$reference");
    block.clear(name);
    if (// There is no overridden value, so this node goes away completely.
    block.child(name) == null) {
        model.removeNodeFromParent(createdNode);
        if (block.size() == 0) {
            // commit suicide
            parent.source.clear("$reference");
            if (parent instanceof NodePart) {
                model.removeNodeFromParent(container);
                pet.updateOrder(createdPath);
                // No need to update tab stops in grandparent, because block nodes don't offer any tab stops.
                containerIsVisible = false;
            }
        }
    } else // Just exposed an overridden value, so update display.
    {
        if (// We are always visible, but our parent could disappear.
        container.visible()) {
            createdNode.setUserObject();
        } else {
            containerIsVisible = false;
        }
    }
    if (containerIsVisible)
        container.invalidateColumns(null);
    pet.updateVisibility(createdPath, index, setSelection);
    if (containerIsVisible)
        container.allNodesChanged(model);
    pet.animate();
}
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) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 22 with PanelEquationTree

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

the class AddVariable method destroy.

public static void destroy(List<String> path, boolean canceled, String name, boolean setSelection) {
    // Retrieve created node
    NodePart parent = (NodePart) NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    NodeVariable createdNode = (NodeVariable) parent.child(name);
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = null;
    if (pet != null)
        model = (FilteredTreeModel) pet.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) {
        if (createdNode.isBinding) {
            if (parent.graph != null)
                parent.graph.killEdge(name);
            if (mparent.root() == mparent)
                PanelModel.instance.panelSearch.updateConnectors(mparent);
        }
        if (model == null)
            FilteredTreeModel.removeNodeFromParentStatic(createdNode);
        else
            model.removeNodeFromParent(createdNode);
        parent.findConnections();
    } else // Just exposed an overridden node
    {
        boolean wasBinding = createdNode.isBinding;
        createdNode.build();
        createdNode.findConnections();
        createdNode.filter();
        if (createdNode.isBinding != wasBinding) {
            parent.updateSubpartConnections();
            if (parent.graph != null) {
                if (createdNode.isBinding)
                    parent.graph.updateEdge(name, parent.connectionBindings.get(name));
                else
                    parent.graph.killEdge(name);
            }
            if (mparent.root() == mparent)
                PanelModel.instance.panelSearch.updateConnectors(mparent);
        }
    }
    // Actually, this could start at grandparent, because parent's pin structure hasn't changed. However, this is convenient and simple.
    parent.updatePins();
    if (pet != null) {
        parent.invalidateColumns(model);
        pet.updateOrder(createdPath);
        // includes nodeStructureChanged(), if necessary
        pet.updateVisibility(createdPath, index, setSelection);
        pet.animate();
    }
}
Also used : MPart(gov.sandia.n2a.eqset.MPart) 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) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 23 with PanelEquationTree

use of gov.sandia.n2a.ui.eq.PanelEquationTree 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, boolean multi) {
    NodePart parent = (NodePart) 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.childOrCreate(name);
    createdPart.merge(newPart);
    // Update GUI
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = null;
    if (pet != null)
        model = (FilteredTreeModel) pet.tree.getModel();
    boolean alreadyExists = createdNode != null;
    boolean wasBinding = alreadyExists && createdNode.isBinding;
    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("");
    if (!alreadyExists) {
        if (model == null)
            FilteredTreeModel.insertNodeIntoUnfilteredStatic(createdNode, parent, index);
        else
            model.insertNodeIntoUnfiltered(createdNode, parent, index);
    }
    TreeNode[] createdPath = createdNode.getPath();
    if (!nameIsGenerated) {
        createdNode.build();
        createdNode.filter();
        if (pet != null) {
            pet.updateOrder(createdPath);
            parent.invalidateColumns(model);
        }
        if (parent.updateVariableConnections())
            parent.updateSubpartConnections();
        if (createdNode.isBinding != wasBinding) {
            if (parent.graph != null) {
                if (createdNode.isBinding)
                    parent.graph.updateEdge(name, parent.connectionBindings.get(name));
                else
                    parent.graph.killEdge(name);
            }
            MPart mparent = parent.source;
            if (mparent.root() == mparent)
                PanelModel.instance.panelSearch.updateConnectors(mparent);
        }
        parent.updatePins();
    }
    if (pet != null) {
        pet.updateVisibility(createdPath, -2, !multi);
        if (multi)
            pet.tree.addSelectionPath(new TreePath(createdPath));
        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) TreeNode(javax.swing.tree.TreeNode) CannotRedoException(javax.swing.undo.CannotRedoException) NodeVariable(gov.sandia.n2a.ui.eq.tree.NodeVariable) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 24 with PanelEquationTree

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

the class ChangeCategory method apply.

public void apply(String key, List<String> selectionBefore, String categoryAfter, List<String> selectionAfter) {
    MNode doc = AppData.models.child(key);
    if (doc == null)
        throw new CannotUndoException();
    // Graph focus
    PanelSearch ps = PanelModel.instance.panelSearch;
    ps.lastSelection = selectionBefore;
    ps.takeFocus();
    // Update DB, and possibly equation tree.
    PanelEquations pe = PanelModel.instance.panelEquations;
    if (// direct to db
    doc != pe.record) {
        doc.set(categoryAfter, "$metadata", "gui", "category");
    } else // got through MPart
    {
        MNode source = pe.root.source;
        if (categoryAfter.isEmpty())
            source.clear("$metadata", "gui", "category");
        else
            source.set(categoryAfter, "$metadata", "gui", "category");
        PanelEquationTree pet = pe.root.getTree();
        FilteredTreeModel model = null;
        if (pet != null)
            model = (FilteredTreeModel) pet.tree.getModel();
        // See ChangeAnnotations for more general code.
        // To simplify things, we always rebuild the metadata block, even though that is often overkill.
        // For simplicity, assume this exists. DB models should always some metadata, such as "id". It is possible for the $metadata node to be deleted by user, so this is not guaranteed.
        NodeAnnotations metadataNode = (NodeAnnotations) pe.root.child("$metadata");
        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();
            pet.updateVisibility(path, -2, false);
            pet.animate();
        }
    }
    // Update search panel.
    ps.lastSelection = selectionAfter;
    // This will apply lastSelection when done.
    ps.search();
}
Also used : NodeAnnotations(gov.sandia.n2a.ui.eq.tree.NodeAnnotations) PanelSearch(gov.sandia.n2a.ui.eq.PanelSearch) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) PanelEquations(gov.sandia.n2a.ui.eq.PanelEquations) MNode(gov.sandia.n2a.db.MNode) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 25 with PanelEquationTree

use of gov.sandia.n2a.ui.eq.PanelEquationTree 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, boolean multi, boolean multiLast, boolean multiShared, boolean touchesPin) {
    NodePart parent = (NodePart) 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.childOrCreate(name);
    createdPart.merge(newPart);
    // Update GUI
    PanelEquations pe = PanelModel.instance.panelEquations;
    boolean graphParent = parent == pe.part;
    PanelEquationTree pet = graphParent ? null : parent.getTree();
    FilteredTreeModel model = null;
    if (pet != null)
        model = (FilteredTreeModel) pet.tree.getModel();
    PanelEquationGraph peg = pe.panelEquationGraph;
    boolean addGraphNode = false;
    if (createdNode == null) {
        addGraphNode = true;
        createdNode = new NodePart(createdPart);
        createdNode.hide = graphParent;
        if (index < 0)
            index = parent.getChildCount();
        if (model == null)
            FilteredTreeModel.insertNodeIntoUnfilteredStatic(createdNode, parent, index);
        else
            model.insertNodeIntoUnfiltered(createdNode, parent, index);
    }
    createdNode.build();
    // Other nodes besides immediate siblings can also refer to us, so to be strictly correct, should run findConnectins() on root of tree.
    parent.findConnections();
    createdNode.rebuildPins();
    createdNode.filter();
    // 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("");
    TreeNode[] createdPath = createdNode.getPath();
    if (pet == null) {
        if (!nameIsGenerated)
            PanelEquationTree.updateOrder(null, createdPath);
        PanelEquationTree.updateVisibility(null, createdPath, -2, false);
    } else {
        if (!nameIsGenerated)
            pet.updateOrder(createdPath);
        pet.updateVisibility(createdPath, -2, !multi);
        if (multi)
            pet.tree.addSelectionPath(new TreePath(createdPath));
        pet.animate();
    }
    if (graphParent) {
        if (addGraphNode) {
            peg.addPart(createdNode);
        } else // Existing graph node; content needs to be restructured.
        {
            PanelEquationTree subpet = createdNode.getTree();
            if (subpet != null) {
                FilteredTreeModel submodel = (FilteredTreeModel) subpet.tree.getModel();
                submodel.nodeStructureChanged(createdNode);
                subpet.animate();
            }
        }
        createdNode.hide = false;
        if (multi) {
            if (!multiShared)
                createdNode.graph.setSelected(true);
        } else {
            peg.clearSelection();
            createdNode.graph.takeFocusOnTitle();
        }
    }
    if (graphParent || touchesPin) {
        if (!multi || multiLast) {
            peg.updatePins();
            peg.reconnect();
            peg.repaint();
        }
    }
    return createdNode;
}
Also used : MPart(gov.sandia.n2a.eqset.MPart) PanelEquationGraph(gov.sandia.n2a.ui.eq.PanelEquationGraph) CannotRedoException(javax.swing.undo.CannotRedoException) PanelEquations(gov.sandia.n2a.ui.eq.PanelEquations) NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) 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

PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)31 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)29 TreeNode (javax.swing.tree.TreeNode)28 MPart (gov.sandia.n2a.eqset.MPart)25 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)24 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)19 CannotRedoException (javax.swing.undo.CannotRedoException)18 TreePath (javax.swing.tree.TreePath)13 CannotUndoException (javax.swing.undo.CannotUndoException)13 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)12 PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)11 PanelEquationGraph (gov.sandia.n2a.ui.eq.PanelEquationGraph)9 NodeContainer (gov.sandia.n2a.ui.eq.tree.NodeContainer)7 MNode (gov.sandia.n2a.db.MNode)6 NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)5 JTree (javax.swing.JTree)4 Variable (gov.sandia.n2a.eqset.Variable)3 NodeAnnotation (gov.sandia.n2a.ui.eq.tree.NodeAnnotation)3 NodeEquation (gov.sandia.n2a.ui.eq.tree.NodeEquation)3 EquationSet (gov.sandia.n2a.eqset.EquationSet)2