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