Search in sources :

Example 36 with FilteredTreeModel

use of gov.sandia.n2a.ui.eq.FilteredTreeModel 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 37 with FilteredTreeModel

use of gov.sandia.n2a.ui.eq.FilteredTreeModel 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 38 with FilteredTreeModel

use of gov.sandia.n2a.ui.eq.FilteredTreeModel 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 39 with FilteredTreeModel

use of gov.sandia.n2a.ui.eq.FilteredTreeModel 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 40 with FilteredTreeModel

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

the class NodeAnnotations method makeAdd.

@Override
public Undoable makeAdd(String type, JTree tree, MNode data, Point location) {
    if (type.isEmpty()) {
        FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
        if (model.getChildCount(this) == 0 || tree.isCollapsed(new TreePath(getPath())))
            type = "Variable";
        else
            type = "Annotation";
    }
    if (type.equals("Annotation")) {
        // Add a new annotation to our children
        int index = getChildCount() - 1;
        TreePath path = tree.getLeadSelectionPath();
        if (path != null) {
            NodeBase selected = (NodeBase) path.getLastPathComponent();
            // unfiltered index
            if (isNodeChild(selected))
                index = getIndex(selected);
        }
        index++;
        return new AddAnnotation(this, index, data);
    }
    return ((NodeBase) parent).makeAdd(type, tree, data, location);
}
Also used : AddAnnotation(gov.sandia.n2a.ui.eq.undo.AddAnnotation) TreePath(javax.swing.tree.TreePath) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel) Point(java.awt.Point)

Aggregations

FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)46 MPart (gov.sandia.n2a.eqset.MPart)34 TreeNode (javax.swing.tree.TreeNode)31 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)29 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)28 CannotRedoException (javax.swing.undo.CannotRedoException)21 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)18 TreePath (javax.swing.tree.TreePath)18 CannotUndoException (javax.swing.undo.CannotUndoException)15 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)14 PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)11 JTree (javax.swing.JTree)10 PanelEquationGraph (gov.sandia.n2a.ui.eq.PanelEquationGraph)9 NodeContainer (gov.sandia.n2a.ui.eq.tree.NodeContainer)9 Variable (gov.sandia.n2a.eqset.Variable)8 MNode (gov.sandia.n2a.db.MNode)7 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)6 NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)6 FontMetrics (java.awt.FontMetrics)6 Point (java.awt.Point)6