Search in sources :

Example 1 with PanelModel

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

the class NodeBase method locateNode.

public static NodeBase locateNode(List<String> path) {
    MNode doc = AppData.models.child(path.get(0));
    PanelModel mep = PanelModel.instance;
    // lazy; only loads if not already loaded
    mep.panelEquations.loadRootFromDB(doc);
    // likewise, focus only moves if it is not already on equation tree
    mep.panelEquations.tree.requestFocusInWindow();
    NodeBase parent = mep.panelEquations.root;
    for (int i = 1; i < path.size(); i++) {
        // not filtered, because we are concerned with maintaining the model, not the view
        parent = (NodeBase) parent.child(path.get(i));
        if (parent == null)
            break;
    }
    return parent;
}
Also used : PanelModel(gov.sandia.n2a.ui.eq.PanelModel) MNode(gov.sandia.n2a.db.MNode)

Example 2 with PanelModel

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

the class AddDoc method destroy.

public static int destroy(String name, boolean fromSearchPanel) {
    MNode doc = AppData.models.child(name);
    PanelModel mep = PanelModel.instance;
    mep.panelEquations.recordDeleted(doc);
    mep.panelMRU.removeDoc(doc);
    int result = mep.panelSearch.removeDoc(doc);
    String id = doc.get("$metadata", "id");
    if (!id.isEmpty())
        AppData.set(id, null);
    ((MDoc) doc).delete();
    mep.panelSearch.lastSelection = Math.min(mep.panelSearch.model.size() - 1, result);
    if (fromSearchPanel) {
        mep.panelSearch.list.setSelectedIndex(mep.panelSearch.lastSelection);
        mep.panelSearch.list.requestFocusInWindow();
    } else {
        mep.panelEquations.tree.requestFocusInWindow();
    }
    return result;
}
Also used : PanelModel(gov.sandia.n2a.ui.eq.PanelModel) MNode(gov.sandia.n2a.db.MNode) MDoc(gov.sandia.n2a.db.MDoc)

Example 3 with PanelModel

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

the class ChangeEquation method apply.

public static void apply(List<String> path, String nameBefore, String nameAfter, String combinerAfter, String valueAfter) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodeBase nodeBefore = parent.child(nameBefore);
    if (nodeBefore == null)
        throw new CannotRedoException();
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    FontMetrics fm = nodeBefore.getFontMetrics(tree);
    NodeBase nodeAfter;
    if (nameBefore.equals(nameAfter)) {
        nodeAfter = nodeBefore;
        nodeAfter.source.set(valueAfter);
    } else {
        // Update the database
        MPart mparent = parent.source;
        MPart newPart = (MPart) mparent.set(nameAfter, valueAfter);
        mparent.clear(nameBefore);
        MPart oldPart = (MPart) mparent.child(nameBefore);
        // Update GUI
        nodeAfter = parent.child(nameAfter);
        if (oldPart == null) {
            if (nodeAfter == null) {
                nodeAfter = nodeBefore;
                nodeAfter.source = newPart;
            } else {
                model.removeNodeFromParent(nodeBefore);
            }
        } else {
            if (nodeAfter == null) {
                int index = parent.getIndex(nodeBefore);
                nodeAfter = new NodeEquation(newPart);
                model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
            }
            if (nodeBefore.visible(model.filterLevel))
                model.nodeChanged(nodeBefore);
            else
                parent.hide(nodeBefore, model, true);
        }
    }
    if (parent.getChildCount() > 0) {
        NodeBase firstChild = (NodeBase) parent.getChildAt(0);
        if (firstChild.needsInitTabs())
            firstChild.initTabs(fm);
    }
    if (!parent.source.get().equals(combinerAfter)) {
        parent.source.set(combinerAfter);
        parent.updateColumnWidths(fm);
        NodeBase grandparent = (NodeBase) parent.getParent();
        grandparent.updateTabStops(fm);
        grandparent.allNodesChanged(model);
    }
    nodeAfter.updateColumnWidths(fm);
    parent.updateTabStops(fm);
    parent.allNodesChanged(model);
    mep.panelEquations.updateVisibility(nodeAfter.getPath());
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) NodeEquation(gov.sandia.n2a.ui.eq.tree.NodeEquation) JTree(javax.swing.JTree) MPart(gov.sandia.n2a.eqset.MPart) FontMetrics(java.awt.FontMetrics) CannotRedoException(javax.swing.undo.CannotRedoException) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 4 with PanelModel

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

