Search in sources :

Example 11 with SpeciesPattern

use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.

the class IssueTableModel method getSourceObjectDescription.

private String getSourceObjectDescription(VCDocument vcDocument, Issue issue) {
    if (vcDocument instanceof BioModel) {
        Object object = issue.getSource();
        {
            DecoratedIssueSource dis = BeanUtils.downcast(DecoratedIssueSource.class, object);
            if (dis != null) {
                return dis.getSourcePath();
            }
        }
        String description = "";
        if (object instanceof SymbolTableEntry) {
            description = ((SymbolTableEntry) object).getName();
        } else if (object instanceof ReactionStep) {
            description = ((ReactionStep) object).getName();
        } else if (object instanceof ReactionRule) {
            description = ((ReactionRule) object).getName();
        } else if (object instanceof SpeciesPattern) {
            // Object parent = issue.getIssueContext().getContextObject();
            // if (parent instanceof SpeciesContext){
            // description = ((SpeciesContext)parent).getName();
            // }
            // if (issue.getIssueContext().hasContextType(ContextType.SpeciesContext)){
            // SpeciesContext thing = (SpeciesContext)issue.getIssueContext().getContextObject(ContextType.SpeciesContext);
            // description = thing.getName();
            // }else if(issue.getIssueContext().hasContextType(ContextType.ReactionRule)) {
            // ReactionRule thing = (ReactionRule)issue.getIssueContext().getContextObject(ContextType.ReactionRule);
            // description = thing.getName();
            // }else if(issue.getIssueContext().hasContextType(ContextType.RbmObservable)) {
            // RbmObservable thing = (RbmObservable)issue.getIssueContext().getContextObject(ContextType.RbmObservable);
            // description = thing.getName();
            // } else {
            System.err.println("Bad issue context for " + ((SpeciesPattern) object).toString());
            description = ((SpeciesPattern) object).toString();
        // }
        } else if (object instanceof MolecularType) {
            description = ((MolecularType) object).getName();
        } else if (object instanceof MolecularComponent) {
            description = ((MolecularComponent) object).getName();
        } else if (object instanceof ComponentStateDefinition) {
            description = ((ComponentStateDefinition) object).getName();
        } else if (object instanceof Structure) {
            description = ((Structure) object).getName();
        } else if (object instanceof SubDomain) {
            description = ((SubDomain) object).getName();
        } else if (object instanceof Geometry) {
            description = ((Geometry) object).getName();
        } else if (object instanceof StructureMapping) {
            description = ((StructureMapping) object).getStructure().getName();
        } else if (object instanceof OutputFunctionIssueSource) {
            description = ((OutputFunctionIssueSource) object).getAnnotatedFunction().getName();
        } else if (object instanceof UnmappedGeometryClass) {
            description = ((UnmappedGeometryClass) object).getGeometryClass().getName();
        } else if (object instanceof MicroscopeMeasurement) {
            description = ((MicroscopeMeasurement) object).getName();
        } else if (object instanceof SpatialObject) {
            description = ((SpatialObject) object).getName();
        } else if (object instanceof SpatialProcess) {
            description = ((SpatialProcess) object).getName();
        } else if (object instanceof GeometryContext) {
            description = "Geometry";
        } else if (object instanceof ModelOptimizationSpec) {
            description = ((ModelOptimizationSpec) object).getParameterEstimationTask().getName();
        } else if (object instanceof Simulation) {
            description = ((Simulation) object).getName();
        } else if (object instanceof SpeciesContextSpec) {
            SpeciesContextSpec scs = (SpeciesContextSpec) object;
            description = scs.getSpeciesContext().getName();
        } else if (object instanceof ReactionCombo) {
            ReactionSpec rs = ((ReactionCombo) object).getReactionSpec();
            description = rs.getReactionStep().getName();
        } else if (object instanceof RbmModelContainer) {
            // RbmModelContainer mc = (RbmModelContainer)object;
            description = "Rules validator";
        } else if (object instanceof SimulationContext) {
            SimulationContext sc = (SimulationContext) object;
            description = sc.getName();
        } else if (object instanceof Model) {
            Model m = (Model) object;
            description = m.getName();
        } else if (object instanceof BioEvent) {
            return ((BioEvent) object).getName() + "";
        } else if (object instanceof MathDescription) {
            return ((MathDescription) object).getName() + "";
        } else {
            System.err.println("unknown object type in IssueTableModel.getSourceObjectDescription(): " + object.getClass());
        }
        return description;
    } else if (vcDocument instanceof MathModel) {
        Object object = issue.getSource();
        String description = "";
        if (object instanceof Variable) {
            description = ((Variable) object).getName();
        } else if (object instanceof SubDomain) {
            description = ((SubDomain) object).getName();
        } else if (object instanceof Geometry) {
            description = "Geometry";
        } else if (object instanceof OutputFunctionIssueSource) {
            description = ((OutputFunctionIssueSource) object).getAnnotatedFunction().getName();
        } else if (object instanceof MathDescription) {
            return "math";
        } else if (object instanceof Simulation) {
            return "Simulation " + ((Simulation) object).getName() + "";
        }
        return description;
    } else {
        System.err.println("unknown document type in IssueTableModel.getSourceObjectDescription()");
        return "";
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SubDomain(cbit.vcell.math.SubDomain) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) OutputFunctionIssueSource(cbit.vcell.solver.OutputFunctionContext.OutputFunctionIssueSource) MolecularComponent(org.vcell.model.rbm.MolecularComponent) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) ModelOptimizationSpec(cbit.vcell.modelopt.ModelOptimizationSpec) UnmappedGeometryClass(cbit.vcell.mapping.GeometryContext.UnmappedGeometryClass) MicroscopeMeasurement(cbit.vcell.mapping.MicroscopeMeasurement) GeometryContext(cbit.vcell.mapping.GeometryContext) Structure(cbit.vcell.model.Structure) ReactionCombo(cbit.vcell.mapping.ReactionSpec.ReactionCombo) ReactionRule(cbit.vcell.model.ReactionRule) DecoratedIssueSource(cbit.vcell.client.desktop.DecoratedIssueSource) ReactionSpec(cbit.vcell.mapping.ReactionSpec) SimulationContext(cbit.vcell.mapping.SimulationContext) MolecularType(org.vcell.model.rbm.MolecularType) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) ReactionStep(cbit.vcell.model.ReactionStep) MathModel(cbit.vcell.mathmodel.MathModel) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) BioEvent(cbit.vcell.mapping.BioEvent)

