use of cbit.vcell.client.task.CheckBeforeDelete in project vcell by virtualcell.
the class ClientRequestManager method runSimulations.
public void runSimulations(final ClientSimManager clientSimManager, final Simulation[] simulations) {
DocumentWindowManager documentWindowManager = clientSimManager.getDocumentWindowManager();
/* run some quick checks to see if we need to do a SaveAs */
boolean needSaveAs = false;
if (documentWindowManager.getVCDocument().getVersion() == null) {
// never saved
needSaveAs = true;
} else if (!documentWindowManager.getVCDocument().getVersion().getOwner().compareEqual(getDocumentManager().getUser())) {
// not the owner
// keep the user informed this time
String choice = PopupGenerator.showWarningDialog(documentWindowManager, getUserPreferences(), UserMessage.warn_SaveNotOwner, null);
if (choice.equals(UserMessage.OPTION_SAVE_AS_NEW)) {
needSaveAs = true;
} else {
// user canceled, just show existing document
getMdiManager().showWindow(documentWindowManager.getManagerID());
throw new UserCancelException("user canceled");
}
}
// Before running the simulation, check if all the sizes of structures are set
if (simulations != null && simulations.length > 0) {
VCDocument vcd = documentWindowManager.getVCDocument();
if (vcd instanceof BioModel) {
String stochChkMsg = null;
// we want to check when there is stochastic application if the rate laws set in model can be automatically transformed.
for (int i = 0; i < simulations.length; i++) {
if (simulations[i].getMathDescription().isNonSpatialStoch() || simulations[i].getMathDescription().isSpatialStoch() || simulations[i].getMathDescription().isSpatialHybrid()) {
if (stochChkMsg == null) {
stochChkMsg = ((BioModel) vcd).getModel().isValidForStochApp();
}
if (!(stochChkMsg.equals(""))) {
DialogUtils.showErrorDialog(documentWindowManager.getComponent(), "Problem in simulation: " + simulations[i].getName() + ".\n" + stochChkMsg);
throw new RuntimeException("Problem in simulation: " + simulations[i].getName() + "\n" + stochChkMsg);
}
}
}
}
}
//
for (int i = 0; simulations != null && i < simulations.length; i++) {
if (simulations[i].getSimulationVersion() != null && simulations[i].getSimulationVersion().getParentSimulationReference() != null) {
simulations[i].clearVersion();
}
}
/* now start the dirty work */
/* block document window */
JFrame currentDocumentWindow = getMdiManager().blockWindow(documentWindowManager.getManagerID());
/* prepare hashtable for tasks */
Hashtable<String, Object> hash = new Hashtable<String, Object>();
hash.put("mdiManager", getMdiManager());
hash.put(DocumentManager.IDENT, getDocumentManager());
hash.put(CommonTask.DOCUMENT_WINDOW_MANAGER.name, documentWindowManager);
hash.put("currentDocumentWindow", currentDocumentWindow);
hash.put("clientSimManager", clientSimManager);
hash.put("simulations", simulations);
hash.put("jobManager", getClientServerManager().getJobManager());
hash.put("requestManager", this);
/* create tasks */
AsynchClientTask[] tasks = null;
if (needSaveAs) {
// check document consistency first
AsynchClientTask documentValid = new DocumentValidTask();
AsynchClientTask setMathDescription = new SetMathDescription();
// get a new name
AsynchClientTask newName = new NewName();
// save it
AsynchClientTask saveDocument = new SaveDocument();
// clean up
AsynchClientTask finishSave = new FinishSave();
// run the simulations
AsynchClientTask runSims = new RunSims();
// assemble array
tasks = new AsynchClientTask[] { documentValid, setMathDescription, newName, saveDocument, finishSave, runSims };
} else {
// check document consistency first
AsynchClientTask documentValid = new DocumentValidTask();
AsynchClientTask setMathDescription = new SetMathDescription();
// check if unchanged document
AsynchClientTask checkUnchanged = new CheckUnchanged(true);
// save it
AsynchClientTask saveDocument = new SaveDocument();
// check for lost results
AsynchClientTask checkBeforeDelete = new CheckBeforeDelete();
// delete old document
AsynchClientTask deleteOldDocument = new DeleteOldDocument();
// clean up
AsynchClientTask finishSave = new FinishSave();
// run the simulations
AsynchClientTask runSims = new RunSims();
// assemble array
tasks = new AsynchClientTask[] { documentValid, setMathDescription, checkUnchanged, saveDocument, checkBeforeDelete, deleteOldDocument, finishSave, runSims };
}
/* run the tasks */
ClientTaskDispatcher.dispatch(currentDocumentWindow, hash, tasks, true);
}
use of cbit.vcell.client.task.CheckBeforeDelete in project vcell by virtualcell.
the class ClientRequestManager method saveDocument.
/**
* Insert the method's description here.
* Creation date: (5/27/2004 3:09:25 PM)
* @param vcDocument cbit.vcell.document.VCDocument
* @param replace boolean
*/
public void saveDocument(final DocumentWindowManager documentWindowManager, boolean replace, AsynchClientTask closeWindowTask) {
/* run some quick checks first to validate request to save or save edition */
if (documentWindowManager.getVCDocument().getVersion() == null) {
// it can never see this happening before, but check anyway and default to save as
// but since we can allow user to save during closing, now it can happen
// (save/save edition buttons should have not been enabled upon document window creation)
System.out.println("\nIGNORED ERROR: should not have been able to use save/save edition on doc with no version key\n");
saveDocumentAsNew(documentWindowManager, closeWindowTask);
return;
}
if (!documentWindowManager.getVCDocument().getVersion().getOwner().compareEqual(getDocumentManager().getUser())) {
// not the owner - this should also not happen, but check anyway...
// keep the user informed this time
System.out.println("\nIGNORED ERROR: should not have been able to use save/save edition on doc with different owner\n");
String choice = PopupGenerator.showWarningDialog(documentWindowManager, getUserPreferences(), UserMessage.warn_SaveNotOwner, null);
if (choice.equals(UserMessage.OPTION_SAVE_AS_NEW)) {
// user chose to Save As
saveDocumentAsNew(documentWindowManager, closeWindowTask);
return;
} else {
if (closeWindowTask == null) {
// user canceled, just show existing document
getMdiManager().showWindow(documentWindowManager.getManagerID());
return;
} else {
ClientTaskDispatcher.dispatch(documentWindowManager.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { closeWindowTask }, false);
}
}
}
/* request is valid, go ahead with save */
/* block document window */
JFrame currentDocumentWindow = getMdiManager().blockWindow(documentWindowManager.getManagerID());
/* prepare hashtable for tasks */
Hashtable<String, Object> hash = new Hashtable<String, Object>();
hash.put("mdiManager", getMdiManager());
hash.put(DocumentManager.IDENT, getDocumentManager());
hash.put(CommonTask.DOCUMENT_WINDOW_MANAGER.name, documentWindowManager);
hash.put("currentDocumentWindow", currentDocumentWindow);
hash.put("requestManager", this);
/* create tasks */
// check document consistency first
AsynchClientTask documentValid = new DocumentValidTask();
AsynchClientTask setMathDescription = new SetMathDescription();
// check if unchanged document
AsynchClientTask checkUnchanged = new CheckUnchanged(false);
// save it
AsynchClientTask saveDocument = new SaveDocument();
// clean up
AsynchClientTask finishSave = new FinishSave();
// assemble array
AsynchClientTask[] tasks = null;
if (replace) {
// check for lost results
AsynchClientTask checkBeforeDelete = new CheckBeforeDelete();
// delete old document
AsynchClientTask deleteOldDocument = new DeleteOldDocument();
tasks = new AsynchClientTask[] { documentValid, setMathDescription, checkUnchanged, saveDocument, checkBeforeDelete, deleteOldDocument, finishSave };
} else {
tasks = new AsynchClientTask[] { documentValid, setMathDescription, checkUnchanged, saveDocument, finishSave };
}
if (closeWindowTask != null) {
// replace finishSave
tasks[tasks.length - 1] = closeWindowTask;
}
/* run tasks */
ClientTaskDispatcher.dispatch(currentDocumentWindow, hash, tasks, false);
}
Aggregations