the class Move method apply.

public static void apply(List<String> path, int indexBefore, int indexAfter, int indexMetadata, boolean createOrder, boolean destroyOrder) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    NodeBase moveNode = (NodeBase) parent.getChildAt(indexBefore);
    model.removeNodeFromParent(moveNode);
    NodeBase metadataNode = parent.child("$metadata");
    if (createOrder) {
        if (metadataNode == null) {
            metadataNode = new NodeAnnotations((MPart) parent.source.set("$metadata", ""));
            model.insertNodeIntoUnfiltered(metadataNode, parent, indexMetadata);
        }
        NodeBase orderNode = new NodeAnnotation((MPart) metadataNode.source.set("gui.order", ""));
        model.insertNodeIntoUnfiltered(orderNode, metadataNode, metadataNode.getChildCount());
    }
    if (destroyOrder) {
        NodeBase orderNode = metadataNode.child("gui.order");
        FontMetrics fm = orderNode.getFontMetrics(tree);
        metadataNode.source.clear("gui.order");
        model.removeNodeFromParent(metadataNode.child("gui.order"));
        if (metadataNode.getChildCount() == 0) {
            parent.source.clear("$metadata");
            model.removeNodeFromParent(metadataNode);
        } else {
            metadataNode.updateTabStops(fm);
            metadataNode.allNodesChanged(model);
        }
    }
    model.insertNodeIntoUnfiltered(moveNode, parent, indexAfter);
    TreeNode[] movePath = moveNode.getPath();
    if (!destroyOrder)
        mep.panelEquations.updateOrder(movePath);
    mep.panelEquations.updateVisibility(movePath);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) JTree(javax.swing.JTree) NodeAnnotations(gov.sandia.n2a.ui.eq.tree.NodeAnnotations) MPart(gov.sandia.n2a.eqset.MPart) NodeAnnotation(gov.sandia.n2a.ui.eq.tree.NodeAnnotation) FontMetrics(java.awt.FontMetrics) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 5 with PanelModel

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

the class AddDoc method destroy.

public static void destroy(String name, List<String> pathAfter, boolean fromSearchPanel) {
    MNode doc = AppData.models.child(name);
    String id = doc.get("$metadata", "id");
    if (!id.isEmpty())
        AppData.set(id, null);
    // Triggers PanelModel.childDeleted(name), which removes doc from all 3 sub-panels.
    AppData.models.clear(name);
    PanelModel pm = PanelModel.instance;
    if (fromSearchPanel)
        pm.panelSearch.forceSelection(pathAfter);
// else leave the focus wherever it's at. We shift focus to make user aware of the delete, but this is only meaningful in the search list.
}
Also used : PanelModel(gov.sandia.n2a.ui.eq.PanelModel) MNode(gov.sandia.n2a.db.MNode)

Aggregations

PanelModel (gov.sandia.n2a.ui.eq.PanelModel)13 MPart (gov.sandia.n2a.eqset.MPart)8 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)6 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)6 JTree (javax.swing.JTree)6 MNode (gov.sandia.n2a.db.MNode)4 FontMetrics (java.awt.FontMetrics)4 CannotRedoException (javax.swing.undo.CannotRedoException)4 MDoc (gov.sandia.n2a.db.MDoc)3 TreeNode (javax.swing.tree.TreeNode)3 NodeContainer (gov.sandia.n2a.ui.eq.tree.NodeContainer)2 NodeEquation (gov.sandia.n2a.ui.eq.tree.NodeEquation)2 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)2 CannotUndoException (javax.swing.undo.CannotUndoException)2 Variable (gov.sandia.n2a.eqset.Variable)1 PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)1 NodeAnnotation (gov.sandia.n2a.ui.eq.tree.NodeAnnotation)1 NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)1