Search in sources :

Example 21 with ComponentStatePattern

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);
    }
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 22 with ComponentStatePattern

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);
                }
            }
        }
    }
}
Also used : ProductPattern(cbit.vcell.model.ProductPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) List(java.util.List) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ReactantPattern(cbit.vcell.model.ReactantPattern)

Example 23 with ComponentStatePattern

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);
}
Also used : ActionEvent(java.awt.event.ActionEvent) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) JSeparator(javax.swing.JSeparator) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) JMenuItem(javax.swing.JMenuItem) Structure(cbit.vcell.model.Structure) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics) MolecularTypeSmallShape(cbit.vcell.graph.MolecularTypeSmallShape) ActionListener(java.awt.event.ActionListener) TreePath(javax.swing.tree.TreePath) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) RbmElementAbstract(org.vcell.model.rbm.RbmElementAbstract) Icon(javax.swing.Icon) ZoomShapeIcon(cbit.vcell.graph.gui.ZoomShapeIcon) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) JMenu(javax.swing.JMenu)

Example 24 with ComponentStatePattern

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));
                    }
                }
            }
        }
    }
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Issue(org.vcell.util.Issue) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) MolecularComponent(org.vcell.model.rbm.MolecularComponent) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) ArrayList(java.util.ArrayList) List(java.util.List)

Example 25 with ComponentStatePattern

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;
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Aggregations

ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)30 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)25 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)19 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)16 MolecularComponent (org.vcell.model.rbm.MolecularComponent)10 MolecularType (org.vcell.model.rbm.MolecularType)9 Graphics (java.awt.Graphics)8 Icon (javax.swing.Icon)8 ZoomShapeIcon (cbit.vcell.graph.gui.ZoomShapeIcon)6 Point (java.awt.Point)6 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)6 JMenu (javax.swing.JMenu)6 JMenuItem (javax.swing.JMenuItem)6 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)6 MolecularTypeSmallShape (cbit.vcell.graph.MolecularTypeSmallShape)5 BondType (org.vcell.model.rbm.MolecularComponentPattern.BondType)5 Bond (org.vcell.model.rbm.SpeciesPattern.Bond)5 BioModelNode (cbit.vcell.desktop.BioModelNode)4 LinkedHashMap (java.util.LinkedHashMap)4