use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.
the class BioModelEditorReactionTableModel method setValueAt.
public void setValueAt(Object value, int row, int column) {
if (getModel() == null || value == null) {
return;
}
try {
ModelProcess modelProcess = getValueAt(row);
if (modelProcess != null) {
switch(column) {
case COLUMN_NAME:
{
String inputValue = ((String) value);
inputValue = inputValue.trim();
modelProcess.setName(inputValue);
break;
}
case COLUMN_EQUATION:
{
String inputValue = (String) value;
inputValue = inputValue.trim();
if (modelProcess instanceof ReactionStep) {
ReactionStep reactionStep = (ReactionStep) modelProcess;
ReactionParticipant[] rpArray = ModelProcessEquation.parseReaction(reactionStep, getModel(), inputValue);
for (ReactionParticipant rp : rpArray) {
SpeciesContext speciesContext = rp.getSpeciesContext();
if (bioModel.getModel().getSpeciesContext(speciesContext.getName()) == null) {
bioModel.getModel().addSpecies(speciesContext.getSpecies());
bioModel.getModel().addSpeciesContext(speciesContext);
}
}
reactionStep.setReactionParticipants(rpArray);
} else if (modelProcess instanceof ReactionRule) {
ReactionRule oldReactionRule = (ReactionRule) modelProcess;
// when editing an existing reaction rule
ReactionRule newReactionRule = (ReactionRule) RbmUtils.parseReactionRule(inputValue, oldReactionRule.getStructure(), bioModel);
if (newReactionRule != null) {
oldReactionRule.setProductPatterns(newReactionRule.getProductPatterns(), false, false);
oldReactionRule.setReactantPatterns(newReactionRule.getReactantPatterns(), false, false);
// String name = oldReactionRule.getName();
// RbmKineticLaw kl = oldReactionRule.getKineticLaw();
// Structure st = oldReactionRule.getStructure();
// getModel().getRbmModelContainer().removeReactionRule(oldReactionRule);
// newReactionRule.setName(name);
// newReactionRule.setKineticLaw(kl);
// newReactionRule.setStructure(st);
// getModel().getRbmModelContainer().addReactionRule(newReactionRule);
}
}
break;
}
case COLUMN_STRUCTURE:
{
Structure s = (Structure) value;
modelProcess.setStructure(s);
break;
}
}
} else {
switch(column) {
case COLUMN_EQUATION:
{
if (getModel().getNumStructures() == 1) {
String inputValue = ((String) value);
inputValue = inputValue.trim();
if (inputValue.contains("(") && inputValue.contains(")")) {
ReactionRule reactionRule = (ReactionRule) RbmUtils.parseReactionRule(inputValue, getModel().getStructure(0), bioModel);
getModel().getRbmModelContainer().addReactionRule(reactionRule);
} else {
if (BioModelEditorRightSideTableModel.ADD_NEW_HERE_REACTION_TEXT.equals(inputValue)) {
return;
}
ReactionStep reactionStep = getModel().createSimpleReaction(getModel().getStructure(0));
ReactionParticipant[] rpArray = ModelProcessEquation.parseReaction(reactionStep, getModel(), inputValue);
for (ReactionParticipant rp : rpArray) {
SpeciesContext speciesContext = rp.getSpeciesContext();
if (bioModel.getModel().getSpeciesContext(speciesContext.getName()) == null) {
bioModel.getModel().addSpecies(speciesContext.getSpecies());
bioModel.getModel().addSpeciesContext(speciesContext);
}
}
reactionStep.setReactionParticipants(rpArray);
}
}
break;
}
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
DialogUtils.showErrorDialog(ownerTable, e.getMessage(), e);
}
}
use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.
the class BioModelEditorModelPanel method deleteButtonPressed.
private void deleteButtonPressed() {
try {
ArrayList<Object> deleteList = new ArrayList<Object>();
int selectedIndex = tabbedPane.getSelectedIndex();
if (selectedIndex == ModelPanelTabID.reaction_diagram.ordinal()) {
deleteList.addAll(Arrays.asList(reactionCartoonEditorPanel.getReactionCartoon().getSelectedObjects()));
// } else if (selectedIndex == ModelPanelTabID.structure_diagram.ordinal()) {
// deleteList.addAll(Arrays.asList(cartoonEditorPanel.getStructureCartoon().getSelectedObjects()));
} else {
computeCurrentSelectedTable();
int[] rows = currentSelectedTable.getSelectedRows();
if (rows == null || rows.length == 0) {
return;
}
if (currentSelectedTable == speciesTable) {
for (int r : rows) {
if (r < speciesTableModel.getRowCount()) {
SpeciesContext speciesContext = speciesTableModel.getValueAt(r);
if (speciesContext != null) {
deleteList.add(speciesContext);
}
}
}
} else if (currentSelectedTable == molecularTypeTable) {
// TODO: delete stuff
for (int r : rows) {
if (r < molecularTypeTableModel.getRowCount()) {
MolecularType mt = molecularTypeTableModel.getValueAt(r);
if (mt != null) {
deleteList.add(mt);
}
}
}
} else if (currentSelectedTable == observablesTable) {
for (int r : rows) {
if (r < observableTableModel.getRowCount()) {
RbmObservable o = observableTableModel.getValueAt(r);
if (o != null) {
deleteList.add(o);
}
}
}
} else if (currentSelectedTable == structuresTable) {
for (int r : rows) {
if (r < structureTableModel.getRowCount()) {
Structure rowValue = structureTableModel.getValueAt(r);
if (rowValue instanceof Feature || rowValue instanceof Membrane) {
deleteList.add(rowValue);
}
}
}
} else if (currentSelectedTable == reactionsTable) {
for (int r : rows) {
if (r < reactionTableModel.getRowCount()) {
ModelProcess reaction = reactionTableModel.getValueAt(r);
if (reaction != null) {
deleteList.add(reaction);
}
}
}
}
}
if (deleteList.size() == 0) {
return;
}
StringBuilder deleteListText = new StringBuilder();
for (Object object : deleteList) {
if (object instanceof SpeciesContext) {
deleteListText.append("Species\t'" + ((SpeciesContext) object).getName() + "'\n");
} else if (object instanceof MolecularType) {
deleteListText.append(((MolecularType) object).getDisplayType() + "\t'" + ((MolecularType) object).getDisplayName() + "'\n");
} else if (object instanceof RbmObservable) {
deleteListText.append("Observable\t'" + ((RbmObservable) object).getName() + "'\n");
} else if (object instanceof ReactionStep) {
deleteListText.append("Reaction\t'" + ((ReactionStep) object).getName() + "'\n");
} else if (object instanceof ReactionRule) {
deleteListText.append("Reaction rule\t'" + ((ReactionRule) object).getName() + "'\n");
} else if (object instanceof Structure) {
deleteListText.append("Structure\t'" + ((Structure) object).getName() + "'\n");
}
}
// TODO: once we display reaction rules in the carton editor panel we'll have to change the way we delete reaction rules
if (deleteList.get(0) instanceof SpeciesContext || deleteList.get(0) instanceof ReactionStep) {
try {
ArrayList<SpeciesContext> speciesContextArrList = new ArrayList<SpeciesContext>();
ArrayList<ReactionStep> reactionStepArrList = new ArrayList<ReactionStep>();
for (Object obj : deleteList) {
if (obj instanceof SpeciesContext) {
speciesContextArrList.add((SpeciesContext) obj);
} else if (obj instanceof ReactionStep) {
reactionStepArrList.add((ReactionStep) obj);
} else {
throw new Exception("Unexpected delete object " + obj.getClass().getName());
}
}
ReactionCartoonTool.deleteReactionsAndSpecies(reactionCartoonEditorPanel, reactionStepArrList.toArray(new ReactionStep[0]), speciesContextArrList.toArray(new SpeciesContext[0]));
} catch (UserCancelException uce) {
return;
}
return;
} else {
String confirm = DialogUtils.showOKCancelWarningDialog(this, "Deleting", "You are going to delete the following:\n\n" + deleteListText + "\n Continue?");
if (confirm.equals(UserMessage.OPTION_CANCEL)) {
return;
}
for (Object object : deleteList) {
if (object instanceof ReactionRule) {
ReactionRule rr = (ReactionRule) object;
bioModel.getModel().getRbmModelContainer().removeReactionRule(rr);
} else if (object instanceof MolecularType) {
Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
MolecularType mt = (MolecularType) object;
if (!bioModel.getModel().getRbmModelContainer().isDeleteAllowed(mt, usedHere)) {
String errMsg = mt.getDisplayType() + " <b>'" + mt + "'</b> cannot be deleted because it's already being used by:<br>";
final int MaxListSize = 7;
int count = 0;
for (String key : usedHere.keySet()) {
System.out.println(key);
if (count >= MaxListSize) {
errMsg += "<br> ... and more.";
break;
}
Pair<Displayable, SpeciesPattern> o = usedHere.get(key);
Displayable e = o.one;
SpeciesPattern sp = o.two;
errMsg += "<br> - " + e.getDisplayType().toLowerCase() + " <b>" + e.getDisplayName() + "</b>";
errMsg += ", " + sp.getDisplayType().toLowerCase() + " " + " <b>" + sp.getDisplayName() + "</b>";
count++;
}
errMsg = "<html>" + errMsg + "</html>";
throw new RuntimeException(errMsg);
}
bioModel.getModel().getRbmModelContainer().removeMolecularType(mt);
} else if (object instanceof RbmObservable) {
RbmObservable o = (RbmObservable) object;
bioModel.getModel().getRbmModelContainer().removeObservable(o);
} else {
bioModel.getModel().removeObject(object);
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
DialogUtils.showErrorDialog(this, ex.getMessage());
}
}
use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.
the class ModelProcessSpecsPanel method initConnections.
/**
* Initializes connections
* @exception java.lang.Exception The exception description.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initConnections() throws java.lang.Exception {
// user code begin {1}
// user code end
this.addPropertyChangeListener(ivjEventHandler);
getScrollPaneTable().setModel(getModelProcessSpecsTableModel());
getScrollPaneTable().setDefaultRenderer(ModelProcess.class, new DefaultScrollTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
defaultToolTipText = null;
if (value instanceof ModelProcess) {
setText(((ModelProcess) value).getName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
}
TableModel tableModel = table.getModel();
if (tableModel instanceof SortTableModel) {
DefaultScrollTableCellRenderer.issueRenderer(this, defaultToolTipText, table, row, column, (SortTableModel) tableModel);
}
return this;
}
});
DefaultScrollTableCellRenderer rbmReactionShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {
List<SpeciesPatternSmallShape> spssList = new ArrayList<SpeciesPatternSmallShape>();
SpeciesPatternSmallShape spss = null;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == ivjModelProcessSpecsTableModel) {
selectedObject = ivjModelProcessSpecsTableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof ModelProcessSpec) {
ModelProcessSpec mps = (ModelProcessSpec) selectedObject;
ModelProcess mp = (ModelProcess) mps.getModelProcess();
if (mp instanceof ReactionRule) {
ReactionRule rr = (ReactionRule) mp;
Graphics panelContext = table.getGraphics();
spssList.clear();
List<ReactantPattern> rpList = rr.getReactantPatterns();
int xPos = 4;
for (int i = 0; i < rpList.size(); i++) {
SpeciesPattern sp = rr.getReactantPattern(i).getSpeciesPattern();
spss = new SpeciesPatternSmallShape(xPos, 2, sp, shapeManager, panelContext, rr, isSelected, issueManager);
if (i < rpList.size() - 1) {
spss.addEndText("+");
} else {
if (rr.isReversible()) {
spss.addEndText("<->");
xPos += 7;
} else {
spss.addEndText("->");
}
}
xPos += spss.getWidth() + 15;
spssList.add(spss);
}
List<ProductPattern> ppList = rr.getProductPatterns();
xPos += 7;
for (int i = 0; i < ppList.size(); i++) {
SpeciesPattern sp = rr.getProductPattern(i).getSpeciesPattern();
spss = new SpeciesPatternSmallShape(xPos, 2, sp, shapeManager, panelContext, rr, isSelected, issueManager);
if (i < ppList.size() - 1) {
spss.addEndText("+");
}
xPos += spss.getWidth() + 15;
spssList.add(spss);
}
} else {
ReactionStep rs = (ReactionStep) mp;
Graphics panelContext = table.getGraphics();
spssList.clear();
int xPos = 4;
int extraSpace = 0;
for (int i = 0; i < rs.getNumReactants(); i++) {
SpeciesPattern sp = rs.getReactant(i).getSpeciesContext().getSpeciesPattern();
spss = new SpeciesPatternSmallShape(xPos, 2, sp, shapeManager, panelContext, rs, isSelected, issueManager);
if (i < rs.getNumReactants() - 1) {
spss.addEndText("+");
} else {
if (rs.isReversible()) {
spss.addEndText("<->");
extraSpace += 7;
} else {
spss.addEndText("->");
}
}
int offset = sp == null ? 17 : 15;
offset += extraSpace;
int w = spss.getWidth();
xPos += w + offset;
spssList.add(spss);
}
xPos += 8;
for (int i = 0; i < rs.getNumProducts(); i++) {
SpeciesPattern sp = rs.getProduct(i).getSpeciesContext().getSpeciesPattern();
if (i == 0 && rs.getNumReactants() == 0) {
xPos += 14;
}
spss = new SpeciesPatternSmallShape(xPos, 2, sp, shapeManager, panelContext, rs, isSelected, issueManager);
if (i == 0 && rs.getNumReactants() == 0) {
spss.addStartText("->");
}
if (i < rs.getNumProducts() - 1) {
spss.addEndText("+");
}
int offset = sp == null ? 17 : 15;
int w = spss.getWidth();
xPos += w + offset;
spssList.add(spss);
}
}
}
} else {
spssList.clear();
}
}
setText("");
return this;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (SpeciesPatternSmallShape spss : spssList) {
if (spss == null) {
continue;
}
spss.paintSelf(g);
}
}
};
getScrollPaneTable().setDefaultRenderer(SpeciesPattern.class, rbmReactionShapeDepictionCellRenderer);
// ivjScrollPaneTable.getColumnModel().getColumn(ModelProcessSpecsTableModel.ColumnType.COLUMN_DEPICTION.ordinal()).setCellRenderer(rbmReactionShapeDepictionCellRenderer);
// ivjScrollPaneTable.getColumnModel().getColumn(ModelProcessSpecsTableModel.ColumnType.COLUMN_DEPICTION.ordinal()).setPreferredWidth(180);
getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
}
use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.
the class BioModelEditorReactionTableModel method bioModelChange.
@Override
protected void bioModelChange(PropertyChangeEvent evt) {
super.bioModelChange(evt);
// ownerTable.getColumnModel().getColumn(COLUMN_STRUCTURE).setCellEditor(getStructureComboBoxEditor());
// updateStructureComboBox();
BioModel oldValue = (BioModel) evt.getOldValue();
if (oldValue != null) {
for (ModelProcess p : oldValue.getModel().getModelProcesses()) {
p.removePropertyChangeListener(this);
}
}
BioModel newValue = (BioModel) evt.getNewValue();
if (newValue != null) {
for (ModelProcess p : newValue.getModel().getModelProcesses()) {
p.addPropertyChangeListener(this);
}
}
}
use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.
the class BioModelEditorReactionTableModel method getComparator.
@Override
public Comparator<ModelProcess> getComparator(final int col, final boolean ascending) {
return new Comparator<ModelProcess>() {
public int compare(ModelProcess o1, ModelProcess o2) {
int scale = ascending ? 1 : -1;
switch(col) {
case COLUMN_NAME:
// TODO: find a good "natural order" sorting algorithm
return // normal ASCII sort
scale * o1.getName().compareTo(o2.getName());
case COLUMN_EQUATION:
ModelProcessEquation re1 = new ModelProcessEquation(o1, bioModel.getModel());
ModelProcessEquation re2 = new ModelProcessEquation(o2, bioModel.getModel());
if (o1 instanceof ReactionStep && o2 instanceof ReactionRule) {
return scale;
} else if (o1 instanceof ReactionRule && o2 instanceof ReactionStep) {
return -scale;
}
// this field simply says "Reaction Rule" for all rules
return scale * re1.toString().compareTo(re2.toString());
case COLUMN_STRUCTURE:
return scale * o1.getStructure().getName().compareTo(o2.getStructure().getName());
case COLUMN_DEPICTION:
if (o1 instanceof ReactionStep && o2 instanceof ReactionRule) {
return scale;
} else if (o1 instanceof ReactionRule && o2 instanceof ReactionStep) {
return -scale;
}
return scale * o1.getNumParticipants().compareTo(o2.getNumParticipants());
case COLUMN_KINETICS:
return scale * o1.getDynamics().toString().compareTo(o2.getDynamics().toString());
case COLUMN_DEFINITION:
ModelProcessEquation mpe1 = new ModelProcessEquation(o1, bioModel.getModel());
ModelProcessEquation mpe2 = new ModelProcessEquation(o2, bioModel.getModel());
if (o1 instanceof ReactionStep && o2 instanceof ReactionRule) {
return scale;
} else if (o1 instanceof ReactionRule && o2 instanceof ReactionStep) {
return -scale;
}
// for rules, we compare just the equation strings, without the "@Compartment:" prefix
return scale * mpe1.toString().compareToIgnoreCase(mpe2.toString());
default:
return 0;
}
}
};
}
Aggregations