use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class StructureMappingTableModel method setValueAt.
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if (rowIndex < 0 || rowIndex >= getRowCount()) {
throw new RuntimeException("StructureMappingTableModel.setValueAt(), row = " + rowIndex + " out of range [" + 0 + "," + (getRowCount() - 1) + "]");
}
if (columnIndex < 0 || columnIndex >= getColumnCount()) {
throw new RuntimeException("StructureMappingTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (getColumnCount() - 1) + "]");
}
StructureMapping structureMapping = getValueAt(rowIndex);
Structure structure = structureMapping.getStructure();
if (bNonSpatial) {
switch(columnIndex) {
case NONSPATIAL_COLUMN_SIZE:
{
try {
Expression exp = null;
if (aValue instanceof String) {
exp = new Expression((String) aValue);
} else if (aValue instanceof Double) {
exp = new Expression(((Double) aValue).doubleValue());
}
// if the input volumn is null, leave it as it was.
if (exp != null) {
// for old ode model, once one size is input, solve the rest. if it is unnamed compartment(the only one), we don't need to solve anything
if (!getGeometryContext().getSimulationContext().isStoch() && getGeometryContext().isAllSizeSpecifiedNull() && getGeometryContext().isAllVolFracAndSurfVolSpecified() && getGeometryContext().getStructureMappings().length > 1) {
structureMapping.getSizeParameter().setExpression(exp);
double size;
try {
size = exp.evaluateConstant();
VCUnitDefinition volumeUnit = getGeometryContext().getSimulationContext().getModel().getUnitSystem().getVolumeUnit();
StructureSizeSolver.updateAbsoluteStructureSizes(getGeometryContext().getSimulationContext(), structure, size, volumeUnit);
fireTableRowsUpdated(0, getRowCount());
} catch (ExpressionException ex) {
ex.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Size of Feature " + structure.getName() + " can not be solved as constant!");
} catch (Exception ex) {
ex.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
}
} else {
structureMapping.getSizeParameter().setExpression(exp);
// set fraction in stoch math description, because these might be used when copy from stoch app to ode app.
if (getGeometryContext().isAllSizeSpecifiedPositive()) /*&& !getGeometryContext().getSimulationContext().isStoch()*/
{
try {
StructureSizeSolver.updateRelativeStructureSizes(getGeometryContext().getSimulationContext());
} catch (Exception ex) {
ex.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
}
}
}
}
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
}
break;
}
}
} else {
switch(columnIndex) {
case SPATIAL_COLUMN_SUBDOMAIN:
{
GeometryClass geometryClass = null;
if (aValue instanceof String) {
String svname = (String) aValue;
geometryClass = getGeometryContext().getGeometry().getGeometryClass(svname);
} else if (aValue instanceof GeometryClass) {
geometryClass = (GeometryClass) aValue;
}
if (geometryClass != null) {
try {
getGeometryContext().assignStructure(structure, geometryClass);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
} catch (IllegalMappingException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
} catch (MappingException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
}
}
break;
}
case SPATIAL_COLUMN_SIZERATIO:
try {
Expression exp = null;
if (aValue instanceof String) {
exp = new Expression((String) aValue);
} else if (aValue instanceof Double) {
exp = new Expression(((Double) aValue).doubleValue());
}
if (exp != null) {
structureMapping.getUnitSizeParameter().setExpression(exp);
StructureSizeSolver.updateUnitStructureSizes(getGeometryContext().getSimulationContext(), structureMapping.getGeometryClass());
}
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
}
break;
case SPATIAL_COLUMN_X_MINUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeXm(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_X_PLUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeXp(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_Y_MINUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeYm(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_Y_PLUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeYp(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_Z_MINUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeZm(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_Z_PLUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeZp(new BoundaryConditionType((String) aValue));
}
break;
}
}
}
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class ReactionCartoonTool method menuAction.
@Override
protected void menuAction(Shape shape, String menuAction) {
if (shape == null) {
return;
}
if (menuAction.equals(CartoonToolMiscActions.Properties.MENU_ACTION)) {
if (shape instanceof FluxReactionShape) {
// showFluxReactionPropertiesDialog((FluxReactionShape) shape);
} else if (shape instanceof SimpleReactionShape) {
// showSimpleReactionPropertiesDialog((SimpleReactionShape) shape);
} else if (shape instanceof ReactantShape) {
// Point locationOnScreen = shape.getSpaceManager().getAbsLoc();
// Point graphPaneLocation = getGraphPane().getLocationOnScreen();
// locationOnScreen.translate(graphPaneLocation.x,
// graphPaneLocation.y);
// showReactantPropertiesDialog((ReactantShape) shape,
// locationOnScreen);
} else if (shape instanceof ProductShape) {
// Point locationOnScreen = shape.getSpaceManager().getAbsLoc();
// Point graphPaneLocation = getGraphPane().getLocationOnScreen();
// locationOnScreen.translate(graphPaneLocation.x,
// graphPaneLocation.y);
// showProductPropertiesDialog((ProductShape) shape,
// locationOnScreen);
} else if (shape instanceof SpeciesContextShape) {
// showEditSpeciesDialog(getGraphPane(), getReactionCartoon()
// .getModel(), ((SpeciesContextShape) shape)
// .getSpeciesContext());
} else if (shape instanceof ReactionContainerShape) {
// ReactionContainerShape rcs = (ReactionContainerShape) shape;
// if (rcs.getStructure() instanceof Feature) {
// //
// // showFeaturePropertyDialog is invoked in two modes:
// //
// // 1) parent!=null and child==null
// // upon ok, it adds a new feature to the supplied parent.
// //
// // 2) parent==null and child!=null
// // upon ok, edits the feature name
// //
// showFeaturePropertiesDialog(getGraphPane(),
// (getReactionCartoon().getModel() == null ? null
// : getReactionCartoon().getModel()), null,
// (Feature) rcs.getStructure());
// } else if (rcs.getStructure() instanceof Membrane) {
// showMembranePropertiesDialog(getGraphPane(), (Membrane) rcs
// .getStructure());
// }
}
} else if (menuAction.equals(CartoonToolMiscActions.AddSpecies.MENU_ACTION)) {
if (shape instanceof ReactionContainerShape) {
getGraphModel().deselectShape(shape);
// showCreateSpeciesContextDialog(getGraphPane(),
// getReactionCartoon().getModel(),
// ((ReactionContainerShape) shape).getStructure(), null);
SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) shape).getStructure());
getGraphModel().select(speciesContext);
}
} else if (menuAction.equals(CartoonToolEditActions.Copy.MENU_ACTION)) {
if (shape instanceof SpeciesContextShape || shape instanceof ReactionStepShape || // rule participants whose rule is not selected won't
shape instanceof RuleParticipantSignatureDiagramShape || // be copied since standalone they are meaningless
shape instanceof ReactionRuleDiagramShape) {
SpeciesContext[] spArray = getSelectedSpeciesContextArray();
ReactionStep[] rsArray = getSelectedReactionStepArray();
ReactionRule[] rrArray = getSelectedReactionRuleArray();
MolecularType[] mtArray = getSelectedMolecularTypeArray(rrArray, rsArray, spArray);
Structure[] structArray = getSelectedStructuresArray(rrArray, rsArray, spArray, mtArray);
Structure fromStruct = null;
ReactionContainerShape rcs = null;
Shape parentShape = shape.getParent();
if (parentShape instanceof ReactionContainerShape) {
rcs = (ReactionContainerShape) parentShape;
fromStruct = rcs.getStructure();
}
ReactionSpeciesCopy reactionSpeciesCopy = new ReactionSpeciesCopy(spArray, rsArray, rrArray, mtArray, fromStruct, structArray);
VCellTransferable.sendToClipboard(reactionSpeciesCopy);
}
} else if (/*menuAction.equals(CartoonToolEditActions.Paste.MENU_ACTION)
|| */
menuAction.equals(CartoonToolEditActions.PasteNew.MENU_ACTION)) {
if (shape instanceof ReactionContainerShape) {
pasteReactionsAndSpecies(((ReactionContainerShape) shape).getStructure());
}
} else if (menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
try {
if (getGraphModel().getSelectedShape() instanceof ReactionContainerShape && menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
getModel().removeStructure(((ReactionContainerShape) getGraphModel().getSelectedShape()).getStructure());
return;
}
if (getSelectedReactionStepArray() != null || getSelectedSpeciesContextArray() != null) {
deleteReactionsAndSpecies(getGraphPane(), getSelectedReactionStepArray(), getSelectedSpeciesContextArray());
}
if (getSelectedReactionParticipantArray() != null && menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
ReactionParticipant[] reactionParticipantArr = getSelectedReactionParticipantArray();
String response = DialogUtils.showWarningDialog(getGraphPane(), "Delete " + reactionParticipantArr.length + " Reaction Stoichiometries", new String[] { RXSPECIES_DELETE, RXSPECIES_CANCEL }, RXSPECIES_CANCEL);
if (response != null && response.equals(RXSPECIES_DELETE)) {
for (int i = 0; i < reactionParticipantArr.length; i++) {
ReactionStep reactionStep = reactionParticipantArr[i].getReactionStep();
reactionStep.removeReactionParticipant(reactionParticipantArr[i]);
}
}
}
} catch (UserCancelException uce) {
return;
} catch (PropertyVetoException e) {
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage());
} catch (Exception e) {
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
} else if (menuAction.equals(CartoonToolMiscActions.SearchReactions.MENU_ACTION)) {
try {
if (shape instanceof ReactionContainerShape) {
showReactionBrowserDialog(((ReactionContainerShape) shape).getStructure(), null);
}
} catch (Exception e) {
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
} else if (menuAction.equals(CartoonToolSaveAsImageActions.MenuAction.MENU_ACTION)) {
try {
String resType = null;
if (shape instanceof ReactionContainerShape) {
showSaveReactionImageDialog();
}
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
} else if (menuAction.equals(CartoonToolMiscActions.Annotate.MENU_ACTION)) {
if (shape instanceof ReactionStepShape) {
// MIRIAMHelper.showMIRIAMAnnotationDialog(((SimpleReactionShape)shape).getReactionStep());
// System.out.println("Menu action annotate activated...");
ReactionStep rs = ((ReactionStepShape) shape).getReactionStep();
VCMetaData vcMetaData = rs.getModel().getVcMetaData();
try {
String newAnnotation = DialogUtils.showAnnotationDialog(getGraphPane(), vcMetaData.getFreeTextAnnotation(rs));
vcMetaData.setFreeTextAnnotation(rs, newAnnotation);
} catch (UtilCancelException e) {
// Do Nothing
} catch (Throwable exc) {
exc.printStackTrace(System.out);
DialogUtils.showErrorDialog(getGraphPane(), "Failed to edit annotation!\n" + exc.getMessage(), exc);
}
}
} else {
// default action is to ignore
}
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class BioCartoonTool method getNewSpecies.
private static Species getNewSpecies(IdentityHashMap<Species, Species> speciesHash, Species copyFromSpecies, Model pasteToModel, boolean bNew, /* boolean bUseDBSpecies,*/
Structure pasteToStruct, HashMap<Structure, Species> userPreferredToTarget) {
Species newSpecies = speciesHash.get(copyFromSpecies);
if (newSpecies != null) {
return newSpecies;
}
Species preferredToSpecies = (userPreferredToTarget != null ? userPreferredToTarget.values().iterator().next() : null);
try {
if (bNew || (userPreferredToTarget != null && preferredToSpecies == null)) {
String newName = copyFromSpecies.getCommonName();
while (pasteToModel.getSpecies(newName) != null) {
newName = org.vcell.util.TokenMangler.getNextEnumeratedToken(newName);
}
newSpecies = new Species(newName, copyFromSpecies.getAnnotation(), copyFromSpecies.getDBSpecies());
pasteToModel.addSpecies(newSpecies);
speciesHash.put(copyFromSpecies, newSpecies);
} else {
// Find a matching existing species if possible
if (preferredToSpecies != null) {
return preferredToSpecies;
}
if (!pasteToModel.contains(copyFromSpecies)) {
// Doesn't have Species (==)
// see if we have a species with DBSpecies that matches
// Species[] speciesFromDBSpeciesArr = (copyFromSpecies.getDBSpecies() != null ? pasteToModel.getSpecies(copyFromSpecies.getDBSpecies()) : null);
// if(/*bUseDBSpecies && */speciesFromDBSpeciesArr != null && speciesFromDBSpeciesArr.length > 0){//DBSpecies match
// //Choose the species in struct if exists
// newSpecies = speciesFromDBSpeciesArr[0];
// for(int i=0;i<speciesFromDBSpeciesArr.length;i+= 1){
// if(pasteToModel.getSpeciesContext(speciesFromDBSpeciesArr[i], pasteToStruct) != null){
// newSpecies = speciesFromDBSpeciesArr[i];
// break;
// }
// }
// }else{// No DBSpecies match
// See if there is a species with same name
newSpecies = pasteToModel.getSpecies(copyFromSpecies.getCommonName());
if (newSpecies == null) {
// No name matches
String newName = copyFromSpecies.getCommonName();
newSpecies = new Species(newName, copyFromSpecies.getAnnotation(), copyFromSpecies.getDBSpecies());
pasteToModel.addSpecies(newSpecies);
speciesHash.put(copyFromSpecies, newSpecies);
}
// }
} else {
// Has species (==)
newSpecies = copyFromSpecies;
}
}
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Could not add species to model : " + e.getMessage());
}
return newSpecies;
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class BioCartoonTool method mapStructures.
// map the structures to be pasted to existing structures in the cloned model
// we may need to generate some name iteratively until we solve all naming conflicts
private static Map<Structure, String> mapStructures(Component requester, ReactionSpeciesCopy rsCopy, Model modelTo, Structure structTo, IssueContext issueContext) {
// use internally only; we exit the dialog when there are no issues left
Vector<Issue> issueVector = new Vector<>();
Structure structFrom = rsCopy.getFromStructure();
Map<Structure, String> fullyMappedStructures = new LinkedHashMap<>();
fullyMappedStructures.put(structFrom, structTo.getName());
StructurePasteMappingPanel structureMappingPanel = null;
do {
issueVector.clear();
if (structureMappingPanel == null) {
structureMappingPanel = new StructurePasteMappingPanel(rsCopy, modelTo, structTo, issueVector, issueContext);
structureMappingPanel.setPreferredSize(new Dimension(400, 220));
}
int result = DialogUtils.showComponentOKCancelDialog(requester, structureMappingPanel, "Assign 'From' structures to 'To' structures");
if (result != JOptionPane.OK_OPTION) {
throw UserCancelException.CANCEL_GENERIC;
}
} while (structureMappingPanel.hasErrors());
for (Map.Entry<Structure, JComboBox<String>> entry : structureMappingPanel.getStructureMap().entrySet()) {
if (entry.getValue().getSelectedItem().equals(StructurePasteMappingPanel.MAKE_NEW)) {
// we generate a "to" structure name based on the "from" name
String newNameTo = entry.getKey().getName();
while (modelTo.getStructure(newNameTo) != null) {
newNameTo = org.vcell.util.TokenMangler.getNextEnumeratedToken(newNameTo);
for (Structure sFrom : rsCopy.getStructuresArr()) {
if (newNameTo.equals(sFrom.getName())) {
// the new name must not match any existing "from" name either
newNameTo = org.vcell.util.TokenMangler.getNextEnumeratedToken(newNameTo);
break;
}
}
}
try {
// as to avoid risk of duplicates / conflicting names
if (entry.getKey() instanceof Membrane) {
modelTo.addMembrane(newNameTo);
} else {
modelTo.addFeature(newNameTo);
}
} catch (ModelException | PropertyVetoException e) {
throw new RuntimeException("Failed to generate the missing 'from' Structures in the cloned model, " + e.getMessage());
}
fullyMappedStructures.put(entry.getKey(), newNameTo);
} else {
// name of an existing "to" structure
fullyMappedStructures.put(entry.getKey(), (String) entry.getValue().getSelectedItem());
}
}
return fullyMappedStructures;
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class GeomDbDriver method getGeometry.
/**
* This method was created in VisualAge.
* @return cbit.vcell.model.Model
* @param rset java.sql.ResultSet
*/
private Geometry getGeometry(QueryHashtable dbc, Connection con, User user, ResultSet rset) throws SQLException, DataAccessException {
//
// get Image reference
//
java.math.BigDecimal bigD = rset.getBigDecimal(geomTable.imageRef.toString());
KeyValue imageRef = null;
if (!rset.wasNull()) {
imageRef = new KeyValue(bigD);
}
//
// get geometry object
//
Geometry tempGeometry = null;
try {
tempGeometry = geomTable.getGeometry(rset, con);
} catch (PropertyVetoException e) {
throw new DataAccessException(e.getMessage());
}
Geometry geom = null;
//
// get image for this geometry
//
VCImage vcImage = null;
if (imageRef != null) {
// permission checking for the image is disabled because it is a child of this geometry
vcImage = getVCImage(dbc, con, user, imageRef, false);
}
if (vcImage != null) {
geom = new Geometry(tempGeometry, vcImage);
} else {
geom = tempGeometry;
}
//
// get SubVolumes for this geometry
//
SubVolume[] subVolumes = getSubVolumesFromGeometry(dbc, con, geom.getVersion().getVersionKey());
if (subVolumes != null) {
try {
geom.getGeometrySpec().setSubVolumes(subVolumes);
} catch (java.beans.PropertyVetoException e) {
lg.error(e.getMessage(), e);
throw new DataAccessException(e.getMessage());
}
}
//
if (geom.getDimension() > 0) {
getSurfaceDescription(con, geom);
}
//
if (geom.getDimension() > 0) {
getFilaments(con, geom);
}
//
// get SurfaceClasses for this geometry
//
SurfaceClass[] surfaceClasses = getSurfaceClassesFromGeometry(dbc, con, geom.getVersion().getVersionKey());
if (surfaceClasses != null) {
try {
geom.getGeometrySurfaceDescription().setSurfaceClasses(surfaceClasses);
} catch (java.beans.PropertyVetoException e) {
lg.error(e.getMessage(), e);
throw new DataAccessException(e.getMessage());
}
}
return geom;
}
Aggregations