Search in sources :

Example 21 with AsynchClientTask

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);
}
Also used : DocumentValidTask(cbit.vcell.client.task.DocumentValidTask) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCDocument(org.vcell.util.document.VCDocument) FinishSave(cbit.vcell.client.task.FinishSave) DeleteOldDocument(cbit.vcell.client.task.DeleteOldDocument) Hashtable(java.util.Hashtable) UserCancelException(org.vcell.util.UserCancelException) SetMathDescription(cbit.vcell.client.task.SetMathDescription) SaveDocument(cbit.vcell.client.task.SaveDocument) JFrame(javax.swing.JFrame) CheckUnchanged(cbit.vcell.client.task.CheckUnchanged) BioModel(cbit.vcell.biomodel.BioModel) CSGObject(cbit.vcell.geometry.CSGObject) NewName(cbit.vcell.client.task.NewName) RunSims(cbit.vcell.client.task.RunSims) CheckBeforeDelete(cbit.vcell.client.task.CheckBeforeDelete)

Example 22 with AsynchClientTask

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);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) URL(java.net.URL)

Example 23 with AsynchClientTask

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);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) RDFXMLContext(org.vcell.pathway.persistence.RDFXMLContext) Hashtable(java.util.Hashtable) Element(org.jdom.Element) PathwayData(cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayData) Document(org.jdom.Document) PathwayModel(org.vcell.pathway.PathwayModel) SBEntity(org.vcell.pathway.sbpax.SBEntity) URL(java.net.URL) PathwayStringObject(cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayStringObject)

Example 24 with AsynchClientTask

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);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) RDFXMLContext(org.vcell.pathway.persistence.RDFXMLContext) Hashtable(java.util.Hashtable) Element(org.jdom.Element) PathwayData(cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayData) PathwayStringObject(cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayStringObject) Document(org.jdom.Document) PathwayModel(org.vcell.pathway.PathwayModel) URL(java.net.URL)

Example 25 with AsynchClientTask

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);
}
Also used : SBEntity(org.vcell.pathway.sbpax.SBEntity) PhysicalEntity(org.vcell.pathway.PhysicalEntity) Entity(org.vcell.pathway.Entity) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Xref(org.vcell.pathway.Xref) UnificationXref(org.vcell.pathway.UnificationXref) RelationshipXref(org.vcell.pathway.RelationshipXref) PublicationXref(org.vcell.pathway.PublicationXref) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) GroupObject(org.vcell.pathway.GroupObject) BioPaxObject(org.vcell.pathway.BioPaxObject) RelationshipObject(org.vcell.relationship.RelationshipObject) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject)

Aggregations

AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)229 Hashtable (java.util.Hashtable)219 ArrayList (java.util.ArrayList)68 UserCancelException (org.vcell.util.UserCancelException)52 File (java.io.File)35 CSGObject (cbit.vcell.geometry.CSGObject)30 Point (java.awt.Point)23 DataAccessException (org.vcell.util.DataAccessException)22 SimulationContext (cbit.vcell.mapping.SimulationContext)21 FRAPStudy (cbit.vcell.microscopy.FRAPStudy)18 PropertyVetoException (java.beans.PropertyVetoException)18 ImageException (cbit.image.ImageException)17 IOException (java.io.IOException)17 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)14 Vector (java.util.Vector)14 DataFormatException (java.util.zip.DataFormatException)14 UtilCancelException (org.vcell.util.UtilCancelException)14 Geometry (cbit.vcell.geometry.Geometry)12 ActionEvent (java.awt.event.ActionEvent)12 BioModel (cbit.vcell.biomodel.BioModel)11