use of cbit.vcell.desktop.BioModelNode in project vcell by virtualcell.
the class RbmTreeCellEditor method getTreeCellEditorComponent.
@Override
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
Component component = null;
realEditor = defaultCellEditor;
if (value instanceof BioModelNode) {
BioModelNode node = (BioModelNode) value;
Object userObject = node.getUserObject();
String text = null;
Icon icon = null;
if (userObject instanceof MolecularType) {
text = ((MolecularType) userObject).getName();
icon = VCellIcons.rbmMolecularTypeIcon;
} else if (userObject instanceof MolecularTypePattern) {
text = ((MolecularTypePattern) userObject).getMolecularType().getName();
icon = VCellIcons.rbmMolecularTypeIcon;
} else if (userObject instanceof MolecularComponent) {
BioModelNode parentNode = (BioModelNode) node.getParent();
Object parentObject = parentNode == null ? null : parentNode.getUserObject();
// TODO: look for the proper icon
icon = VCellIcons.rbmComponentErrorIcon;
if (parentObject instanceof MolecularType) {
text = ((MolecularComponent) userObject).getName();
} else if (parentObject instanceof MolecularTypePattern) {
realEditor = getMolecularComponentPatternCellEditor();
getMolecularComponentPatternCellEditor().molecularTypePattern = ((MolecularTypePattern) parentObject);
// find SpeciesPattern
while (true) {
parentNode = (BioModelNode) parentNode.getParent();
if (parentNode == null) {
break;
}
if (parentNode.getUserObject() instanceof RbmObservable) {
((MolecularComponentPatternCellEditor) realEditor).owner = MolecularComponentPatternCellEditor.observable;
getMolecularComponentPatternCellEditor().speciesPattern = ((RbmObservable) parentNode.getUserObject()).getSpeciesPattern(0);
break;
}
if (parentNode.getUserObject() instanceof ReactionRule) {
((MolecularComponentPatternCellEditor) realEditor).owner = MolecularComponentPatternCellEditor.reaction;
ReactionRulePropertiesTreeModel tm = (ReactionRulePropertiesTreeModel) tree.getModel();
switch(tm.getParticipantType()) {
case Reactant:
getMolecularComponentPatternCellEditor().speciesPattern = ((ReactionRule) parentNode.getUserObject()).getReactantPattern(0).getSpeciesPattern();
break;
case Product:
getMolecularComponentPatternCellEditor().speciesPattern = ((ReactionRule) parentNode.getUserObject()).getProductPattern(0).getSpeciesPattern();
break;
}
}
if (parentNode.getUserObject() instanceof SpeciesContext) {
((MolecularComponentPatternCellEditor) realEditor).owner = MolecularComponentPatternCellEditor.species;
getMolecularComponentPatternCellEditor().speciesPattern = ((SpeciesContext) parentNode.getUserObject()).getSpeciesPattern();
break;
}
}
}
} else if (userObject instanceof ComponentStateDefinition) {
text = ((ComponentStateDefinition) userObject).getName();
icon = VCellIcons.rbmComponentStateIcon;
} else if (userObject instanceof RbmObservable) {
text = ((RbmObservable) userObject).getName();
icon = VCellIcons.rbmObservableIcon;
}
renderer.setOpenIcon(icon);
renderer.setClosedIcon(icon);
renderer.setLeafIcon(icon);
component = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
if (editingComponent instanceof JTextField) {
JTextField textField = (JTextField) editingComponent;
textField.setText(text);
}
}
return component;
}
use of cbit.vcell.desktop.BioModelNode in project vcell by virtualcell.
the class ReactionRuleEditorPropertiesPanel method delete.
public void delete() {
Object obj = rightClickSourceTree.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 ReactionRuleParticipantLocal) {
ReactionRuleParticipantLocal reactionRuleParticipant = (ReactionRuleParticipantLocal) selectedUserObject;
switch(reactionRuleParticipant.type) {
case Reactant:
reactionRule.removeReactant((ReactantPattern) (reactionRuleParticipant.speciesPattern));
break;
case Product:
reactionRule.removeProduct((ProductPattern) (reactionRuleParticipant.speciesPattern));
break;
}
} else if (selectedUserObject instanceof MolecularTypePattern) {
MolecularTypePattern mtp = (MolecularTypePattern) selectedUserObject;
Object parentObject = parentNode.getUserObject();
if (parentObject instanceof ReactionRuleParticipantLocal) {
ReactionRuleParticipantLocal rrp = (ReactionRuleParticipantLocal) parentObject;
rrp.speciesPattern.getSpeciesPattern().removeMolecularTypePattern(mtp);
if (rrp.type == ReactionRuleParticipantType.Reactant) {
// we reset the "opposite" tree because it too might have changed
productTreeModel.populateTree();
} else if (rrp.type == ReactionRuleParticipantType.Product) {
reactantTreeModel.populateTree();
}
}
}
}
use of cbit.vcell.desktop.BioModelNode in project vcell by virtualcell.
the class ReactionRulePropertiesTreeModel method createMolecularTypePatternNode.
private BioModelNode createMolecularTypePatternNode(MolecularTypePattern molecularTypePattern) {
MolecularType molecularType = molecularTypePattern.getMolecularType();
BioModelNode node = new BioModelNode(molecularTypePattern, true);
if (molecularTypePattern.hasExplicitParticipantMatch()) {
ParticipantMatchLabelLocal pmll = new ParticipantMatchLabelLocal(molecularTypePattern.getParticipantMatchLabel());
BioModelNode nm = new BioModelNode(pmll, true);
node.add(nm);
}
for (MolecularComponent mc : molecularType.getComponentList()) {
// dead code, we don't show state and bond
if (bShowDetails || molecularTypePattern.getMolecularComponentPattern(mc).isbVisible()) {
BioModelNode n = createMolecularComponentPatternNode(molecularTypePattern.getMolecularComponentPattern(mc));
if (n != null) {
node.add(n);
}
}
}
return node;
}
use of cbit.vcell.desktop.BioModelNode 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");
}
use of cbit.vcell.desktop.BioModelNode 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