use of org.vcell.model.rbm.ComponentStatePattern 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);
}
}
use of org.vcell.model.rbm.ComponentStatePattern 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 org.vcell.model.rbm.ComponentStatePattern in project vcell by virtualcell.
the class ObservablePropertiesPanel method showPopupMenu.
private void showPopupMenu(MouseEvent e, PointLocationInShapeContext locationContext) {
if (popupFromShapeMenu == null) {
popupFromShapeMenu = new JPopupMenu();
}
if (popupFromShapeMenu.isShowing()) {
return;
}
boolean bDelete = false;
boolean bAdd = false;
boolean bEdit = false;
boolean bRename = false;
popupFromShapeMenu.removeAll();
Point mousePoint = e.getPoint();
final Object deepestShape = locationContext.getDeepestShape();
final RbmElementAbstract selectedObject;
if (deepestShape == null) {
selectedObject = null;
// when cursor is outside any species pattern we offer to add a new one
System.out.println("outside");
popupFromShapeMenu.add(getAddSpeciesPatternFromShapeMenuItem());
} else if (deepestShape instanceof ComponentStateLargeShape) {
System.out.println("inside state");
if (((ComponentStateLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((ComponentStateLargeShape) deepestShape).getComponentStatePattern();
} else {
return;
}
} else if (deepestShape instanceof MolecularComponentLargeShape) {
System.out.println("inside component");
if (((MolecularComponentLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((MolecularComponentLargeShape) deepestShape).getMolecularComponentPattern();
} else {
return;
}
} else if (deepestShape instanceof MolecularTypeLargeShape) {
System.out.println("inside molecule");
if (((MolecularTypeLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((MolecularTypeLargeShape) deepestShape).getMolecularTypePattern();
} else {
return;
}
} else if (deepestShape instanceof SpeciesPatternLargeShape) {
System.out.println("inside species pattern");
if (((SpeciesPatternLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((SpeciesPatternLargeShape) deepestShape).getSpeciesPattern();
} else {
return;
}
} else {
selectedObject = null;
System.out.println("inside something else?");
return;
}
if (selectedObject instanceof SpeciesPattern) {
getAddFromShapeMenu().setText(VCellErrorMessages.AddMolecularTypes);
getAddFromShapeMenu().removeAll();
for (final MolecularType mt : bioModel.getModel().getRbmModelContainer().getMolecularTypeList()) {
JMenuItem menuItem = new JMenuItem(mt.getName());
Graphics gc = splitPaneHorizontal.getGraphics();
Icon icon = new MolecularTypeSmallShape(4, 4, mt, null, gc, mt, null, issueManager);
menuItem.setIcon(icon);
getAddFromShapeMenu().add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern molecularTypePattern = new MolecularTypePattern(mt);
((SpeciesPattern) selectedObject).addMolecularTypePattern(molecularTypePattern);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
}
});
}
});
}
JMenu compartmentMenuItem = new JMenu("Specify structure (for all)");
compartmentMenuItem.removeAll();
for (final Structure struct : bioModel.getModel().getStructures()) {
JMenuItem menuItem = new JMenuItem(struct.getName());
compartmentMenuItem.add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String nameStruct = e.getActionCommand();
Structure struct = bioModel.getModel().getStructure(nameStruct);
observable.setStructure(struct);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// repaint tree
observableTreeModel.populateTree();
// observableTree.scrollPathToVisible(path); // scroll back up to show the observable
}
});
}
});
}
JMenuItem deleteMenuItem = new JMenuItem("Delete Species Pattern");
deleteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// observable.getSpeciesPatternList().remove((SpeciesPattern)selectedObject);
observable.removeSpeciesPattern((SpeciesPattern) selectedObject);
final TreePath path = observableTreeModel.findObjectPath(null, observable);
observableTree.setSelectionPath(path);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// repaint tree
observableTreeModel.populateTree();
// scroll back up to show the observable
observableTree.scrollPathToVisible(path);
}
});
}
});
popupFromShapeMenu.add(deleteMenuItem);
popupFromShapeMenu.add(new JSeparator());
popupFromShapeMenu.add(getAddFromShapeMenu());
popupFromShapeMenu.add(compartmentMenuItem);
} else if (selectedObject instanceof MolecularTypePattern) {
MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
String moveRightMenuText = "Move <b>" + "right" + "</b>";
moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
Icon icon = VCellIcons.moveRightIcon;
moveRightMenuItem.setIcon(icon);
moveRightMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern from = (MolecularTypePattern) selectedObject;
SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
sp.shiftRight(from);
observableTreeModel.populateTree();
}
});
popupFromShapeMenu.add(moveRightMenuItem);
String moveLeftMenuText = "Move <b>" + "left" + "</b>";
moveLeftMenuText = "<html>" + moveLeftMenuText + "</html>";
JMenuItem moveLeftMenuItem = new JMenuItem(moveLeftMenuText);
icon = VCellIcons.moveLeftIcon;
moveLeftMenuItem.setIcon(icon);
moveLeftMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern from = (MolecularTypePattern) selectedObject;
SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
sp.shiftLeft(from);
observableTreeModel.populateTree();
}
});
popupFromShapeMenu.add(moveLeftMenuItem);
popupFromShapeMenu.add(new JSeparator());
String deleteMenuText = "Delete <b>" + mtp.getMolecularType().getName() + "</b>";
deleteMenuText = "<html>" + deleteMenuText + "</html>";
JMenuItem deleteMenuItem = new JMenuItem(deleteMenuText);
deleteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularTypePattern mtp = (MolecularTypePattern) selectedObject;
SpeciesPattern sp = locationContext.sps.getSpeciesPattern();
sp.removeMolecularTypePattern(mtp);
}
});
popupFromShapeMenu.add(deleteMenuItem);
} else if (selectedObject instanceof MolecularComponentPattern) {
manageComponentPatternFromShape(selectedObject, locationContext, ShowWhat.ShowBond);
bDelete = false;
} else if (selectedObject instanceof ComponentStatePattern) {
MolecularComponentPattern mcp = ((ComponentStateLargeShape) deepestShape).getMolecularComponentPattern();
manageComponentPatternFromShape(mcp, locationContext, ShowWhat.ShowState);
}
if (bRename) {
popupFromShapeMenu.add(getRenameFromShapeMenuItem());
}
if (bDelete) {
popupFromShapeMenu.add(getDeleteFromShapeMenuItem());
}
if (bEdit) {
popupFromShapeMenu.add(getEditFromShapeMenuItem());
}
if (bAdd) {
popupFromShapeMenu.add(new JSeparator());
popupFromShapeMenu.add(getAddFromShapeMenu());
}
popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
use of org.vcell.model.rbm.ComponentStatePattern in project vcell by virtualcell.
the class RbmObservable method checkComponentStateConsistency.
public void checkComponentStateConsistency(IssueContext issueContext, List<Issue> issueList, MolecularTypePattern mtpThis) {
if (issueList == null) {
// this may be called during parsing before the model is consistent
return;
}
MolecularType mtThat = mtpThis.getMolecularType();
for (MolecularComponentPattern mcpThis : mtpThis.getComponentPatternList()) {
if (mcpThis.isImplied()) {
// continue;
}
ComponentStatePattern cspThis = mcpThis.getComponentStatePattern();
String mcNameThis = mcpThis.getMolecularComponent().getName();
if (cspThis == null && mcpThis.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
// String msg = "Component pattern " + mcNameThis + " is in no State while the component has possible States defined.";
String msg = "One of the possible States must be chosen for " + MolecularComponentPattern.typeName + " " + mcNameThis + ".";
issueList.add(new Issue(this, mcpThis, issueContext, IssueCategory.Identifiers, msg, null, Issue.SEVERITY_WARNING));
}
MolecularComponent[] mcThatList = mtThat.getMolecularComponents(mcNameThis);
if (mcThatList.length == 0) {
System.out.println("we already fired an issue about component missing");
// nothing to do here, we already fired an issue about component missing
continue;
} else if (mcThatList.length > 1) {
String msg = "Multiple " + MolecularComponent.typeName + "s with the same name are not yet supported.";
issueList.add(new Issue(this, mcpThis, issueContext, IssueCategory.Identifiers, msg, null, Issue.SEVERITY_ERROR));
} else {
// found exactly 1 component
MolecularComponent mcThat = mcThatList[0];
List<ComponentStateDefinition> csdListThat = mcThat.getComponentStateDefinitions();
if (csdListThat.size() == 0) {
// component has no states, we check if mcpThis has any states... it shouldn't
if (cspThis == null) {
// all is well
continue;
}
if (!cspThis.isAny() || (cspThis.getComponentStateDefinition() != null)) {
String msg = MolecularComponentPattern.typeName + " " + mcNameThis + " is in an invalid State.";
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_WARNING));
}
} else {
// we check if mcpThis has any of these states... it should!
if ((cspThis == null) || cspThis.isAny() || (cspThis.getComponentStateDefinition() == null)) {
// String msg = "Component pattern " + mcNameThis + " must be in an explicit State.";
// issueList.add(new Issue(this, IssueCategory.Identifiers, msg, Issue.SEVERITY_WARNING));
} else {
String csdNameThis = cspThis.getComponentStateDefinition().getName();
if (csdNameThis.isEmpty() || (mcThat.getComponentStateDefinition(csdNameThis) == null)) {
String msg = "Invalid State " + csdNameThis + " " + MolecularComponentPattern.typeName + " " + mcNameThis;
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_WARNING));
}
}
}
}
}
}
use of org.vcell.model.rbm.ComponentStatePattern in project vcell by virtualcell.
the class RbmObservable method deleteStateFromPatterns.
public boolean deleteStateFromPatterns(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd) {
for (SpeciesPattern sp : getSpeciesPatternList()) {
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
if (mtp.getMolecularType() == mt) {
List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
for (MolecularComponentPattern mcp : componentPatterns) {
if (!(mcp.getMolecularComponent() == mc)) {
continue;
}
ComponentStatePattern csp = mcp.getComponentStatePattern();
if (csp == null) {
continue;
}
if (csp.isAny()) {
if (mc.getComponentStateDefinitions().size() == 1) {
mcp.setComponentStatePattern(null);
}
continue;
}
if (csp.getComponentStateDefinition() == csd) {
if (mc.getComponentStateDefinitions().size() == 1) {
// we are about to delete the last possible state, so we set the ComponentStatePattern to null
mcp.setComponentStatePattern(null);
} else {
// some other state is still available, we set the ComponentStatePattern to Any and let the user deal with it
csp = new ComponentStatePattern();
mcp.setComponentStatePattern(csp);
}
}
}
}
}
}
return true;
}
Aggregations