use of org.vcell.util.document.Versionable in project vcell by virtualcell.
the class BioModelTreePanel method setSelectedVersionable.
/**
* Sets the selectedVersionable property (cbit.sql.Versionable) value.
* @param selectedVersionable The new value for the property.
* @see #getSelectedVersionable
*/
private void setSelectedVersionable(Versionable selectedVersionable) {
Versionable oldValue = fieldSelectedVersionable;
fieldSelectedVersionable = selectedVersionable;
firePropertyChange(PROPERTY_NAME_SELECTED_VERSIONABLE, oldValue, selectedVersionable);
}
use of org.vcell.util.document.Versionable in project vcell by virtualcell.
the class BioModelTreePanel method treeSelection.
/**
* Comment
*/
private Versionable treeSelection() {
TreePath treePath = getselectionModel1().getSelectionPath();
if (treePath == null) {
setSelectedVersionable(null);
return null;
}
BioModelNode bioModelNode = (BioModelNode) treePath.getLastPathComponent();
Object object = bioModelNode.getUserObject();
if (object instanceof Versionable) {
setSelectedVersionable((Versionable) object);
return (Versionable) object;
} else {
setSelectedVersionable(null);
return null;
}
}
use of org.vcell.util.document.Versionable in project vcell by virtualcell.
the class ServerDocumentManager method isChanged.
/**
* Insert the method's description here.
* Creation date: (2/5/01 4:58:40 PM)
*/
boolean isChanged(QueryHashtable dbc, User user, cbit.image.VCImage vcImage) throws org.vcell.util.DataAccessException {
//
// identify versionable as it was last loaded from the database
//
KeyValue key = (vcImage.getVersion() != null) ? (vcImage.getVersion().getVersionKey()) : null;
if (key == null) {
return true;
}
Versionable savedVersionable = null;
//
try {
savedVersionable = dbServer.getDBTopLevel().getVCImage(dbc, user, key, true);
} catch (ObjectNotFoundException e) {
//
return true;
} catch (Throwable e) {
//
// loaded version has been deleted
//
lg.error(e.getLocalizedMessage(), e);
return true;
}
return isChanged0(user, vcImage, savedVersionable);
}
use of org.vcell.util.document.Versionable in project vcell by virtualcell.
the class BioModelTreePanel method getJMenuCopyAs.
/**
* Return the JMenuItemCopy property value.
* @return javax.swing.JMenuItem
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JMenu getJMenuCopyAs() {
if (ivjJMenuCopyAs == null) {
try {
ivjJMenuCopyAs = new javax.swing.JMenu();
ivjJMenuCopyAs.setName("JMenuCopy");
ivjJMenuCopyAs.setText("Copy As");
// Menu items in Menu-Copy
menuItemNonSpatialCopyStochastic = new JMenuItem();
menuItemNonSpatialCopyStochastic.setName("JMenuItemToStochApp");
menuItemNonSpatialCopyStochastic.setText(MENU_TEXT_STOCHASTIC_APPLICATION);
menuItemNonSpatialCopyStochastic.setActionCommand(GuiConstants.ACTIONCMD_NON_SPATIAL_COPY_TO_STOCHASTIC_APPLICATION);
menuItemNonSpatialCopyDeterministic = new javax.swing.JMenuItem();
menuItemNonSpatialCopyDeterministic.setName("JMenuItemToNonStochApp");
menuItemNonSpatialCopyDeterministic.setText(MENU_TEXT_DETERMINISTIC_APPLICATION);
menuItemNonSpatialCopyDeterministic.setActionCommand(GuiConstants.ACTIONCMD_NON_SPATIAL_COPY_TO_DETERMINISTIC_APPLICATION);
menuSpatialCopyAsNonSpatial = new JMenu(MENU_TEXT_NON_SPATIAL_APPLICATION);
menuItemSpatialCopyAsNonSpatialDeterministic = new JMenuItem(MENU_TEXT_DETERMINISTIC_APPLICATION);
menuItemSpatialCopyAsNonSpatialDeterministic.setActionCommand(GuiConstants.ACTIONCMD_SPATIAL_COPY_TO_NON_SPATIAL_DETERMINISTIC_APPLICATION);
menuItemSpatialCopyAsNonSpatialStochastic = new JMenuItem(MENU_TEXT_STOCHASTIC_APPLICATION);
menuItemSpatialCopyAsNonSpatialStochastic.setActionCommand(GuiConstants.ACTIONCMD_SPATIAL_COPY_TO_NON_SPATIAL_STOCHASTIC_APPLICATION);
menuSpatialCopyAsNonSpatial.add(menuItemSpatialCopyAsNonSpatialDeterministic);
menuSpatialCopyAsNonSpatial.add(menuItemSpatialCopyAsNonSpatialStochastic);
menuSpatialCopyAsSpatial = new JMenu(MENU_TEXT_SPATIAL_APPLICATION);
menuItemSpatialCopyAsSpatialDeterministic = new JMenuItem(MENU_TEXT_DETERMINISTIC_APPLICATION);
menuItemSpatialCopyAsSpatialDeterministic.setActionCommand(GuiConstants.ACTIONCMD_SPATIAL_COPY_TO_SPATIAL_DETERMINISTIC_APPLICATION);
menuItemSpatialCopyAsSpatialStochastic = new JMenuItem(MENU_TEXT_STOCHASTIC_APPLICATION);
menuItemSpatialCopyAsSpatialStochastic.setActionCommand(GuiConstants.ACTIONCMD_SPATIAL_COPY_TO_SPATIAL_STOCHASTIC_APPLICATION);
menuSpatialCopyAsSpatial.add(menuItemSpatialCopyAsSpatialDeterministic);
menuSpatialCopyAsSpatial.add(menuItemSpatialCopyAsSpatialStochastic);
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
ivjJMenuCopyAs.removeAll();
Versionable selectedSimContext = getSelectedVersionable();
if (selectedSimContext != null && selectedSimContext instanceof SimulationContext && ((SimulationContext) selectedSimContext).getGeometry().getDimension() == 0 || getSelectedApplicationParent() != null && getSelectedApplicationParent().getGeometry().getDimension() == 0) {
// add menu items to menu
ivjJMenuCopyAs.add(menuItemNonSpatialCopyDeterministic);
ivjJMenuCopyAs.add(menuItemNonSpatialCopyStochastic);
} else {
ivjJMenuCopyAs.add(menuSpatialCopyAsNonSpatial);
ivjJMenuCopyAs.add(menuSpatialCopyAsSpatial);
}
return ivjJMenuCopyAs;
}
use of org.vcell.util.document.Versionable in project vcell by virtualcell.
the class ServerDocumentManager method saveSimulation.
/**
* Insert the method's description here.
* Creation date: (10/28/00 12:08:30 AM)
* @deprecated for testing purposes only.
*/
public String saveSimulation(QueryHashtable dbc, User user, String simulationXML, boolean bForceIndependent) throws DataAccessException, java.sql.SQLException, java.beans.PropertyVetoException, cbit.vcell.xml.XmlParseException {
//
// this invokes "update" on the database layer
//
Simulation simulation = XmlHelper.XMLToSim(simulationXML);
forceDeepDirtyIfForeign(user, simulation);
Version oldVersion = simulation.getVersion();
Simulation origSimulation = null;
if (oldVersion != null) {
try {
origSimulation = dbServer.getDBTopLevel().getSimulation(dbc, user, oldVersion.getVersionKey());
} catch (ObjectNotFoundException e) {
}
}
boolean bSomethingChanged = false;
//
// UPDATE AND SUBSTITUTE FROM BOTTOM UP
//
// Image->Geometry
// Geometry->MathDescription
// MathDescription->Simulation
//
//
// if this simulation has an image:
// save if necessary (only once) and store saved instance in hashTable
//
Hashtable<Versionable, Versionable> memoryToDatabaseHash = new Hashtable<Versionable, Versionable>();
{
VCImage memoryImage = simulation.getMathDescription().getGeometry().getGeometrySpec().getImage();
if (memoryImage != null) {
// defaults to unchanged
memoryToDatabaseHash.put(memoryImage, memoryImage);
if (memoryImage.getKey() != null && memoryImage.getVersion().getName().equals(memoryImage.getName())) {
//
// if image had previously been saved, not been forced 'dirty', and name not changed
// compare with original image to see if "update" is required.
//
VCImage databaseImage = null;
if (origSimulation != null) {
VCImage origImage = origSimulation.getMathDescription().getGeometry().getGeometrySpec().getImage();
if (origImage != null && origImage.getKey().equals(memoryImage.getKey())) {
databaseImage = origImage;
}
}
if (databaseImage == null) {
//
// saved image not found in origMathModel (too bad), get from database.
//
databaseImage = dbServer.getDBTopLevel().getVCImage(dbc, user, memoryImage.getKey(), false);
}
if (databaseImage != null && !databaseImage.compareEqual(memoryImage)) {
KeyValue updatedImageKey = dbServer.getDBTopLevel().updateVersionable(user, memoryImage, false, true);
VCImage updatedImage = dbServer.getDBTopLevel().getVCImage(dbc, user, updatedImageKey, false);
memoryToDatabaseHash.put(memoryImage, updatedImage);
bSomethingChanged = true;
}
} else {
//
// Image hasn't been saved, has been renamed, or has been forced 'dirty'
// insert it with a unique name
//
int count = 0;
fixNullImageName(memoryImage);
while (dbServer.getDBTopLevel().isNameUsed(user, VersionableType.VCImage, memoryImage.getName(), true)) {
try {
memoryImage.setName(TokenMangler.getNextRandomToken(memoryImage.getName()));
} catch (java.beans.PropertyVetoException e) {
lg.error(e.getLocalizedMessage(), e);
}
if (count++ > 5) {
throw new DataAccessException("failed to find unique image name '" + memoryImage.getName() + "' is last name tried");
}
}
KeyValue updatedImageKey = dbServer.getDBTopLevel().insertVersionable(user, memoryImage, memoryImage.getName(), false, true);
VCImage updatedImage = dbServer.getDBTopLevel().getVCImage(dbc, user, updatedImageKey, false);
memoryToDatabaseHash.put(memoryImage, updatedImage);
bSomethingChanged = true;
}
}
}
//
// for the Geometry:
// substitute saved Image into Geometry and
// save Geometry if necessary (only once) and store saved instance in hashtable.
//
{
Geometry memoryGeometry = simulation.getMathDescription().getGeometry();
// defaults to unchanged
memoryToDatabaseHash.put(memoryGeometry, memoryGeometry);
boolean bMustSaveGeometry = false;
VCImage geometryImage = memoryGeometry.getGeometrySpec().getImage();
if (geometryImage != null && memoryToDatabaseHash.get(geometryImage) != geometryImage) {
//
// image had changed and was saved, load saved image into geometry and force a save of this geometry.
//
memoryGeometry.getGeometrySpec().setImage((VCImage) memoryToDatabaseHash.get(geometryImage));
geometryImage = (VCImage) memoryToDatabaseHash.get(geometryImage);
bMustSaveGeometry = true;
}
if (memoryGeometry.getKey() != null && memoryGeometry.getVersion().getName().equals(memoryGeometry.getName())) {
if (!bMustSaveGeometry) {
//
// if geometry had previously been saved, not been forced 'dirty', and name not changed
// compare with original geometry to see if "update" is required.
//
Geometry databaseGeometry = null;
if (origSimulation != null) {
Geometry origGeometry = origSimulation.getMathDescription().getGeometry();
if (origGeometry.getKey().equals(memoryGeometry.getKey())) {
databaseGeometry = origGeometry;
}
}
if (databaseGeometry == null) {
//
// saved geometry not found in origMathModel (too bad), get from database.
//
databaseGeometry = dbServer.getDBTopLevel().getGeometry(dbc, user, memoryGeometry.getKey(), false);
}
if (databaseGeometry != null && !databaseGeometry.compareEqual(memoryGeometry)) {
bMustSaveGeometry = true;
}
}
if (bMustSaveGeometry) {
KeyValue updatedImageKey = (geometryImage != null) ? (geometryImage.getKey()) : (null);
KeyValue updatedGeometryKey = dbServer.getDBTopLevel().updateVersionable(dbc, user, memoryGeometry, updatedImageKey, false, true);
Geometry updatedGeometry = dbServer.getDBTopLevel().getGeometry(dbc, user, updatedGeometryKey, false);
memoryToDatabaseHash.put(memoryGeometry, updatedGeometry);
bSomethingChanged = true;
}
} else {
//
// Geometry hasn't been saved, has been renamed, or has been forced 'dirty'
// insert it with a unique name
//
int count = 0;
while (dbServer.getDBTopLevel().isNameUsed(user, VersionableType.Geometry, memoryGeometry.getName(), true)) {
try {
memoryGeometry.setName(TokenMangler.getNextRandomToken(memoryGeometry.getName()));
} catch (java.beans.PropertyVetoException e) {
lg.error(e.getLocalizedMessage(), e);
}
if (count++ > 5) {
throw new DataAccessException("failed to find unique geometry name '" + memoryGeometry.getName() + "' is last name tried");
}
}
KeyValue updatedImageKey = (geometryImage != null) ? (geometryImage.getKey()) : (null);
KeyValue updatedGeometryKey = dbServer.getDBTopLevel().insertVersionable(dbc, user, memoryGeometry, updatedImageKey, memoryGeometry.getName(), false, true);
Geometry updatedGeometry = dbServer.getDBTopLevel().getGeometry(dbc, user, updatedGeometryKey, false);
memoryToDatabaseHash.put(memoryGeometry, updatedGeometry);
bSomethingChanged = true;
}
}
//
// for the MathDescription:
// substitute saved geometry into MathDescription
// save MathDescription if necessary (only once) and store saved instance in hashtable.
//
MathCompareResults mathCompareResults = null;
{
MathDescription memoryMathDescription = simulation.getMathDescription();
// defaults to unchanged
memoryToDatabaseHash.put(memoryMathDescription, memoryMathDescription);
boolean bMustSaveMathDescription = false;
Geometry scGeometry = memoryMathDescription.getGeometry();
if (scGeometry != null && memoryToDatabaseHash.get(scGeometry) != scGeometry) {
//
// geometry had changed and was saved, load saved geometry into SimulationContext (and it's MathDescription) and force a save of this SimulationContext.
//
memoryMathDescription.setGeometry((Geometry) memoryToDatabaseHash.get(scGeometry));
bMustSaveMathDescription = true;
}
if (memoryMathDescription.getKey() != null && memoryMathDescription.getVersion().getName().equals(memoryMathDescription.getName())) {
if (!bMustSaveMathDescription) {
//
// if MathDescription had previously been saved, not been forced 'dirty', and name not changed
// compare with original MathDescription to see if "update" is required.
//
MathDescription databaseMathDescription = null;
if (origSimulation != null) {
MathDescription origMathDescription = origSimulation.getMathDescription();
if (origMathDescription.getKey().equals(memoryMathDescription.getKey())) {
databaseMathDescription = origMathDescription;
}
}
if (databaseMathDescription == null) {
//
// saved mathDescription not found in origMathModel (too bad), get from database.
//
databaseMathDescription = dbServer.getDBTopLevel().getMathDescription(dbc, user, memoryMathDescription.getKey());
}
if (databaseMathDescription != null) {
mathCompareResults = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), memoryMathDescription, databaseMathDescription);
if (!mathCompareResults.decision.equals(Decision.MathEquivalent_SAME_MATHDESC_AS_IN_DB)) {
bMustSaveMathDescription = true;
}
}
}
if (bMustSaveMathDescription) {
KeyValue updatedGeometryKey = memoryMathDescription.getGeometry().getKey();
KeyValue updatedMathDescriptionKey = dbServer.getDBTopLevel().updateVersionable(user, memoryMathDescription, updatedGeometryKey, false, true);
MathDescription updatedMathDescription = dbServer.getDBTopLevel().getMathDescription(dbc, user, updatedMathDescriptionKey);
memoryToDatabaseHash.put(memoryMathDescription, updatedMathDescription);
bSomethingChanged = true;
}
} else {
//
// MathDescription hasn't been saved, has been renamed, or has been forced 'dirty'
// insert it with a any name (doens't have to be unique ... mathDescription is not a top-level versionable).
//
KeyValue updatedGeometryKey = memoryMathDescription.getGeometry().getKey();
KeyValue updatedMathDescriptionKey = dbServer.getDBTopLevel().insertVersionable(user, memoryMathDescription, updatedGeometryKey, memoryMathDescription.getName(), false, true);
MathDescription updatedMathDescription = dbServer.getDBTopLevel().getMathDescription(dbc, user, updatedMathDescriptionKey);
memoryToDatabaseHash.put(memoryMathDescription, updatedMathDescription);
bSomethingChanged = true;
}
}
//
// for each Simulation in document:
// substitute saved MathDescriptions into Simulation and
// save Simulation if necessary (only once) and store saved instance in hashtable.
//
Simulation memorySimulation = simulation;
//
// didn't evaluate this Simulation yet.
//
// defaults to unchanged
memoryToDatabaseHash.put(memorySimulation, memorySimulation);
boolean bMustSaveSimulation = false;
MathDescription simMathDescription = memorySimulation.getMathDescription();
if (simMathDescription != null && memoryToDatabaseHash.get(simMathDescription) != simMathDescription) {
if (memoryToDatabaseHash.get(simMathDescription) != null) {
// make sure mathDescription hasn't already propagated (newer math won't be in hashtable)
//
// mathDescription had changed and was saved, load saved mathDescription into SimulationContext (and force a save)
//
memorySimulation.setMathDescription((MathDescription) memoryToDatabaseHash.get(simMathDescription));
bMustSaveSimulation = true;
}
}
Simulation databaseSimulation = null;
//
if (memorySimulation.getKey() != null) {
databaseSimulation = origSimulation;
if (databaseSimulation != null && !databaseSimulation.compareEqual(memorySimulation)) {
bMustSaveSimulation = true;
}
if (!memorySimulation.getVersion().getName().equals(memorySimulation.getName())) {
// name was changed.
bMustSaveSimulation = true;
}
} else {
// never been saved.
bMustSaveSimulation = true;
}
if (bMustSaveSimulation) {
KeyValue updatedMathDescriptionKey = memorySimulation.getMathDescription().getKey();
KeyValue updatedSimulationKey = null;
boolean bMathEquivalent = false;
if (origSimulation != null) {
bMathEquivalent = !bForceIndependent && Simulation.testEquivalency(memorySimulation, origSimulation, mathCompareResults);
}
if (memorySimulation.getKey() != null && memorySimulation.getVersion().getName().equals(memorySimulation.getName())) {
// name not changed, update simulation (but pass in database Simulation to check for parent-equivalence)
updatedSimulationKey = dbServer.getDBTopLevel().updateVersionable(user, memorySimulation, updatedMathDescriptionKey, false, bMathEquivalent, true);
} else {
// name changed, insert simulation (but pass in database Simulation to check for parent-equivalence)
updatedSimulationKey = dbServer.getDBTopLevel().insertVersionable(user, memorySimulation, updatedMathDescriptionKey, memorySimulation.getName(), false, bMathEquivalent, true);
}
Simulation updatedSimulation = dbServer.getDBTopLevel().getSimulation(dbc, user, updatedSimulationKey);
memoryToDatabaseHash.put(memorySimulation, updatedSimulation);
bSomethingChanged = true;
simulationXML = XmlHelper.simToXML(updatedSimulation);
return simulationXML;
} else {
return simulationXML;
}
}
Aggregations