use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class PDEDataViewer method sendImageJDomain.
private void sendImageJDomain() {
try {
if (getPdeDataContext().getDataIdentifier().getVariableType().getType() != VariableType.VOLUME.getType()) {
DialogUtils.showErrorDialog(this, "Domain info for " + getPdeDataContext().getDataIdentifier().getVariableType() + " not yet implemented for ImageJ");
return;
}
final ImageJHelper.ListenAndCancel listenAndCancel = new ImageJHelper.ListenAndCancel();
AsynchClientTask sendDataTask = new AsynchClientTask("Sending domain Data...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
ImageJHelper.sendVolumeDomain(PDEDataViewer.this, getPdeDataContext(), getPdeDataContext().getCartesianMesh().getISize(), getClientTaskStatusSupport(), listenAndCancel, "Volume domains '" + getSimulationModelInfo().getContextName() + "':'" + getSimulation().getName() + "'", getSimulationModelInfo());
}
};
ClientTaskDispatcher.dispatch(PDEDataViewer.this, new Hashtable<>(), new AsynchClientTask[] { sendDataTask }, true, false, true, listenAndCancel, false);
} catch (Exception e) {
handleException(e);
}
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class ClientRequestManager method changeGeometry0.
private void changeGeometry0(final TopLevelWindowManager requester, final SimulationContext simContext) {
AsynchClientTask selectDocumentTypeTask = createSelectDocTask(requester);
AsynchClientTask selectLoadGeomTask = createSelectLoadGeomTask(requester);
AsynchClientTask processGeometryTask = new AsynchClientTask("Processing geometry...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry newGeometry = (Geometry) hashTable.get(GEOMETRY_KEY);
if (requester instanceof MathModelWindowManager) {
// User can cancel here
continueAfterMathModelGeomChangeWarning((MathModelWindowManager) requester, newGeometry);
}
if (newGeometry.getDimension() > 0 && newGeometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
newGeometry.getGeometrySurfaceDescription().updateAll();
}
}
};
AsynchClientTask setNewGeometryTask = new AsynchClientTask("Setting new Geometry...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry newGeometry = (Geometry) hashTable.get(GEOMETRY_KEY);
if (newGeometry != null) {
if (requester instanceof BioModelWindowManager) {
simContext.setGeometry(newGeometry);
} else if (requester instanceof MathModelWindowManager) {
MathModel mathModel = (MathModel) ((MathModelWindowManager) requester).getVCDocument();
mathModel.getMathDescription().setGeometry(newGeometry);
}
}
}
};
Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
ClientTaskDispatcher.dispatch(requester.getComponent(), hashTable, new AsynchClientTask[] { selectDocumentTypeTask, selectLoadGeomTask, processGeometryTask, setNewGeometryTask }, false);
}
use of cbit.vcell.client.task.AsynchClientTask 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.AsynchClientTask in project vcell by virtualcell.
the class DatabaseWindowManager method accessPermissions.
/**
* Insert the method's description here.
* Creation date: (5/14/2004 5:35:55 PM)
*/
public void accessPermissions(final Component requester, final VersionInfo selectedVersionInfo) {
final GroupAccess groupAccess = selectedVersionInfo.getVersion().getGroupAccess();
final DocumentManager docManager = getRequestManager().getDocumentManager();
AsynchClientTask task1 = new AsynchClientTask("show dialog", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
getAclEditor().clearACLList();
getAclEditor().setACLState(new ACLEditor.ACLState(groupAccess));
Object choice = showAccessPermissionDialog(getAclEditor(), requester);
if (choice != null) {
hashTable.put("choice", choice);
}
}
};
AsynchClientTask task2 = new AsynchClientTask("access permission", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Object choice = hashTable.get("choice");
if (choice != null && choice.equals("OK")) {
ACLEditor.ACLState aclState = getAclEditor().getACLState();
if (aclState != null) {
if (aclState.isAccessPrivate() || (aclState.getAccessList() != null && aclState.getAccessList().length == 0)) {
VersionInfo vInfo = null;
if (selectedVersionInfo instanceof BioModelInfo) {
vInfo = docManager.setGroupPrivate((BioModelInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof MathModelInfo) {
vInfo = docManager.setGroupPrivate((MathModelInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof GeometryInfo) {
vInfo = docManager.setGroupPrivate((GeometryInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof VCImageInfo) {
vInfo = docManager.setGroupPrivate((VCImageInfo) selectedVersionInfo);
}
} else if (aclState.isAccessPublic()) {
VersionInfo vInfo = null;
if (selectedVersionInfo instanceof BioModelInfo) {
vInfo = docManager.setGroupPublic((BioModelInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof MathModelInfo) {
vInfo = docManager.setGroupPublic((MathModelInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof GeometryInfo) {
vInfo = docManager.setGroupPublic((GeometryInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof VCImageInfo) {
vInfo = docManager.setGroupPublic((VCImageInfo) selectedVersionInfo);
}
} else {
String[] aclUserNames = aclState.getAccessList();
String[] originalGroupAccesNames = new String[0];
// Turn User[] into String[]
if (groupAccess instanceof GroupAccessSome) {
GroupAccessSome gas = (GroupAccessSome) groupAccess;
User[] originalUsers = gas.getNormalGroupMembers();
for (int i = 0; i < originalUsers.length; i += 1) {
originalGroupAccesNames = (String[]) BeanUtils.addElement(originalGroupAccesNames, originalUsers[i].getName());
}
}
// Determine users needing adding
String[] needToAddUsers = new String[0];
for (int i = 0; i < aclUserNames.length; i += 1) {
if (!BeanUtils.arrayContains(originalGroupAccesNames, aclUserNames[i])) {
System.out.println("Added user=" + aclUserNames[i]);
needToAddUsers = (String[]) BeanUtils.addElement(needToAddUsers, aclUserNames[i]);
}
}
// Determine users needing removing
String[] needToRemoveUsers = new String[0];
for (int i = 0; i < originalGroupAccesNames.length; i += 1) {
if (!BeanUtils.arrayContains(aclUserNames, originalGroupAccesNames[i])) {
System.out.println("Removed user=" + originalGroupAccesNames[i]);
needToRemoveUsers = (String[]) BeanUtils.addElement(needToRemoveUsers, originalGroupAccesNames[i]);
}
}
VersionInfo vInfo = null;
String errorNames = "";
// Add Users to Group Access List
for (int i = 0; i < needToAddUsers.length; i++) {
try {
if (selectedVersionInfo instanceof BioModelInfo) {
vInfo = docManager.addUserToGroup((BioModelInfo) selectedVersionInfo, needToAddUsers[i]);
} else if (selectedVersionInfo instanceof MathModelInfo) {
vInfo = docManager.addUserToGroup((MathModelInfo) selectedVersionInfo, needToAddUsers[i]);
} else if (selectedVersionInfo instanceof GeometryInfo) {
vInfo = docManager.addUserToGroup((GeometryInfo) selectedVersionInfo, needToAddUsers[i]);
} else if (selectedVersionInfo instanceof VCImageInfo) {
vInfo = docManager.addUserToGroup((VCImageInfo) selectedVersionInfo, needToAddUsers[i]);
}
} catch (ObjectNotFoundException e) {
errorNames += "Error changing permissions.\n" + selectedVersionInfo.getVersionType().getTypeName() + " \"" + selectedVersionInfo.getVersion().getName() + "\" edition (" + selectedVersionInfo.getVersion().getDate() + ")\nnot found, " + "your model list may be out of date, please go to menu Server->Reconnect to refresh the model list" + "\n";
break;
} catch (DataAccessException e) {
errorNames += "Error adding user '" + needToAddUsers[i] + "' : " + e.getMessage() + "\n";
}
}
// Remove users from Group Access List
for (int i = 0; i < needToRemoveUsers.length; i++) {
try {
if (selectedVersionInfo instanceof BioModelInfo) {
vInfo = docManager.removeUserFromGroup((BioModelInfo) selectedVersionInfo, needToRemoveUsers[i]);
} else if (selectedVersionInfo instanceof MathModelInfo) {
vInfo = docManager.removeUserFromGroup((MathModelInfo) selectedVersionInfo, needToRemoveUsers[i]);
} else if (selectedVersionInfo instanceof GeometryInfo) {
vInfo = docManager.removeUserFromGroup((GeometryInfo) selectedVersionInfo, needToRemoveUsers[i]);
} else if (selectedVersionInfo instanceof VCImageInfo) {
vInfo = docManager.removeUserFromGroup((VCImageInfo) selectedVersionInfo, needToRemoveUsers[i]);
}
} catch (DataAccessException e) {
errorNames += "Error Removing user '" + needToRemoveUsers[i] + "'\n -----" + e.getMessage() + "\n";
}
}
if (errorNames.length() > 0) {
if (DatabaseWindowManager.this.getComponent() != null) {
PopupGenerator.showErrorDialog(DatabaseWindowManager.this, errorNames);
} else {
DialogUtils.showErrorDialog(requester, errorNames);
}
accessPermissions(requester, selectedVersionInfo);
}
}
}
}
}
};
ClientTaskDispatcher.dispatch(requester, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class DBReactionWizardPanel method applySelectedReactionElements.
/**
* Comment
*/
private void applySelectedReactionElements() {
AsynchClientTask getRXSourceModelTask = new AsynchClientTask("Get RX source model", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// Get the complete original model the user selected reaction is from
Model fromModel = getDocumentManager().getBioModel(resolvedReaction.getVCellBioModelID()).getModel();
// find the user selected ReactionStep in the original model
ReactionStep fromRXStep = null;
ReactionStep[] rxArr = fromModel.getReactionSteps();
for (int i = 0; i < rxArr.length; i++) {
if (rxArr[i].getKey().equals(resolvedReaction.getVCellRXID())) {
fromRXStep = rxArr[i];
break;
}
}
// Create user assignment preferences
BioCartoonTool.UserResolvedRxElements userResolvedRxElements = new BioCartoonTool.UserResolvedRxElements();
userResolvedRxElements.fromSpeciesContextArr = new SpeciesContext[resolvedReaction.elementCount()];
userResolvedRxElements.toSpeciesArr = new Species[resolvedReaction.elementCount()];
userResolvedRxElements.toStructureArr = new Structure[resolvedReaction.elementCount()];
StringBuffer warningsSB = new StringBuffer();
for (int i = 0; i < resolvedReaction.elementCount(); i++) {
System.out.println(resolvedReaction.getOrigSpeciesContextName(i));
userResolvedRxElements.fromSpeciesContextArr[i] = fromModel.getSpeciesContext(resolvedReaction.getOrigSpeciesContextName(i));
userResolvedRxElements.toSpeciesArr[i] = (speciesAssignmentJCB[i].getSelectedItem() instanceof Species ? (Species) speciesAssignmentJCB[i].getSelectedItem() : null);
userResolvedRxElements.toStructureArr[i] = (Structure) structureAssignmentJCB[i].getSelectedItem();
if (userResolvedRxElements.toSpeciesArr[i] != null) {
SpeciesContext fromSpeciesContext = userResolvedRxElements.fromSpeciesContextArr[i];
Species toSpecies = userResolvedRxElements.toSpeciesArr[i];
if (fromSpeciesContext.getSpecies().getDBSpecies() != null && !Compare.isEqualOrNull(toSpecies.getDBSpecies(), fromSpeciesContext.getSpecies().getDBSpecies())) {
warningsSB.append((warningsSB.length() > 0 ? "\n" : "") + "'" + fromSpeciesContext.getSpecies().getCommonName() + "' formal(" + (fromSpeciesContext.getSpecies().getDBSpecies() != null ? fromSpeciesContext.getSpecies().getDBSpecies().getPreferredName() : "null") + ")" + "\nwill be re-assigned to\n" + "'" + toSpecies.getCommonName() + "' formal(" + (toSpecies.getDBSpecies() != null ? toSpecies.getDBSpecies().getPreferredName() : "null") + ")");
}
}
}
if (warningsSB.length() > 0) {
final String proceed = "Add reaction anyway";
final String cancel = "Cancel";
String result = DialogUtils.showWarningDialog(DBReactionWizardPanel.this, "A user choice selected under 'Assign to Model species' will force re-assignment of " + "the formal reference for one of the species in the reaction.\n" + warningsSB, new String[] { proceed, cancel }, cancel);
if (result.equals(cancel)) {
throw UserCancelException.CANCEL_GENERIC;
}
}
hashTable.put("fromRXStep", fromRXStep);
hashTable.put("userResolvedRxElements", userResolvedRxElements);
}
};
AsynchClientTask pasteReactionTask = new AsynchClientTask("Paste reaction", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// TODO Auto-generated method stub
Model pasteToModel = DBReactionWizardPanel.this.getModel();
Structure pasteToStructure = DBReactionWizardPanel.this.getStructure();
BioCartoonTool.pasteReactionSteps(DBReactionWizardPanel.this, new ReactionStep[] { (ReactionStep) hashTable.get("fromRXStep") }, pasteToModel, pasteToStructure, false, (UserResolvedRxElements) hashTable.get("userResolvedRxElements"), rxPasteInterface);
closeParent();
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { getRXSourceModelTask, pasteReactionTask }, false, false, null, true);
}
Aggregations