Example 12 with SpeciesPattern

use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.

the class MolecularTypePropertiesPanel method showPopupMenu.

private void showPopupMenu(MouseEvent e, PointLocationInShapeContext locationContext) {
    if (popupFromShapeMenu == null) {
        popupFromShapeMenu = new JPopupMenu();
    }
    if (popupFromShapeMenu.isShowing()) {
        return;
    }
    final Object deepestShape = locationContext.getDeepestShape();
    final Object selectedObject;
    if (deepestShape == null) {
        selectedObject = null;
        // when cursor is outside there's nothing to do  ???
        System.out.println("outside");
        return;
    } else if (deepestShape instanceof ComponentStateLargeShape) {
        System.out.println("inside state");
        if (((ComponentStateLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((ComponentStateLargeShape) deepestShape).getComponentStateDefinition();
        } else {
            // right click only works on highlighted entity, if it's not highlighted we simply return
            return;
        }
    } else if (deepestShape instanceof MolecularComponentLargeShape) {
        System.out.println("inside component");
        if (((MolecularComponentLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((MolecularComponentLargeShape) deepestShape).getMolecularComponent();
        } else {
            return;
        }
    } else if (deepestShape instanceof MolecularTypeLargeShape) {
        System.out.println("inside molecule");
        if (((MolecularTypeLargeShape) deepestShape).isHighlighted()) {
            selectedObject = ((MolecularTypeLargeShape) deepestShape).getMolecularType();
        } else {
            return;
        }
    } else if (deepestShape instanceof SpeciesPatternLargeShape) {
        // this cannot happen, here just for symmetry
        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;
    }
    System.out.println(selectedObject);
    boolean bDelete = false;
    boolean bAdd = false;
    popupFromShapeMenu.removeAll();
    Point mousePoint = e.getPoint();
    if (selectedObject instanceof MolecularType) {
        // rename, add
        if (selectedObject != molecularType) {
            throw new RuntimeException("The selected object from shape different from the current object");
        }
        JMenuItem renamMenuItem = new JMenuItem("Rename");
        popupFromShapeMenu.add(renamMenuItem);
        JMenuItem addMenuItem = new JMenuItem("Add " + MolecularComponent.typeName);
        // Icon icon = new MolecularTypeSmallShape(1, 4, mt, gc, mt);
        // menuItem.setIcon(icon);
        popupFromShapeMenu.add(new JSeparator());
        popupFromShapeMenu.add(addMenuItem);
        addMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                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);
            // editInPlace((LargeShape)deepestShape);
            }
        });
        renamMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                editInPlace((LargeShape) deepestShape);
            }
        });
    } else if (selectedObject instanceof MolecularComponent) {
        // move left / right / separator / rename, delete, separator, add
        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) {
                MolecularComponent from = (MolecularComponent) selectedObject;
                List<MolecularComponent> mcList = molecularType.getComponentList();
                int fromIndex = mcList.indexOf(from);
                if (mcList.size() == fromIndex + 1) {
                    // already the last element
                    return;
                }
                int toIndex = fromIndex + 1;
                MolecularComponent to = mcList.remove(toIndex);
                mcList.add(fromIndex, to);
                molecularTypeTreeModel.populateTree();
                molecularType.firePropertyChange("entityChange", null, "bbb");
            }
        });
        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) {
                MolecularComponent from = (MolecularComponent) selectedObject;
                List<MolecularComponent> mcList = molecularType.getComponentList();
                int fromIndex = mcList.indexOf(from);
                if (fromIndex == 0) {
                    // already the first element
                    return;
                }
                int toIndex = fromIndex - 1;
                MolecularComponent to = mcList.remove(toIndex);
                mcList.add(fromIndex, to);
                molecularTypeTreeModel.populateTree();
                molecularType.firePropertyChange("entityChange", null, "bbb");
            }
        });
        popupFromShapeMenu.add(moveLeftMenuItem);
        popupFromShapeMenu.add(new JSeparator());
        JMenuItem renamMenuItem = new JMenuItem("Rename");
        popupFromShapeMenu.add(renamMenuItem);
        JMenuItem addMenuItem = new JMenuItem("Add " + ComponentStateDefinition.typeName);
        JMenuItem deleteMenuItem = new JMenuItem("Delete ");
        popupFromShapeMenu.add(deleteMenuItem);
        popupFromShapeMenu.add(new JSeparator());
        popupFromShapeMenu.add(addMenuItem);
        deleteMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularComponent mc = (MolecularComponent) selectedObject;
                // 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(shapePanel, 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(molecularType, 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(shapePanel, errMsg, "Delete " + mc.getDisplayType(), dialogButton);
                    if (returnCode == JOptionPane.YES_OPTION) {
                        // keep this code in sync with MolecularTypeTableModel.setValueAt
                        if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc) == true) {
                            molecularType.removeMolecularComponent(mc);
                        }
                    }
                } else {
                    if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc) == true) {
                        molecularType.removeMolecularComponent(mc);
                    }
                }
            }
        });
        addMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                MolecularComponent mc = (MolecularComponent) selectedObject;
                ComponentStateDefinition componentStateDefinition = mc.createComponentStateDefinition();
                mc.addComponentStateDefinition(componentStateDefinition);
                bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, mc, componentStateDefinition);
                bioModel.getModel().getRbmModelContainer().adjustRulesPatterns(molecularType, mc, componentStateDefinition);
                bioModel.getModel().getRbmModelContainer().adjustSpeciesPatterns(molecularType, mc, componentStateDefinition);
            // editInPlace((LargeShape)deepestShape);
            }
        });
        renamMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                editInPlace((LargeShape) deepestShape);
            }
        });
    } else if (selectedObject instanceof ComponentStateDefinition) {
        // rename, delete
        JMenuItem renamMenuItem = new JMenuItem("Rename");
        popupFromShapeMenu.add(renamMenuItem);
        JMenuItem deleteMenuItem = new JMenuItem("Delete");
        popupFromShapeMenu.add(deleteMenuItem);
        deleteMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ComponentStateDefinition csd = (ComponentStateDefinition) selectedObject;
                // must exist, we're deleting one of its states
                MolecularComponent mc = locationContext.mcs.getMolecularComponent();
                Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
                bioModel.getModel().getRbmModelContainer().findStateUsage(molecularType, 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(shapePanel, errMsg, "Delete " + ComponentStateDefinition.typeName, dialogButton);
                    if (returnCode == JOptionPane.YES_OPTION) {
                        // keep this code in sync with MolecularTypeTableModel.setValueAt
                        if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc, csd) == true) {
                            mc.deleteComponentStateDefinition(csd);
                        }
                    }
                } else {
                    if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc, csd) == true) {
                        mc.deleteComponentStateDefinition(csd);
                    }
                }
            }
        });
        renamMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                editInPlace((LargeShape) deepestShape);
            }
        });
    }
    popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
