Search in sources :

Example 1 with MathModelEditor

use of cbit.vcell.client.desktop.mathmodel.MathModelEditor in project vcell by virtualcell.

the class DocumentEditor method getSelectedSimulationContext.

protected SimulationContext getSelectedSimulationContext() {
    if (this instanceof MathModelEditor) {
        return null;
    }
    // make sure only one simulation context is selected
    TreePath[] selectedPaths = documentEditorTree.getSelectionPaths();
    SimulationContext simulationContext = null;
    for (TreePath path : selectedPaths) {
        Object node = path.getLastPathComponent();
        if (!(node instanceof BioModelNode)) {
            return null;
        }
        BioModelNode n = (BioModelNode) node;
        while (true) {
            Object userObject = n.getUserObject();
            if (userObject instanceof SimulationContext) {
                if (simulationContext == null) {
                    simulationContext = (SimulationContext) userObject;
                    break;
                } else if (simulationContext != userObject) {
                    return null;
                }
            }
            TreeNode parent = n.getParent();
            if (parent == null || !(parent instanceof BioModelNode)) {
                break;
            }
            n = (BioModelNode) parent;
        }
    }
    return simulationContext;
}
Also used : TreePath(javax.swing.tree.TreePath) MathModelEditor(cbit.vcell.client.desktop.mathmodel.MathModelEditor) TreeNode(javax.swing.tree.TreeNode) BioModelNode(cbit.vcell.desktop.BioModelNode) SimulationContext(cbit.vcell.mapping.SimulationContext)

Aggregations

MathModelEditor (cbit.vcell.client.desktop.mathmodel.MathModelEditor)1 BioModelNode (cbit.vcell.desktop.BioModelNode)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 TreeNode (javax.swing.tree.TreeNode)1 TreePath (javax.swing.tree.TreePath)1