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 BioModelEditorPathwayCommonsPanel method search.
public void search() {
String text = searchTextField.getText();
if (text == null || text.length() == 0) {
return;
}
text = text.trim();
if (text.length() == 0) {
return;
}
final String searchText = text;
searchTextList.add(searchText);
searchTextField.setAutoCompletionWords(searchTextList);
AsynchClientTask task1 = new AsynchClientTask("searching", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
URL url = new URL(defaultBaseURL + "?" + PathwayCommonsKeyword.cmd + "=" + PathwayCommonsKeyword.search + "&" + PathwayCommonsKeyword.version + "=" + PathwayCommonsVersion.v2.name + "&" + PathwayCommonsKeyword.q + "=" + URLEncoder.encode(searchText, "UTF-8") + "&" + PathwayCommonsKeyword.maxHits + "=" + 14 + "&" + PathwayCommonsKeyword.output + "=" + PathwayCommonsKeyword.xml);
System.out.println(url);
String responseContent = BeanUtils.downloadBytes(url, getClientTaskStatusSupport());
Document document = DOMUtil.parse(responseContent);
Element errorElement = DOMUtil.firstChildElement(document, "error");
if (errorElement != null) {
// String xml = DOMUtil.firstChildContent(document, "error");
throw new RuntimeException(errorElement.getTextContent());
}
Element searchResponse = DOMUtil.firstChildElement(document, "search_response");
if (searchResponse != null) {
// String xml = DOMUtil.firstChildContent(document, "search_response");
// System.out.println(xml);
hashTable.put("searchResponse", searchResponse);
}
}
};
AsynchClientTask task2 = new AsynchClientTask("showing", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Element searchResponse = (Element) hashTable.get("searchResponse");
if (searchResponse != null) {
responseTreeModel.addSearchResponse(searchText, searchResponse);
}
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false, true, null);
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class BioModelEditorSabioPanel method treeSelectionChanged.
public void treeSelectionChanged() {
System.out.println("treeSelectionChanged");
final SBEntity kineticLaw = computeSelectedKineticLaw();
if (kineticLaw == null) {
return;
}
String kineticLawID = kineticLaw.getID();
final String kls = new String("kineticLaw");
if (!kineticLawID.contains(kls)) {
return;
}
kineticLawID = kineticLawID.substring(kineticLawID.lastIndexOf(kls) + kls.length());
command = "EntryID:" + kineticLawID;
AsynchClientTask task1 = new AsynchClientTask("Importing Kinetic Laws", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(final Hashtable<String, Object> hashTable) throws Exception {
final URL url = new URL("http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/biopax?q=" + command);
// final URL url = new URL("http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/biopax?q=EntryID:33107");
System.out.println(url.toString());
String ERROR_CODE_TAG = "error_code";
Document jdomDocument = XmlUtil.getJDOMDocument(url, getClientTaskStatusSupport());
Element rootElement = jdomDocument.getRootElement();
String errorCode = rootElement.getChildText(ERROR_CODE_TAG);
if (errorCode != null) {
throw new RuntimeException("Failed to access " + url + " \n\nPlease try again.");
}
PathwayModel pathwayModel = PathwayIOUtil.extractPathwayFromJDOM(jdomDocument, new RDFXMLContext(), getClientTaskStatusSupport());
PathwayData pathwayData = new PathwayData("Sabio Kinetic Laws", pathwayModel);
hashTable.put("pathwayData", pathwayData);
}
};
AsynchClientTask task2 = new AsynchClientTask("showing", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
PathwayData pathwayData = (PathwayData) hashTable.get("pathwayData");
if (pathwayData != null) {
setSelectedObjects(new Object[] { pathwayData });
}
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, true, true, null);
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class BioModelEditorSabioPanel method populateKineticLawsTree.
public void populateKineticLawsTree() {
// String category1 = (String)categoryList1.getSelectedItem();
String category1 = "AnyRole";
String category2 = (String) categoryList2.getSelectedItem();
String entity1 = entityName1.getText();
String entity2 = entityName2.getText();
// http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/biopax?q=%28Pathway:JAK-STAT%20AND%20CellularLocation:cytosol%29
command = "";
if (entity1.isEmpty() && entity2.isEmpty()) {
DialogUtils.showWarningDialog(this, "No search criteria specified.");
return;
}
if (!entity1.isEmpty() && entity2.isEmpty()) {
command += category1 + ":" + entity1;
} else if (entity1.isEmpty() && !entity2.isEmpty()) {
command += category2 + ":" + entity2;
} else {
// both entities present
command += "%28" + category1 + ":" + entity1 + "%20AND%20" + category2 + ":" + entity2 + "%29";
}
AsynchClientTask task1 = new AsynchClientTask("Importing Kinetic Laws", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(final Hashtable<String, Object> hashTable) throws Exception {
final URL url = new URL("http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/biopax?q=" + command);
System.out.println(url.toString());
String ERROR_CODE_TAG = "error_code";
Document jdomDocument = XmlUtil.getJDOMDocument(url, getClientTaskStatusSupport());
Element rootElement = jdomDocument.getRootElement();
String errorCode = rootElement.getChildText(ERROR_CODE_TAG);
if (errorCode != null) {
throw new RuntimeException("Failed to access " + url + " \n\nPlease try again.");
}
PathwayModel pathwayModel = PathwayIOUtil.extractPathwayFromJDOM(jdomDocument, new RDFXMLContext(), getClientTaskStatusSupport());
PathwayData pathwayData = new PathwayData("Sabio Kinetic Laws", pathwayModel);
hashTable.put("pathwayData", pathwayData);
}
};
AsynchClientTask task2 = new AsynchClientTask("showing", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
PathwayData pathwayData = (PathwayData) hashTable.get("pathwayData");
if (pathwayData != null) {
responseTreeModel.addSearchResponse("text", pathwayData);
}
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, true, true, null);
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class BioPaxObjectPropertiesPanel method lookupFormalName.
private void lookupFormalName(final int tableRow) {
final String FORMAL_NAMES_KEY = "FORMAL_NAMES_KEY";
final Entity entity = (Entity) BioPaxObjectPropertiesPanel.this.bioPaxObject;
AsynchClientTask initLookupTask = new AsynchClientTask("init lookup...", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (!lookupContains(entity)) {
lookupAdd(entity);
}
refreshInterface();
}
};
AsynchClientTask lookupTask = new AsynchClientTask("looking...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING, false) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
ArrayList<Xref> xrefArrList = entity.getxRef();
ArrayList<String> formalNames = AnnotationMapping.getNameRef(xrefArrList, null);
if (formalNames != null && formalNames.size() > 0) {
hashTable.put(FORMAL_NAMES_KEY, formalNames);
}
}
};
AsynchClientTask finishLookupTask = new AsynchClientTask("init lookup...", AsynchClientTask.TASKTYPE_SWING_NONBLOCKING, false) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
try {
ArrayList<String> formalNames = (ArrayList<String>) hashTable.get(FORMAL_NAMES_KEY);
if (formalNames != null) {
entity.setFormalNames(formalNames);
} else if (entity.getxRef() != null && entity.getxRef().size() > 0) {
String str = "";
for (int i = 0; i < ((Entity) BioPaxObjectPropertiesPanel.this.bioPaxObject).getxRef().size(); i++) {
str += (i > 0 ? "\n" : "") + entity.getxRef().get(i).getDb() + ":" + entity.getxRef().get(i).getId();
}
throw new Exception("Formal name lookup not yet implemented using:\n" + str);
} else {
throw new Exception("No cross-references available to lookup formal name for " + entity.getName().get(0));
}
} finally {
lookupRemove(entity);
refreshInterface();
table.setRowSelectionInterval(tableRow, tableRow);
}
}
};
ClientTaskDispatcher.dispatch(null, new Hashtable<String, Object>(), new AsynchClientTask[] { initLookupTask, lookupTask, finishLookupTask }, null, false, false, false, null, false);
}
Aggregations