Also used : ActionEvent(java.awt.event.ActionEvent) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) JSeparator(javax.swing.JSeparator) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) LinkedHashMap(java.util.LinkedHashMap) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) MolecularComponent(org.vcell.model.rbm.MolecularComponent) JMenuItem(javax.swing.JMenuItem) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) Pair(org.vcell.util.Pair) Displayable(org.vcell.util.Displayable) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) MolecularType(org.vcell.model.rbm.MolecularType) ActionListener(java.awt.event.ActionListener) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) ComponentStateLargeShape(cbit.vcell.graph.MolecularComponentLargeShape.ComponentStateLargeShape) LargeShape(cbit.vcell.graph.LargeShape) MolecularComponentLargeShape(cbit.vcell.graph.MolecularComponentLargeShape) RelationshipObject(org.vcell.relationship.RelationshipObject) BioPaxObject(org.vcell.pathway.BioPaxObject) Icon(javax.swing.Icon) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ActionMap(javax.swing.ActionMap) InputMap(javax.swing.InputMap)

Example 13 with SpeciesPattern

use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.

the class MolecularTypeTableModel method checkInputValue.

@Override
public String checkInputValue(String inputValue, int row, int columnIndex) {
    String errMsg = null;
    final Column col = Column.values()[columnIndex];
    MolecularType selectedMolecularType = getValueAt(row);
    switch(col) {
        case name:
            {
                if (!inputValue.equals(TokenMangler.fixTokenStrict(inputValue))) {
                    errMsg = "'" + inputValue + "' not legal identifier, try '" + TokenMangler.fixTokenStrict(inputValue) + "'.";
                    errMsg += VCellErrorMessages.PressEscToUndo;
                    errMsg = "<html>" + errMsg + "</html>";
                    return errMsg;
                }
                inputValue = TokenMangler.fixTokenStrict(inputValue);
                MolecularType mt = getModel().getRbmModelContainer().getMolecularType(inputValue);
                if (mt != null && mt != selectedMolecularType) {
                    errMsg = mt.getDisplayType() + " '" + inputValue + "' already exists!";
                    errMsg += VCellErrorMessages.PressEscToUndo;
                    errMsg = "<html>" + errMsg + "</html>";
                    return errMsg;
                }
                break;
            }
        case bngl_pattern:
            {
                try {
                    inputValue = inputValue.trim();
                    if (inputValue.length() > 0) {
                        MolecularType mt = RbmUtils.parseMolecularType(inputValue);
                        MolecularType mt1 = getModel().getRbmModelContainer().getMolecularType(mt.getName());
                        if (mt1 != null && getRowIndex(mt1) != row) {
                            // molecular type with this name exists already on another row
                            errMsg = mt.getDisplayType() + " '" + mt.getDisplayName() + "' already exists!";
                            errMsg += VCellErrorMessages.PressEscToUndo;
                            errMsg = "<html>" + errMsg + "</html>";
                            return errMsg;
                        }
                        // need to check if any Component we try to delete is not already in use elsewhere
                        for (MolecularComponent selectedMolecularComponent : selectedMolecularType.getComponentList()) {
                            if (mt.getMolecularComponent(selectedMolecularComponent.getName()) == null) {
                                // the user tries to delete this mc
                                Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
                                bioModel.getModel().getRbmModelContainer().findComponentUsage(selectedMolecularType, selectedMolecularComponent, usedHere);
                                if (!usedHere.isEmpty()) {
                                    errMsg = selectedMolecularComponent.dependenciesToHtml(usedHere);
                                    errMsg += "<br><br>Deleting and Renaming a Component can be done in the Object Properties tree below.";
                                    errMsg += VCellErrorMessages.PressEscToUndo;
                                    errMsg = "<html>" + errMsg + "</html>";
                                    return errMsg;
                                }
                            }
                        }
                        // need to check if any State we try to delete is not already in use elsewhere
                        for (MolecularComponent selectedMolecularComponent : selectedMolecularType.getComponentList()) {
                            for (ComponentStateDefinition selectedComponentStateDefinition : selectedMolecularComponent.getComponentStateDefinitions()) {
                                MolecularComponent mc = mt.getMolecularComponent(selectedMolecularComponent.getName());
                                if (mc.getComponentStateDefinition(selectedComponentStateDefinition.getName()) == null) {
                                    // new list is missing a state which was present in the original
                                    if (!getModel().getRbmModelContainer().isDeleteAllowed(selectedMolecularType, selectedMolecularComponent, selectedComponentStateDefinition)) {
                                        errMsg = "State '" + selectedComponentStateDefinition + "' cannot be deleted because it's already being used.";
                                        errMsg += "<br>Deleting and Renaming a State can be done in the Object Properties tree below.";
                                        errMsg += VCellErrorMessages.PressEscToUndo;
                                        errMsg = "<html>" + errMsg + "</html>";
                                        return errMsg;
                                    }
                                }
                            }
                        }
                    }
                } catch (Exception ex) {
                    errMsg = ex.getMessage();
                    errMsg += VCellErrorMessages.PressEscToUndo;
                    errMsg = "<html>" + errMsg + "</html>";
                    return errMsg;
                }
                break;
            }
    }
    return null;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Displayable(org.vcell.util.Displayable) MolecularComponent(org.vcell.model.rbm.MolecularComponent) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Pair(org.vcell.util.Pair) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 14 with SpeciesPattern

use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.

the class ObservablePropertiesPanel method manageComponentPatternFromShape.

public void manageComponentPatternFromShape(final RbmElementAbstract selectedObject, PointLocationInShapeContext locationContext, ShowWhat showWhat) {
    final MolecularComponentPattern mcp = (MolecularComponentPattern) selectedObject;
    final MolecularComponent mc = mcp.getMolecularComponent();
    popupFromShapeMenu.removeAll();
    // ------------------------------------------------------------------- State
    if (showWhat == ShowWhat.ShowState && mc.getComponentStateDefinitions().size() != 0) {
        String prefix = "State:  ";
        String csdCurrentName = "";
        final Map<String, String> itemMap = new LinkedHashMap<String, String>();
        if (mcp.getComponentStatePattern() == null || mcp.getComponentStatePattern().isAny()) {
            csdCurrentName = "<html>" + prefix + "<b>" + ComponentStatePattern.strAny + "</b></html>";
        } else {
            csdCurrentName = "<html>" + prefix + ComponentStatePattern.strAny + "</html>";
        }
        itemMap.put(csdCurrentName, ComponentStatePattern.strAny);
        for (final ComponentStateDefinition csd : mc.getComponentStateDefinitions()) {
            csdCurrentName = "";
            if (mcp.getComponentStatePattern() != null && !mcp.getComponentStatePattern().isAny()) {
                ComponentStateDefinition csdCurrent = mcp.getComponentStatePattern().getComponentStateDefinition();
                csdCurrentName = csdCurrent.getName();
            }
            String name = csd.getName();
            if (name.equals(csdCurrentName)) {
                // currently selected menu item is shown in bold
                name = "<html>" + prefix + "<b>" + name + "</b></html>";
            } else {
                name = "<html>" + prefix + name + "</html>";
            }
            itemMap.put(name, csd.getName());
        }
        for (String name : itemMap.keySet()) {
            JMenuItem menuItem = new JMenuItem(name);
            popupFromShapeMenu.add(menuItem);
            menuItem.setIcon(VCellIcons.rbmComponentStateIcon);
            menuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    String key = e.getActionCommand();
                    String name = itemMap.get(key);
                    if (name.equals(ComponentStatePattern.strAny)) {
                        ComponentStatePattern csp = new ComponentStatePattern();
                        mcp.setComponentStatePattern(csp);
                    } else {
                        ComponentStateDefinition csd = mcp.getMolecularComponent().getComponentStateDefinition(name);
                        if (csd == null) {
                            throw new RuntimeException("Missing ComponentStateDefinition " + name + " for Component " + mcp.getMolecularComponent().getName());
                        }
                        ComponentStatePattern csp = new ComponentStatePattern(csd);
                        mcp.setComponentStatePattern(csp);
                    }
                }
            });
        }
    }
    if (showWhat == ShowWhat.ShowState) {
        return;
    }
    // ------------------------------------------------------------------------------------------- Bonds
    final MolecularTypePattern mtp = locationContext.getMolecularTypePattern();
    final SpeciesPattern sp = locationContext.getSpeciesPattern();
    JMenu editBondMenu = new JMenu();
    final String specifiedString = mcp.getBondType() == BondType.Specified ? "<html><b>" + "Site bond specified" + "</b></html>" : "<html>" + "Site bond specified" + "</html>";
    editBondMenu.setText(specifiedString);
    editBondMenu.setToolTipText("Specified");
    editBondMenu.removeAll();
    final Map<String, Bond> itemMap = new LinkedHashMap<String, Bond>();
    // String noneString = "<html>Bond:&nbsp;&nbsp;<b>" + BondType.None.symbol + "</b> " + BondType.None.name() + "</html>";
    // String existsString = "<html>Bond:&nbsp;&nbsp;<b>" + BondType.Exists.symbol + "</b> " + BondType.Exists.name() + "</html>";
    // String possibleString = "<html>Bond:&nbsp;&nbsp;<b>" + BondType.Possible.symbol + "</b> " + BondType.Possible.name() + "</html>";
    String noneString = mcp.getBondType() == BondType.None ? "<html><b>" + "Site is unbound" + "</b></html>" : "<html>" + "Site is unbound" + "</html>";
    // Site is bound
    String existsString = mcp.getBondType() == BondType.Exists ? "<html><b>" + "Site has external bond" + "</b></html>" : "<html>" + "Site has external bond" + "</html>";
    String possibleString = mcp.getBondType() == BondType.Possible ? "<html><b>" + "Site may be bound" + "</b></html>" : "<html>" + "Site may be bound" + "</html>";
    itemMap.put(noneString, null);
    itemMap.put(existsString, null);
    itemMap.put(possibleString, null);
    if (mtp != null && sp != null) {
        List<Bond> bondPartnerChoices = sp.getAllBondPartnerChoices(mtp, mc);
        for (Bond b : bondPartnerChoices) {
            // if(b.equals(mcp.getBond())) {
            // continue;	// if the mcp has a bond already we don't offer it
            // }
            int index = 0;
            if (mcp.getBondType() == BondType.Specified) {
                index = mcp.getBondId();
            } else {
                index = sp.nextBondId();
            }
            // itemMap.put(b.toHtmlStringLong(mtp, mc, sp, index), b);
            itemMap.put(b.toHtmlStringLong(sp, mtp, mc, index), b);
        // itemMap.put(b.toHtmlStringLong(sp, index), b);
        }
    }
    int index = 0;
    Graphics gc = splitPaneHorizontal.getGraphics();
    for (String name : itemMap.keySet()) {
        JMenuItem menuItem = new JMenuItem(name);
        if (index == 0) {
            menuItem.setIcon(VCellIcons.rbmBondNoneIcon);
            menuItem.setToolTipText("None");
            popupFromShapeMenu.add(menuItem);
        } else if (index == 1) {
            menuItem.setIcon(VCellIcons.rbmBondExistsIcon);
            menuItem.setToolTipText("Exists");
            popupFromShapeMenu.add(menuItem);
        } else if (index == 2) {
            menuItem.setIcon(VCellIcons.rbmBondPossibleIcon);
            menuItem.setToolTipText("Possible");
            popupFromShapeMenu.add(menuItem);
        } else if (index > 2) {
            Bond b = itemMap.get(name);
            // clone of the sp, with only the bond of interest
            SpeciesPattern spBond = new SpeciesPattern(bioModel.getModel(), sp);
            spBond.resetBonds();
            spBond.resetStates();
            MolecularTypePattern mtpFrom = spBond.getMolecularTypePattern(mtp.getMolecularType().getName(), mtp.getIndex());
            MolecularComponentPattern mcpFrom = mtpFrom.getMolecularComponentPattern(mc);
            MolecularTypePattern mtpTo = spBond.getMolecularTypePattern(b.molecularTypePattern.getMolecularType().getName(), b.molecularTypePattern.getIndex());
            MolecularComponentPattern mcpTo = mtpTo.getMolecularComponentPattern(b.molecularComponentPattern.getMolecularComponent());
            spBond.setBond(mtpTo, mcpTo, mtpFrom, mcpFrom);
            Icon icon = new SpeciesPatternSmallShape(3, 4, spBond, gc, observable, false, issueManager);
            ((SpeciesPatternSmallShape) icon).setDisplayRequirements(DisplayRequirements.highlightBonds);
            menuItem.setIcon(icon);
            editBondMenu.add(menuItem);
        // } else {
        // if(index == 0) {
        // menuItem.setForeground(Color.blue);
        // }
        // popupFromShapeMenu.add(menuItem);
        }
        menuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                String name = e.getActionCommand();
                BondType btBefore = mcp.getBondType();
                if (name.equals(noneString)) {
                    if (btBefore == BondType.Specified) {
                        // specified -> not specified
                        // change the partner to possible
                        mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
                        mcp.getBond().molecularComponentPattern.setBond(null);
                    }
                    mcp.setBondType(BondType.None);
                    mcp.setBond(null);
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            observableTreeModel.populateTree();
                        }
                    });
                } else if (name.equals(existsString)) {
                    if (btBefore == BondType.Specified) {
                        // specified -> exists
                        // change the partner to possible
                        mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
                        mcp.getBond().molecularComponentPattern.setBond(null);
                    }
                    mcp.setBondType(BondType.Exists);
                    mcp.setBond(null);
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            observableTreeModel.populateTree();
                        }
                    });
                } else if (name.equals(possibleString)) {
                    if (btBefore == BondType.Specified) {
                        // specified -> possible
                        // change the partner to possible
                        mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
                        mcp.getBond().molecularComponentPattern.setBond(null);
                    }
                    mcp.setBondType(BondType.Possible);
                    mcp.setBond(null);
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            observableTreeModel.populateTree();
                        }
                    });
                } else {
                    if (btBefore != BondType.Specified) {
                        // if we go from a non-specified to a specified we need to find the next available
                        // bond id, so that we can choose the color for displaying the bond
                        // a bad bond id, like -1, will crash badly when trying to choose the color
                        int bondId = sp.nextBondId();
                        mcp.setBondId(bondId);
                    } else {
                        // specified -> specified
                        // change the old partner to possible, continue using the bond id
                        mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
                        mcp.getBond().molecularComponentPattern.setBond(null);
                    }
                    mcp.setBondType(BondType.Specified);
                    Bond b = itemMap.get(name);
                    mcp.setBond(b);
                    mcp.getBond().molecularComponentPattern.setBondId(mcp.getBondId());
                    sp.resolveBonds();
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            observableTreeModel.populateTree();
                        }
                    });
                }
            }
        });
        index++;
    }
    popupFromShapeMenu.add(editBondMenu);
}
Also used : BondType(org.vcell.model.rbm.MolecularComponentPattern.BondType) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) SpeciesPatternSmallShape(cbit.vcell.graph.SpeciesPatternSmallShape) ActionEvent(java.awt.event.ActionEvent) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Point(java.awt.Point) LinkedHashMap(java.util.LinkedHashMap) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) Graphics(java.awt.Graphics) ActionListener(java.awt.event.ActionListener) MolecularComponent(org.vcell.model.rbm.MolecularComponent) Icon(javax.swing.Icon) ZoomShapeIcon(cbit.vcell.graph.gui.ZoomShapeIcon) JMenuItem(javax.swing.JMenuItem) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) Bond(org.vcell.model.rbm.SpeciesPattern.Bond) JMenu(javax.swing.JMenu)

