Search in sources :

Example 1 with NodePart

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

the class PanelEquationTree method updateOrder.

/**
 *        Records the current order of nodes in "gui.order", provided that metadata field exists.
 *        Otherwise, we assume the user doesn't care.
 *        @param path To the node that changed (added, deleted, moved). In general, this node's
 *        parent will be the part that is tracking the order of its children.
 */
public void updateOrder(TreeNode[] path) {
    NodePart parent = null;
    for (int i = path.length - 2; i >= 0; i--) {
        if (path[i] instanceof NodePart) {
            parent = (NodePart) path[i];
            break;
        }
    }
    // This should never happen, because root of tree is a NodePart.
    if (parent == null)
        return;
    // Find $metadata/gui.order for the currently selected node. If it exists, update it.
    // Note that this is a modified version of moveSelected() which does not actually move
    // anything, and which only modifies an existing $metadata/gui.order, not create a new one.
    NodeAnnotations metadataNode = null;
    String order = null;
    Enumeration<?> i = parent.children();
    while (i.hasMoreElements()) {
        NodeBase c = (NodeBase) i.nextElement();
        String key = c.source.key();
        if (order == null)
            order = key;
        else
            order = order + "," + key;
        if (key.equals("$metadata"))
            metadataNode = (NodeAnnotations) c;
    }
    if (metadataNode == null)
        return;
    i = metadataNode.children();
    while (i.hasMoreElements()) {
        NodeAnnotation a = (NodeAnnotation) i.nextElement();
        if (a.source.key().equals("gui.order")) {
            a.source.set(order);
            FontMetrics fm = a.getFontMetrics(tree);
            metadataNode.updateTabStops(fm);
            model.nodeChanged(a);
            break;
        }
    }
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) NodeAnnotations(gov.sandia.n2a.ui.eq.tree.NodeAnnotations) NodeAnnotation(gov.sandia.n2a.ui.eq.tree.NodeAnnotation) FontMetrics(java.awt.FontMetrics) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) ExtensionPoint(gov.sandia.n2a.plugins.ExtensionPoint)

Example 2 with NodePart

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

the class AddAnnotation method create.

public static NodeBase create(List<String> path, int index, String name, String value, String blockName, NodeFactory factory, NodeFactory factoryBlock) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    MPart block = (MPart) parent.source.childOrCreate(blockName);
    PanelEquationTree pet = PanelModel.instance.panelEquations;
    JTree tree = pet.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    // If this is a variable, then mix metadata with equations and references
    NodeBase container = parent;
    if (// If this is a part, then display special block
    parent instanceof NodePart) {
        if (// empty implies the node is absent
        block.size() == 0) {
            container = factoryBlock.create(block);
            model.insertNodeIntoUnfiltered(container, parent, index);
            index = 0;
        } else // the node is present, so retrieve it
        {
            container = parent.child(blockName);
        }
    }
    NodeBase createdNode = container.child(name);
    boolean alreadyExists = createdNode != null;
    MPart createdPart = (MPart) block.set(name, value);
    if (!alreadyExists)
        createdNode = factory.create(createdPart);
    FontMetrics fm = createdNode.getFontMetrics(tree);
    if (container.getChildCount() > 0) {
        NodeBase firstChild = (NodeBase) container.getChildAt(0);
        if (firstChild.needsInitTabs())
            firstChild.initTabs(fm);
    }
    // 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 (value == null)
        createdNode.setUserObject("");
    // preempt initialization; uses actual name, not user value
    createdNode.updateColumnWidths(fm);
    if (!alreadyExists)
        model.insertNodeIntoUnfiltered(createdNode, container, index);
    if (// create was merged with change name/value
    value != null) {
        container.updateTabStops(fm);
        container.allNodesChanged(model);
        TreeNode[] createdPath = createdNode.getPath();
        pet.updateOrder(createdPath);
        pet.updateVisibility(createdPath);
        if (path.size() == 1 && name.equals("lock"))
            pet.updateLock();
    }
    return createdNode;
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) MPart(gov.sandia.n2a.eqset.MPart) JTree(javax.swing.JTree) FontMetrics(java.awt.FontMetrics) TreeNode(javax.swing.tree.TreeNode) CannotRedoException(javax.swing.undo.CannotRedoException) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 3 with NodePart

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

the class FilteredTreeModel method setFilterLevel.

public void setFilterLevel(int value, JTree tree) {
    filterLevel = value;
    if (root == null)
        return;
    NodePart r = (NodePart) root;
    r.filter(filterLevel);
    StoredPath path = new StoredPath(tree);
    reload(root);
    path.restore(tree);
}
Also used : NodePart(gov.sandia.n2a.ui.eq.tree.NodePart)

Example 4 with NodePart

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

the class AddInherit method create.

