Search in sources :

Example 16 with NodePart

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

the class PanelEquationTree method moveSelected.

public void moveSelected(int direction) {
    if (locked)
        return;
    TreePath path = tree.getSelectionPath();
    if (path == null)
        return;
    NodeBase nodeBefore = (NodeBase) path.getLastPathComponent();
    NodeBase parent = (NodeBase) nodeBefore.getParent();
    if (// Only parts support $metadata.gui.order
    parent instanceof NodePart) {
        // First check if we can move in the filtered (visible) list.
        int indexBefore = model.getIndexOfChild(parent, nodeBefore);
        int indexAfter = indexBefore + direction;
        if (indexAfter >= 0 && indexAfter < model.getChildCount(parent)) {
            // Then convert to unfiltered indices.
            NodeBase nodeAfter = (NodeBase) model.getChild(parent, indexAfter);
            indexBefore = parent.getIndex(nodeBefore);
            indexAfter = parent.getIndex(nodeAfter);
            PanelModel.instance.undoManager.add(new Move((NodePart) parent, indexBefore, indexAfter));
        }
    }
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) TreePath(javax.swing.tree.TreePath) Move(gov.sandia.n2a.ui.eq.undo.Move) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) ExtensionPoint(gov.sandia.n2a.plugins.ExtensionPoint)

Example 17 with NodePart

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

the class PanelEquationTree method loadRootFromDB.

public void loadRootFromDB(MNode doc) {
    if (record == doc)
        return;
    if (record != null) {
        tree.stopEditing();
        // Save tree state for current record, but only if it's better than the previously-saved state.
        if (focusCache.get(record) == null || tree.getSelectionPath() != null)
            focusCache.put(record, new StoredPath(tree));
    }
    record = doc;
    try {
        root = new NodePart(new MPart((MPersistent) record));
        root.build();
        root.findConnections();
        // triggers repaint, but may be too slow
        model.setRoot(root);
        updateLock();
        // next call to repaintSouth() will repaint everything
        needsFullRepaint = true;
        StoredPath sp = focusCache.get(record);
        if (sp == null) {
            tree.expandRow(0);
            tree.setSelectionRow(0);
        } else {
            sp.restore(tree);
        }
    } catch (Exception e) {
        System.err.println("Exception while parsing model: " + e);
        e.printStackTrace();
    }
}
Also used : MPart(gov.sandia.n2a.eqset.MPart) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) ExpandVetoException(javax.swing.tree.ExpandVetoException) IOException(java.io.IOException)

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