Example 15 with SpeciesPattern

use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.

the class ObservableTableModel method computeData.

@Override
protected List<RbmObservable> computeData() {
    if (getModel() == null) {
        return new ArrayList<RbmObservable>();
    }
    List<RbmObservable> oList;
    if (searchText == null || searchText.length() == 0) {
        oList = new ArrayList<RbmObservable>(getModel().getRbmModelContainer().getObservableList());
    } else {
        oList = new ArrayList<RbmObservable>();
        String lowerCaseSearchText = searchText.toLowerCase();
        for (RbmObservable o : getModel().getRbmModelContainer().getObservableList()) {
            String name = o.getName();
            String struct = o.getStructure().getName();
            String type = o.getType().name();
            if (name != null && name.toLowerCase().contains(lowerCaseSearchText)) {
                oList.add(o);
            } else if (struct != null && struct.toLowerCase().contains(lowerCaseSearchText)) {
                oList.add(o);
            } else if (type != null && type.toLowerCase().contains(lowerCaseSearchText)) {
                oList.add(o);
            } else {
                String expression = "";
                for (SpeciesPattern sp : o.getSpeciesPatternList()) {
                    expression += sp.toString() + " ";
                }
                if (expression.toLowerCase().contains(lowerCaseSearchText)) {
                    oList.add(o);
                }
            }
        }
    }
    return oList;
}
Also used : RbmObservable(cbit.vcell.model.RbmObservable) ArrayList(java.util.ArrayList) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Aggregations

SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)93 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)39 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)30 MolecularType (org.vcell.model.rbm.MolecularType)25 RbmObservable (cbit.vcell.model.RbmObservable)22 SpeciesContext (cbit.vcell.model.SpeciesContext)22 Structure (cbit.vcell.model.Structure)22 Point (java.awt.Point)18 ReactionRule (cbit.vcell.model.ReactionRule)16 ArrayList (java.util.ArrayList)16 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)16 Graphics (java.awt.Graphics)13 PropertyVetoException (java.beans.PropertyVetoException)13 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)12 ProductPattern (cbit.vcell.model.ProductPattern)12 ReactantPattern (cbit.vcell.model.ReactantPattern)12 Dimension (java.awt.Dimension)12 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)12 Model (cbit.vcell.model.Model)11 ModelException (cbit.vcell.model.ModelException)11