Search in sources :

Example 11 with BondType

use of org.vcell.model.rbm.MolecularComponentPattern.BondType in project vcell by virtualcell.

the class ReactionRulePropertiesTreeModel method valueForPathChanged.

@Override
public void valueForPathChanged(TreePath path, Object newValue) {
    Object obj = path.getLastPathComponent();
    if (obj == null || !(obj instanceof BioModelNode)) {
        return;
    }
    BioModelNode selectedNode = (BioModelNode) obj;
    BioModelNode parentNode = (BioModelNode) selectedNode.getParent();
    Object userObject = selectedNode.getUserObject();
    try {
        if (newValue instanceof String) {
            String inputString = (String) newValue;
            if (inputString == null || inputString.length() == 0) {
                return;
            }
            if (userObject instanceof ReactionRule) {
                // TODO: untested!!!
                ((ReactionRule) userObject).setName(inputString);
            }
        } else if (newValue instanceof MolecularComponentPattern) {
            MolecularComponentPattern newMcp = (MolecularComponentPattern) newValue;
            Object parentObject = parentNode == null ? null : parentNode.getUserObject();
            if (parentObject instanceof MolecularTypePattern) {
                MolecularTypePattern mtp = (MolecularTypePattern) parentObject;
                MolecularComponent mc = newMcp.getMolecularComponent();
                MolecularComponentPattern mcp = mtp.getMolecularComponentPattern(mc);
                mcp.setComponentStatePattern(newMcp.getComponentStatePattern());
                BondType bp = mcp.getBondType();
                BondType newbp = newMcp.getBondType();
                mcp.setBondType(newbp);
                // specified -> specified
                if (bp == BondType.Specified && newbp == BondType.Specified) {
                // bond didn't change
                } else if (bp == BondType.Specified && newbp != BondType.Specified) {
                    // specified -> non specified
                    // change the partner to possible
                    mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
                    mcp.setBond(null);
                } else if (bp != BondType.Specified && newbp == BondType.Specified) {
                    // non specified -> specified
                    int newBondId = newMcp.getBondId();
                    mcp.setBondId(newBondId);
                    mcp.setBond(newMcp.getBond());
                    mcp.getBond().molecularComponentPattern.setBondId(newBondId);
                    for (ReactantPattern rp : reactionRule.getReactantPatterns()) {
                        rp.getSpeciesPattern().resolveBonds();
                    }
                    for (ProductPattern pp : reactionRule.getProductPatterns()) {
                        pp.getSpeciesPattern().resolveBonds();
                    }
                } else {
                }
            }
        }
    } catch (Exception ex) {
        DialogUtils.showErrorDialog(ownerTree, ex.getMessage());
    }
}
Also used : BondType(org.vcell.model.rbm.MolecularComponentPattern.BondType) ReactionRule(cbit.vcell.model.ReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) MolecularComponent(org.vcell.model.rbm.MolecularComponent) BioModelNode(cbit.vcell.desktop.BioModelNode) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) ReactantPattern(cbit.vcell.model.ReactantPattern)

Aggregations

BondType (org.vcell.model.rbm.MolecularComponentPattern.BondType)11 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)9 MolecularComponent (org.vcell.model.rbm.MolecularComponent)7 Bond (org.vcell.model.rbm.SpeciesPattern.Bond)7 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)6 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)5 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)4 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)4 BioModelNode (cbit.vcell.desktop.BioModelNode)3 SpeciesPatternSmallShape (cbit.vcell.graph.SpeciesPatternSmallShape)3 ZoomShapeIcon (cbit.vcell.graph.gui.ZoomShapeIcon)3 Graphics (java.awt.Graphics)3 Point (java.awt.Point)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 LinkedHashMap (java.util.LinkedHashMap)3 Icon (javax.swing.Icon)3 JMenu (javax.swing.JMenu)3 JMenuItem (javax.swing.JMenuItem)3 ParticleBondType (cbit.vcell.math.ParticleMolecularComponentPattern.ParticleBondType)2