Search in sources :

Example 46 with MolecularTypePattern

use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.

the class ReactionRuleEditorPropertiesPanel method reflectStateToProduct.

private void reflectStateToProduct(MolecularComponentPattern mcpReactant, ComponentStatePattern cspReactant) {
    MolecularTypePattern mtpReactant = reactionRule.getReactantMoleculeOfComponent(mcpReactant);
    MolecularTypePattern mtpProduct = reactionRule.getMatchingProductMolecule(mtpReactant);
    if (mtpProduct == null) {
        return;
    }
    for (MolecularComponentPattern mcpProduct : mtpProduct.getComponentPatternList()) {
        if (mcpProduct.getMolecularComponent() != mcpReactant.getMolecularComponent()) {
            continue;
        }
        // use this if isAny
        ComponentStatePattern csp = new ComponentStatePattern();
        if (!cspReactant.isAny()) {
            ComponentStateDefinition csd = cspReactant.getComponentStateDefinition();
            csp = new ComponentStatePattern(csd);
        }
        mcpProduct.setComponentStatePattern(csp);
    }
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 47 with MolecularTypePattern

use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.

the class ReactionRulePropertiesTreeModel method populateTree.

public void populateTree() {
    if (reactionRule == null) {
        // this may be legit, for example when there's a plain reaction rather than a reaction rule
        System.out.println("ReactionRulePropertiesTreeModel: reactionRule is null.");
        return;
    }
    if (bioModel == null) {
        System.out.println("ReactionRulePropertiesTreeModel: bioModel is null.");
        return;
    }
    rootNode.setUserObject(reactionRule);
    rootNode.removeAllChildren();
    int count = 0;
    List<? extends ReactionRuleParticipant> patterns = participantType == ReactionRuleParticipantType.Reactant ? reactionRule.getReactantPatterns() : reactionRule.getProductPatterns();
    for (ReactionRuleParticipant rrp : patterns) {
        BioModelNode rrNode = new BioModelNode(new ReactionRuleParticipantLocal(participantType, rrp, ++count));
        for (MolecularTypePattern mtp : rrp.getSpeciesPattern().getMolecularTypePatterns()) {
            BioModelNode node = createMolecularTypePatternNode(mtp);
            rrNode.add(node);
        }
        rootNode.add(rrNode);
    }
    nodeStructureChanged(rootNode);
    // GuiUtils.treeExpandAll(ownerTree, rootNode, true);
    GuiUtils.treeExpandAllRows(ownerTree);
    // we fire a dummy event because the species properties panel and the bio model editor species table model
    // will repaint the shape and respectively the table row for any speciesContext property change event
    reactionRule.firePropertyChange("entityChange", null, "bbb");
}
Also used : ReactionRuleParticipant(cbit.vcell.model.ReactionRuleParticipant) BioModelNode(cbit.vcell.desktop.BioModelNode) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 48 with MolecularTypePattern

use of org.vcell.model.rbm.MolecularTypePattern 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 49 with MolecularTypePattern

use of org.vcell.model.rbm.MolecularTypePattern 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)

Example 50 with MolecularTypePattern

use of org.vcell.model.rbm.MolecularTypePattern in project vcell by virtualcell.

the class SpeciesPropertiesTreeModel method populateTree.

public void populateTree() {
    if (speciesContext == null || bioModel == null) {
        return;
    }
    rootNode.setUserObject(speciesContext);
    rootNode.removeAllChildren();
    int count = 0;
    if (speciesContext.getSpeciesPattern() == null) {
        nodeStructureChanged(rootNode);
        return;
    }
    SpeciesPattern sp = speciesContext.getSpeciesPattern();
    // BioModelNode spNode = new BioModelNode(new SpeciesPatternLocal(sp, ++count));
    for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
        BioModelNode node = createMolecularTypePatternNode(mtp);
        rootNode.add(node);
    // spNode.add(node);
    }
    // rootNode.add(spNode);
    nodeStructureChanged(rootNode);
    GuiUtils.treeExpandAllRows(ownerTree);
    // we fire a "dummy" event because the species properties panel and the bio model editor species table model
    // will repaint the shape and respectively the table row for any speciesContext property change event
    speciesContext.firePropertyChange("entityChange", null, "bbb");
}
Also used : BioModelNode(cbit.vcell.desktop.BioModelNode) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Aggregations

MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)72 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)49 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)39 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)19 Graphics (java.awt.Graphics)16 MolecularType (org.vcell.model.rbm.MolecularType)16 Point (java.awt.Point)14 BioModelNode (cbit.vcell.desktop.BioModelNode)11 RbmObservable (cbit.vcell.model.RbmObservable)10 SpeciesContext (cbit.vcell.model.SpeciesContext)10 Icon (javax.swing.Icon)10 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)10 MolecularComponent (org.vcell.model.rbm.MolecularComponent)10 ArrayList (java.util.ArrayList)9 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)7 ReactionRule (cbit.vcell.model.ReactionRule)7 LinkedHashMap (java.util.LinkedHashMap)7 MolecularTypeLargeShape (cbit.vcell.graph.MolecularTypeLargeShape)6 MolecularTypeSmallShape (cbit.vcell.graph.MolecularTypeSmallShape)6 RuleAnalysisChanged (cbit.vcell.graph.ReactionCartoon.RuleAnalysisChanged)6