public static void create(List<String> path, String value) {
    NodePart parent = (NodePart) NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodePart grandparent = (NodePart) parent.getTrueParent();
    PanelEquations pe = PanelModel.instance.panelEquations;
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
    PanelEquationGraph peg = pe.panelEquationGraph;
    parent.source.set(value, "$inherit");
    parent.build();
    if (grandparent == null)
        parent.findConnections();
    else
        grandparent.findConnections();
    parent.rebuildPins();
    parent.filter();
    if (parent == pe.part) {
        peg.reloadPart();
        parent.filter();
    }
    // Since $inherit is being added, parent will almost certainly become visible, if it's not already.
    model.nodeStructureChanged(parent);
    TreeNode[] createdPath = parent.child("$inherit").getPath();
    pet.updateOrder(createdPath);
    pet.updateVisibility(createdPath);
    pet.animate();
    if (parent != pe.part) {
        peg.updatePins();
        peg.reconnect();
        peg.repaint();
    }
    if (// root node, so update categories in search list
    parent.getTrueParent() == null) {
        PanelModel.instance.panelSearch.search();
    }
}
Also used : PanelEquationGraph(gov.sandia.n2a.ui.eq.PanelEquationGraph) TreeNode(javax.swing.tree.TreeNode) CannotRedoException(javax.swing.undo.CannotRedoException) PanelEquations(gov.sandia.n2a.ui.eq.PanelEquations) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 5 with NodePart

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

the class AddPart method destroy.

public static void destroy(List<String> path, boolean canceled, String name, boolean setSelected, boolean multiShared, boolean touchesPin) {
    // Retrieve created node
    NodePart parent = (NodePart) NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    NodePart createdNode = (NodePart) parent.child(name);
    PanelEquations pe = PanelModel.instance.panelEquations;
    boolean graphParent = parent == pe.part;
    // Only use tree if it is not the graph parent, since graph parent hides its sub-parts.
    PanelEquationTree pet = graphParent ? null : parent.getTree();
    FilteredTreeModel model = null;
    if (pet != null)
        model = (FilteredTreeModel) pet.tree.getModel();
    // only used if graphParent is true
    PanelEquationGraph peg = pe.panelEquationGraph;
    TreeNode[] createdPath = createdNode.getPath();
    // returns -1 if createdNode is filtered out of parent
    int index = parent.getIndexFiltered(createdNode);
    if (canceled)
        index--;
    MPart mparent = parent.source;
    mparent.clear(name);
    if (// Node is fully deleted
    mparent.child(name) == null) {
        pe.deleteFocus(createdNode);
        if (model == null)
            FilteredTreeModel.removeNodeFromParentStatic(createdNode);
        else
            model.removeNodeFromParent(createdNode);
        if (graphParent)
            peg.removePart(createdNode, setSelected && !multiShared);
        parent.findConnections();
        parent.updatePins();
    } else // Just exposed an overridden node
    {
        // Does not change the fake-root status of this node.
        createdNode.build();
        parent.findConnections();
        createdNode.rebuildPins();
        createdNode.filter();
        if (// Need to update entire model under fake root.
        graphParent) {
            PanelEquationTree subpet = createdNode.getTree();
            if (subpet != null) {
                FilteredTreeModel submodel = (FilteredTreeModel) subpet.tree.getModel();
                submodel.nodeStructureChanged(createdNode);
                subpet.animate();
            }
            // Implicitly, the title of the node was focused when the part was deleted, so ensure it gets the focus back.
            if (setSelected && !multiShared)
                createdNode.graph.takeFocusOnTitle();
        }
    }
    pe.resetBreadcrumbs();
    if (pet == null) {
        PanelEquationTree.updateOrder(null, createdPath);
        PanelEquationTree.updateVisibility(null, createdPath, index, false);
    } else {
        pet.updateOrder(createdPath);
        // includes nodeStructureChanged(), if necessary
        pet.updateVisibility(createdPath, index, setSelected);
        pet.animate();
    }
    if (graphParent || touchesPin) {
        peg.updatePins();
        peg.reconnect();
        peg.repaint();
    }
    if (graphParent) {
        if (pe.view == PanelEquations.NODE && peg.isEmpty())
            pe.panelParent.setOpen(true);
        if (setSelected && multiShared)
            pe.switchFocus(false, false);
    }
}
Also used : MPart(gov.sandia.n2a.eqset.MPart) PanelEquationGraph(gov.sandia.n2a.ui.eq.PanelEquationGraph) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) PanelEquations(gov.sandia.n2a.ui.eq.PanelEquations) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel) Point(java.awt.Point)

Aggregations

NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)33 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)21 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)19 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)18 MPart (gov.sandia.n2a.eqset.MPart)17 TreeNode (javax.swing.tree.TreeNode)16 PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)12 TreePath (javax.swing.tree.TreePath)11 CannotRedoException (javax.swing.undo.CannotRedoException)11 PanelEquationGraph (gov.sandia.n2a.ui.eq.PanelEquationGraph)10 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)10 CannotUndoException (javax.swing.undo.CannotUndoException)8 MNode (gov.sandia.n2a.db.MNode)7 NodeAnnotation (gov.sandia.n2a.ui.eq.tree.NodeAnnotation)5 NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)5 NodeContainer (gov.sandia.n2a.ui.eq.tree.NodeContainer)3 FontMetrics (java.awt.FontMetrics)3 Point (java.awt.Point)3 Rectangle (java.awt.Rectangle)3 ArrayList (java.util.ArrayList)3