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);
}
}
}
}
}
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());
}
}
Aggregations