use of org.vcell.model.rbm.MolecularComponent 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());
}
}
use of org.vcell.model.rbm.MolecularComponent in project vcell by virtualcell.
the class SpeciesPropertiesTreeModel method createMolecularComponentPatternNode.
private BioModelNode createMolecularComponentPatternNode(MolecularComponentPattern molecularComponentPattern) {
MolecularComponent mc = molecularComponentPattern.getMolecularComponent();
BioModelNode node = new BioModelNode(molecularComponentPattern, true);
// }
return node;
}
use of org.vcell.model.rbm.MolecularComponent in project vcell by virtualcell.
the class MolecularTypePropertiesPanel method addNewFromTree.
public void addNewFromTree() {
Object obj = molecularTypeTree.getLastSelectedPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
return;
}
BioModelNode selectedNode = (BioModelNode) obj;
Object selectedUserObject = selectedNode.getUserObject();
if (selectedUserObject == molecularType) {
MolecularComponent molecularComponent = molecularType.createMolecularComponent();
molecularType.addMolecularComponent(molecularComponent);
bioModel.getModel().getRbmModelContainer().adjustSpeciesContextPatterns(molecularType, molecularComponent);
bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, molecularComponent);
bioModel.getModel().getRbmModelContainer().adjustRulesPatterns(molecularType, molecularComponent);
molecularTypeTree.startEditingAtPath(molecularTypeTreeModel.findObjectPath(null, molecularComponent));
} else if (selectedUserObject instanceof MolecularComponent) {
MolecularComponent molecularComponent = (MolecularComponent) selectedUserObject;
ComponentStateDefinition componentStateDefinition = molecularComponent.createComponentStateDefinition();
molecularComponent.addComponentStateDefinition(componentStateDefinition);
bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, molecularComponent, componentStateDefinition);
molecularTypeTree.startEditingAtPath(molecularTypeTreeModel.findObjectPath(null, componentStateDefinition));
}
}
use of org.vcell.model.rbm.MolecularComponent in project vcell by virtualcell.
the class MolecularTypePropertiesPanel method deleteFromTree.
public void deleteFromTree() {
Object obj = molecularTypeTree.getLastSelectedPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
return;
}
BioModelNode selectedNode = (BioModelNode) obj;
TreeNode parent = selectedNode.getParent();
if (!(parent instanceof BioModelNode)) {
return;
}
BioModelNode parentNode = (BioModelNode) parent;
Object selectedUserObject = selectedNode.getUserObject();
if (selectedUserObject instanceof MolecularComponent) {
MolecularComponent mc = (MolecularComponent) selectedUserObject;
Object userObject = parentNode.getUserObject();
if (userObject instanceof MolecularType) {
MolecularType mt = (MolecularType) userObject;
// detailed verifications will be done there, to see if they are being used in reactions, species, observables
if (!mc.getComponentStateDefinitions().isEmpty()) {
String[] options = { "OK" };
String errMsg = mc.getDisplayType() + " '<b>" + mc.getDisplayName() + "</b>' cannot be deleted because it contains explicit States.";
errMsg += "<br>Please delete each individual State first.";
errMsg += "<br><br>Detailed usage information will be provided at that time to help you decide.";
errMsg = "<html>" + errMsg + "</html>";
JOptionPane.showOptionDialog(this.getParent().getParent(), errMsg, "Delete " + mc.getDisplayType(), JOptionPane.NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
return;
}
// we find and display component usage information to help the user decide
Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
bioModel.getModel().getRbmModelContainer().findComponentUsage(mt, mc, usedHere);
if (!usedHere.isEmpty()) {
String errMsg = mc.dependenciesToHtml(usedHere);
errMsg += "<br><br>Delete anyway?";
errMsg = "<html>" + errMsg + "</html>";
int dialogButton = JOptionPane.YES_NO_OPTION;
int returnCode = JOptionPane.showConfirmDialog(this.getParent().getParent(), errMsg, "Delete " + mc.getDisplayType(), dialogButton);
if (returnCode == JOptionPane.YES_OPTION) {
// keep this code in sync with MolecularTypeTableModel.setValueAt
if (bioModel.getModel().getRbmModelContainer().delete(mt, mc) == true) {
mt.removeMolecularComponent(mc);
}
} else {
return;
}
} else {
if (bioModel.getModel().getRbmModelContainer().delete(mt, mc) == true) {
mt.removeMolecularComponent(mc);
}
}
}
} else if (selectedUserObject instanceof ComponentStateDefinition) {
ComponentStateDefinition csd = (ComponentStateDefinition) selectedUserObject;
Object userObject = parentNode.getUserObject();
if (!(userObject instanceof MolecularComponent)) {
System.out.println("Unexpected parent in tree hierarchy for " + ComponentStateDefinition.typeName + " " + csd.getDisplayName() + "!");
return;
}
MolecularComponent mc = (MolecularComponent) userObject;
TreeNode grandParent = parentNode.getParent();
BioModelNode grandParentNode = (BioModelNode) grandParent;
userObject = grandParentNode.getUserObject();
if (!(userObject instanceof MolecularType)) {
System.out.println("Unexpected parent in tree hierarchy for " + mc.getDisplayType() + " " + mc.getDisplayName() + "!");
return;
}
MolecularType mt = (MolecularType) userObject;
Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
bioModel.getModel().getRbmModelContainer().findStateUsage(mt, mc, csd, usedHere);
if (!usedHere.isEmpty()) {
String errMsg = csd.dependenciesToHtml(usedHere);
errMsg += "<br><br>Delete anyway?";
errMsg = "<html>" + errMsg + "</html>";
int dialogButton = JOptionPane.YES_NO_OPTION;
int returnCode = JOptionPane.showConfirmDialog(this.getParent().getParent(), errMsg, "Delete " + ComponentStateDefinition.typeName, dialogButton);
if (returnCode == JOptionPane.YES_OPTION) {
// keep this code in sync with MolecularTypeTableModel.setValueAt
if (bioModel.getModel().getRbmModelContainer().delete(mt, mc, csd) == true) {
// this stays
mc.deleteComponentStateDefinition(csd);
}
} else {
return;
}
} else {
if (bioModel.getModel().getRbmModelContainer().delete(mt, mc, csd) == true) {
// this stays
mc.deleteComponentStateDefinition(csd);
}
}
// mc.deleteComponentStateDefinition(csd);
}
}
use of org.vcell.model.rbm.MolecularComponent in project vcell by virtualcell.
the class MolecularTypeTableModel method pattern.
private String pattern(MolecularType molecularType) {
String str = molecularType.getName() + "(";
List<MolecularComponent> mcl = molecularType.getComponentList();
for (int i = 0; i < mcl.size(); i++) {
MolecularComponent mc = mcl.get(i);
str += mc.getName();
List<ComponentStateDefinition> csdl = mc.getComponentStateDefinitions();
for (int j = 0; j < csdl.size(); j++) {
ComponentStateDefinition cs = csdl.get(j);
str += "~" + cs.getName();
}
if (i < mcl.size() - 1) {
str += ",";
}
}
str += ")";
return str;
}
Aggregations