use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.
the class BioModelEditorReactionTableModel method checkInputValue.
public String checkInputValue(String inputValue, int row, int column) {
ModelProcess modelProcess = getValueAt(row);
String errMsg = null;
switch(column) {
case COLUMN_NAME:
if (modelProcess == null || !modelProcess.getName().equals(inputValue)) {
if (getModel().getReactionStep(inputValue) != null) {
errMsg = "Reaction '" + inputValue + "' already exist!";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
if (getModel().getRbmModelContainer().getReactionRule(inputValue) != null) {
errMsg = "ReactionRule '" + inputValue + "' already exist!";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
}
break;
case COLUMN_EQUATION:
try {
if (modelProcess instanceof ReactionStep) {
ReactionStep reactionStep = (ReactionStep) modelProcess;
ModelProcessEquation.parseReaction(reactionStep, getModel(), inputValue);
} else if (modelProcess instanceof ReactionRule) {
// ReactionRuleEmbedded reactionRule = (ReactionRuleEmbedded)modelProcess;
ReactionRule newlyParsedReactionRule_NotUsedForValidation = RbmUtils.parseReactionRule(inputValue, getModel().getStructures()[0], bioModel);
} else {
// new row ... it's a rule if contains parentheses, plain reaction if it does not
if (inputValue.contains("(") && inputValue.contains(")")) {
ReactionRule newlyParsedReactionRule_NotUsedForValidation = RbmUtils.parseReactionRule(inputValue, getModel().getStructures()[0], bioModel);
if (newlyParsedReactionRule_NotUsedForValidation == null) {
throw new RuntimeException("Unable to generate a reaction rule for this input.");
}
} else {
ReactionStep reactionStep = (ReactionStep) modelProcess;
ModelProcessEquation.parseReaction(reactionStep, getModel(), inputValue);
}
}
} catch (org.vcell.model.bngl.ParseException ex) {
errMsg = ex.getMessage();
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;
case COLUMN_STRUCTURE:
if (getModel().getStructure(inputValue) == null) {
errMsg = "Structure '" + inputValue + "' does not exist!";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
break;
}
return null;
}
use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.
the class BioModelEditorReactionTableModel method computeData.
protected ArrayList<ModelProcess> computeData() {
ArrayList<ModelProcess> processList = new ArrayList<ModelProcess>();
if (getModel() != null) {
ModelProcess[] modelProcesses = getModel().getModelProcesses();
if (searchText == null || searchText.length() == 0) {
processList.addAll(Arrays.asList(modelProcesses));
} else {
String lowerCaseSearchText = searchText.toLowerCase();
for (ModelProcess process : modelProcesses) {
boolean bMatchRelationshipObj = false;
if (process instanceof ReactionStep) {
ReactionStep reactionStep = (ReactionStep) process;
HashSet<RelationshipObject> relObjsHash = bioModel.getRelationshipModel().getRelationshipObjects(reactionStep);
for (RelationshipObject relObj : relObjsHash) {
if (relObj.getBioPaxObject() instanceof Entity) {
if (((Entity) relObj.getBioPaxObject()).getName().get(0).toLowerCase().contains(lowerCaseSearchText)) {
bMatchRelationshipObj = true;
break;
}
}
}
}
if (bMatchRelationshipObj || process.containsSearchText(lowerCaseSearchText)) {
if (!processList.contains(process)) {
processList.add(process);
}
}
if (process instanceof ReactionStep) {
// we also search in reaction step expression, for strings like "s1 + s2" or s1 -> s2
ModelProcessEquation mpe = new ModelProcessEquation(process, bioModel.getModel());
if (mpe.toString().toLowerCase().contains(lowerCaseSearchText)) {
if (!processList.contains(process)) {
processList.add(process);
}
}
}
}
}
}
return processList;
}
use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.
the class BioModelEditorModelPanel method duplicateButtonPressed.
private void duplicateButtonPressed() {
computeCurrentSelectedTable();
int row = currentSelectedTable.getSelectedRow();
System.out.println("Duplicate Button Pressed for row " + row);
if (currentSelectedTable == reactionsTable) {
ModelProcess mp = reactionTableModel.getValueAt(row);
if (!(mp instanceof ReactionRule)) {
return;
}
ReactionRule oldRule = (ReactionRule) mp;
if (bioModel.getModel().getNumStructures() == 1) {
duplicateReactionRule(oldRule, oldRule.getStructure());
} else if (bioModel.getModel().getNumStructures() > 1) {
final JPopupMenu menu = new JPopupMenu("Choose compartment");
for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
String ourType = oldRule.getStructure().getTypeName();
Structure s = bioModel.getModel().getStructure(i);
String theirType = s.getTypeName();
if (!ourType.equals(theirType)) {
// offer to duplicate only within structures of the same type as the original,
continue;
// otherwise units will be meaningless (surface vs volume)
}
String sName = s.getName();
JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
menuItem.setIcon(new StructureToolShapeIcon(17));
menu.add(menuItem);
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
newObject = duplicateReactionRule(oldRule, s);
// moves selection on the newly created object
// if (newObject != null) {
// for (int i = 0; i < currentSelectedTableModel.getRowCount(); i ++) {
// if (currentSelectedTableModel.getValueAt(i) == newObject) {
// currentSelectedTable.setRowSelectionInterval(i, i);
// break;
// }
// }
// }
}
});
}
menu.show(duplicateButton, 0, duplicateButton.getHeight());
}
} else if (currentSelectedTable == speciesTable) {
SpeciesContext sc = speciesTableModel.getValueAt(row);
if (!sc.hasSpeciesPattern()) {
return;
}
if (bioModel.getModel().getNumStructures() == 1) {
duplicateSpecies(sc, sc.getStructure(), bioModel.getModel());
} else if (bioModel.getModel().getNumStructures() > 1) {
final JPopupMenu menu = new JPopupMenu("Choose compartment");
for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
String ourType = sc.getStructure().getTypeName();
Structure s = bioModel.getModel().getStructure(i);
String theirType = s.getTypeName();
if (!ourType.equals(theirType)) {
continue;
}
String sName = s.getName();
JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
menuItem.setIcon(new StructureToolShapeIcon(17));
menu.add(menuItem);
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
newObject = duplicateSpecies(sc, s, bioModel.getModel());
}
});
}
menu.show(duplicateButton, 0, duplicateButton.getHeight());
}
} else if (currentSelectedTable == observablesTable) {
RbmObservable o = observableTableModel.getValueAt(row);
if (o.getSpeciesPatternList().isEmpty()) {
return;
}
if (bioModel.getModel().getNumStructures() == 1) {
duplicateObservable(o, o.getStructure(), bioModel.getModel());
} else if (bioModel.getModel().getNumStructures() > 1) {
final JPopupMenu menu = new JPopupMenu("Choose compartment");
for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
Structure s = bioModel.getModel().getStructure(i);
String sName = s.getName();
JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
menuItem.setIcon(new StructureToolShapeIcon(17));
menu.add(menuItem);
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
newObject = duplicateObservable(o, s, bioModel.getModel());
}
});
}
menu.show(duplicateButton, 0, duplicateButton.getHeight());
}
}
}
use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.
the class PhysiologyRelationshipTableModel method refreshData.
private void refreshData() {
ArrayList<PhysiologyRelationshipTableRow> pathwayObjectList = new ArrayList<PhysiologyRelationshipTableRow>();
if (bioModel != null) {
HashSet<RelationshipObject> relationshipObjects = null;
if (bioModelEntityObject != null) {
relationshipObjects = bioModel.getRelationshipModel().getRelationshipObjects(bioModelEntityObject);
}
List<PhysiologyRelationshipTableRow> allPathwayObjectList = new ArrayList<PhysiologyRelationshipTableRow>();
for (BioPaxObject bpObject1 : bioModel.getPathwayModel().getBiopaxObjects()) {
if ((bpObject1 instanceof PhysicalEntity && (bioModelEntityObject == null || bioModelEntityObject instanceof SpeciesContext)) || (bpObject1 instanceof Conversion && (bioModelEntityObject == null || bioModelEntityObject instanceof ModelProcess)) || (bpObject1 instanceof PhysicalEntity && (bioModelEntityObject == null || bioModelEntityObject instanceof MolecularType))) {
PhysiologyRelationshipTableRow entityRow = new PhysiologyRelationshipTableRow(bpObject1);
if (relationshipObjects != null) {
for (RelationshipObject ro : relationshipObjects) {
if (ro.getBioPaxObject() == entityRow.getBioPaxObject()) {
entityRow.setSelected(true);
break;
}
}
}
if (!bShowLinkOnly || entityRow.selected) {
allPathwayObjectList.add(entityRow);
}
}
}
if (searchText == null || searchText.length() == 0) {
pathwayObjectList.addAll(allPathwayObjectList);
} else {
for (PhysiologyRelationshipTableRow rs : allPathwayObjectList) {
BioPaxObject bpObject = rs.getBioPaxObject();
String lowerCaseSearchText = searchText.toLowerCase();
if (getLabel(bpObject).toLowerCase().contains(lowerCaseSearchText) || getType(bpObject).toLowerCase().contains(lowerCaseSearchText)) {
pathwayObjectList.add(rs);
}
}
}
}
setData(pathwayObjectList);
GuiUtils.flexResizeTableColumns(ownerTable);
}
Aggregations