Search in sources :

Example 61 with BioModelNode

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;
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) RbmObservable(cbit.vcell.model.RbmObservable) BioModelNode(cbit.vcell.desktop.BioModelNode) SpeciesContext(cbit.vcell.model.SpeciesContext) JTextField(javax.swing.JTextField) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) MolecularType(org.vcell.model.rbm.MolecularType) MolecularComponent(org.vcell.model.rbm.MolecularComponent) Icon(javax.swing.Icon) Component(java.awt.Component) MolecularComponent(org.vcell.model.rbm.MolecularComponent) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 62 with BioModelNode

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();
            }
        }
    }
}
Also used : TreeNode(javax.swing.tree.TreeNode) ReactionRuleParticipantLocal(cbit.vcell.client.desktop.biomodel.RbmDefaultTreeModel.ReactionRuleParticipantLocal) RbmObject(org.vcell.model.rbm.RbmObject) BioModelNode(cbit.vcell.desktop.BioModelNode) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 63 with BioModelNode

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;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) MolecularComponent(org.vcell.model.rbm.MolecularComponent) BioModelNode(cbit.vcell.desktop.BioModelNode)

Example 64 with BioModelNode

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");
}
Also used : ReactionRuleParticipant(cbit.vcell.model.ReactionRuleParticipant) BioModelNode(cbit.vcell.desktop.BioModelNode) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 65 with BioModelNode

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());
    }
}
Also used : BondType(org.vcell.model.rbm.MolecularComponentPattern.BondType) ReactionRule(cbit.vcell.model.ReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) MolecularComponent(org.vcell.model.rbm.MolecularComponent) BioModelNode(cbit.vcell.desktop.BioModelNode) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) ReactantPattern(cbit.vcell.model.ReactantPattern)

Aggregations

BioModelNode (cbit.vcell.desktop.BioModelNode)82 TreePath (javax.swing.tree.TreePath)22 MolecularComponent (org.vcell.model.rbm.MolecularComponent)17 CSGObject (cbit.vcell.geometry.CSGObject)12 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)11 SimulationContext (cbit.vcell.mapping.SimulationContext)10 MolecularType (org.vcell.model.rbm.MolecularType)10 Point (java.awt.Point)9 Icon (javax.swing.Icon)8 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)8 TestSuiteInfoNew (cbit.vcell.numericstest.TestSuiteInfoNew)7 TreeNode (javax.swing.tree.TreeNode)7 DocumentEditorTreeFolderClass (cbit.vcell.client.desktop.biomodel.DocumentEditorTreeModel.DocumentEditorTreeFolderClass)6 DocumentEditorTreeFolderNode (cbit.vcell.client.desktop.biomodel.DocumentEditorTreeModel.DocumentEditorTreeFolderNode)6 TestCaseNew (cbit.vcell.numericstest.TestCaseNew)6 TestCriteriaNew (cbit.vcell.numericstest.TestCriteriaNew)6 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)6 BioPaxObject (org.vcell.pathway.BioPaxObject)6 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)5 Component (java.awt.Component)5