Search in sources :

Example 21 with ProductPattern

use of cbit.vcell.model.ProductPattern in project vcell by virtualcell.

the class ReactionRulePropertiesTreeModel method propertyChange.

public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName().equals(PropertyConstants.PROPERTY_NAME_NAME)) {
        nodeChanged(rootNode);
    } else if (evt.getPropertyName().equals("entityChange")) {
        nodeChanged(rootNode);
    } else if (evt.getSource() == reactionRule || evt.getSource() instanceof SpeciesPattern || evt.getSource() instanceof MolecularTypePattern) {
        populateTree();
        Object source = evt.getSource();
        if (source == reactionRule) {
            if (participantType == ReactionRuleParticipantType.Reactant && evt.getPropertyName().equals(ReactionRule.PROPERTY_NAME_REACTANT_PATTERNS)) {
                List<ReactantPattern> oldValue = (List<ReactantPattern>) evt.getOldValue();
                if (oldValue != null) {
                    for (ReactantPattern sp : oldValue) {
                        RbmUtils.removePropertyChangeListener(sp.getSpeciesPattern(), this);
                    }
                }
                List<ReactantPattern> newValue = (List<ReactantPattern>) evt.getNewValue();
                if (newValue != null) {
                    for (ReactantPattern sp : newValue) {
                        RbmUtils.addPropertyChangeListener(sp.getSpeciesPattern(), this);
                    }
                }
            } else if (participantType == ReactionRuleParticipantType.Product && evt.getPropertyName().equals(ReactionRule.PROPERTY_NAME_PRODUCT_PATTERNS)) {
                List<ProductPattern> oldValue = (List<ProductPattern>) evt.getOldValue();
                if (oldValue != null) {
                    for (ProductPattern sp : oldValue) {
                        RbmUtils.removePropertyChangeListener(sp.getSpeciesPattern(), this);
                    }
                }
                List<ProductPattern> newValue = (List<ProductPattern>) evt.getNewValue();
                if (newValue != null) {
                    for (ProductPattern sp : newValue) {
                        RbmUtils.addPropertyChangeListener(sp.getSpeciesPattern(), this);
                    }
                }
            }
        } else if (source instanceof SpeciesPattern) {
            if (evt.getPropertyName().equals(SpeciesPattern.PROPERTY_NAME_MOLECULAR_TYPE_PATTERNS)) {
                List<MolecularTypePattern> oldValue = (List<MolecularTypePattern>) evt.getOldValue();
                if (oldValue != null) {
                    for (MolecularTypePattern mtp : oldValue) {
                        RbmUtils.removePropertyChangeListener(mtp, this);
                    }
                }
                List<MolecularTypePattern> newValue = (List<MolecularTypePattern>) evt.getNewValue();
                if (newValue != null) {
                    for (MolecularTypePattern mtp : newValue) {
                        RbmUtils.addPropertyChangeListener(mtp, this);
                    }
                }
            }
        } else if (source instanceof MolecularTypePattern) {
            if (evt.getPropertyName().equals(MolecularTypePattern.PROPERTY_NAME_COMPONENT_PATTERN_LIST)) {
                List<MolecularComponentPattern> oldValue = (List<MolecularComponentPattern>) evt.getOldValue();
                if (oldValue != null) {
                    for (MolecularComponentPattern mcp : oldValue) {
                        RbmUtils.removePropertyChangeListener(mcp, this);
                    }
                }
                List<MolecularComponentPattern> newValue = (List<MolecularComponentPattern>) evt.getNewValue();
                if (newValue != null) {
                    for (MolecularComponentPattern mcp : newValue) {
                        RbmUtils.addPropertyChangeListener(mcp, this);
                    }
                }
            }
        } else if (source instanceof MolecularComponentPattern) {
            if (evt.getSource().equals(MolecularComponentPattern.PROPERTY_NAME_COMPONENT_STATE)) {
                ComponentStatePattern oldValue = (ComponentStatePattern) evt.getOldValue();
                if (oldValue != null) {
                    oldValue.removePropertyChangeListener(this);
                }
                ComponentStatePattern newValue = (ComponentStatePattern) evt.getNewValue();
                if (newValue != null) {
                    newValue.addPropertyChangeListener(this);
                }
            }
        }
    }
}
Also used : ProductPattern(cbit.vcell.model.ProductPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) List(java.util.List) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ReactantPattern(cbit.vcell.model.ReactantPattern)

Example 22 with ProductPattern

use of cbit.vcell.model.ProductPattern 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

ProductPattern (cbit.vcell.model.ProductPattern)22 ReactantPattern (cbit.vcell.model.ReactantPattern)20 ReactionRule (cbit.vcell.model.ReactionRule)17 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)12 Structure (cbit.vcell.model.Structure)10 ArrayList (java.util.ArrayList)8 SpeciesContext (cbit.vcell.model.SpeciesContext)7 MolecularType (org.vcell.model.rbm.MolecularType)6 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)6 RbmObservable (cbit.vcell.model.RbmObservable)5 ReactionStep (cbit.vcell.model.ReactionStep)5 ModelException (cbit.vcell.model.ModelException)4 RbmKineticLaw (cbit.vcell.model.RbmKineticLaw)4 Point (java.awt.Point)4 List (java.util.List)4 SpeciesPatternSmallShape (cbit.vcell.graph.SpeciesPatternSmallShape)3 Model (cbit.vcell.model.Model)3 Product (cbit.vcell.model.Product)3 Reactant (cbit.vcell.model.Reactant)3 Graphics (java.awt.Graphics)3