Search in sources :

Example 66 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class LoadFRAPData_MultiFileDescriptor method preNextProcess.

// load the data before the panel disappears
public ArrayList<AsynchClientTask> preNextProcess() {
    // create AsynchClientTask arraylist
    ArrayList<AsynchClientTask> taskArrayList = new ArrayList<AsynchClientTask>();
    final File[] files = multiFilePanel.getSelectedFiles();
    if (files.length > 0) {
        final String filePath = files[0].getParent();
        final String LOADING_MESSAGE = "Loading files from directory " + filePath + "...";
        AsynchClientTask updateUIBeforeLoadTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                try {
                    VirtualFrapMainFrame.updateStatus(LOADING_MESSAGE);
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                }
            }
        };
        AsynchClientTask loadTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy newFRAPStudy = null;
                newFRAPStudy = FRAPWorkspace.loadFRAPDataFromMultipleFiles(files, this.getClientTaskStatusSupport(), multiFilePanel.isTimeSeries(), multiFilePanel.getTimeInterval());
                isFileLoaded = true;
                // for all loaded files
                hashTable.put(FRAPStudyPanel.NEW_FRAPSTUDY_KEY, newFRAPStudy);
            }
        };
        AsynchClientTask afterLoadingSwingTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy newFRAPStudy = (FRAPStudy) hashTable.get(FRAPStudyPanel.NEW_FRAPSTUDY_KEY);
                // setFrapStudy fires property change, so we have to put it in Swing thread.
                getFrapWorkspace().setFrapStudy(newFRAPStudy, true);
                VirtualFrapLoader.mf.setMainFrameTitle("");
                VirtualFrapMainFrame.updateProgress(0);
                if (isFileLoaded) {
                    VirtualFrapMainFrame.updateStatus("Loaded files from " + filePath);
                } else {
                    VirtualFrapMainFrame.updateStatus("Failed loading files from " + filePath + ".");
                }
            }
        };
        taskArrayList.add(updateUIBeforeLoadTask);
        taskArrayList.add(loadTask);
        taskArrayList.add(afterLoadingSwingTask);
    } else {
        DialogUtils.showErrorDialog(multiFilePanel, "No file is selected. Please input one or more file names to continue.");
        throw new RuntimeException("No file is selected. Please input one or more file names to continue.");
    }
    return taskArrayList;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) File(java.io.File)

Example 67 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class LoadFRAPData_PostProcessingDataDescriptor method preNextProcess.

public ArrayList<AsynchClientTask> preNextProcess() {
    final String LOADING_MESSAGE = "Loading variable data " + postProcessingDataPanel.getSelectedVariableName() + "...";
    AsynchClientTask updateUIBeforeLoadTask = new AsynchClientTask("Updating status message...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (postProcessingDataPanel.getSelectedVariableName() == null || postProcessingDataPanel.getSelectedDataManager() == null) {
                throw new RuntimeException("Post Processing Data variable not selected");
            }
            VirtualFrapMainFrame.updateStatus(LOADING_MESSAGE);
        }
    };
    AsynchClientTask loadTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            String selectedVariableName = postProcessingDataPanel.getSelectedVariableName();
            int selectedSlice = postProcessingDataPanel.getSelectedSlice();
            DataProcessingOutputInfo dataProcessingOutputInfo = postProcessingDataPanel.getSelectedDataProcessingOutputInfo();
            PDEDataManager pdeDataManager = postProcessingDataPanel.getSelectedDataManager();
            DataOperationResults.DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataOperationResults.DataProcessingOutputDataValues) pdeDataManager.doDataOperation(new DataOperation.DataProcessingOutputDataValuesOP(pdeDataManager.getVCDataIdentifier(), selectedVariableName, TimePointHelper.createAllTimeTimePointHelper(), DataIndexHelper.createSliceDataIndexHelper(selectedSlice), null, null));
            ArrayList<SourceDataInfo> sdiArr = dataProcessingOutputDataValues.createSourceDataInfos(dataProcessingOutputInfo.getVariableISize(selectedVariableName), dataProcessingOutputInfo.getVariableOrigin(selectedVariableName), dataProcessingOutputInfo.getVariableExtent(selectedVariableName));
            FRAPStudy newFRAPStudy = FRAPWorkspace.loadFRAPDataFromDataProcessingOutput(sdiArr, dataProcessingOutputInfo.getVariableTimePoints(), 0, /*data already sliced*/
            65535.0, this.getClientTaskStatusSupport());
            isFileLoaded = true;
            hashTable.put(FRAPStudyPanel.NEW_FRAPSTUDY_KEY, newFRAPStudy);
        }
    };
    AsynchClientTask afterLoadingSwingTask = new AsynchClientTask("Setting FrapWorkspace FrapStudy...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FRAPStudy newFRAPStudy = (FRAPStudy) hashTable.get(FRAPStudyPanel.NEW_FRAPSTUDY_KEY);
            // setFrapStudy fires property change, so we have to put it in Swing thread.
            getFrapWorkspace().setFrapStudy(newFRAPStudy, true);
            VirtualFrapLoader.mf.setMainFrameTitle("");
            VirtualFrapMainFrame.updateProgress(0);
            if (isFileLoaded) {
                VirtualFrapMainFrame.updateStatus("Loaded " + postProcessingDataPanel.getSelectedVariableName());
            } else {
                VirtualFrapMainFrame.updateStatus("Failed loading " + postProcessingDataPanel.getSelectedVariableName() + ".");
            }
        }
    };
    ArrayList<AsynchClientTask> tasks = new ArrayList<AsynchClientTask>();
    tasks.add(updateUIBeforeLoadTask);
    tasks.add(loadTask);
    tasks.add(afterLoadingSwingTask);
    return tasks;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) SourceDataInfo(cbit.image.SourceDataInfo) PDEDataManager(cbit.vcell.simdata.PDEDataManager) DataProcessingOutputInfo(cbit.vcell.simdata.DataOperationResults.DataProcessingOutputInfo) DataOperationResults(cbit.vcell.simdata.DataOperationResults) FRAPStudy(cbit.vcell.microscopy.FRAPStudy)

Example 68 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class LoadFRAPData_SingleFileDescriptor method preNextProcess.

// load the data before the panel disappears
public ArrayList<AsynchClientTask> preNextProcess() {
    // create AsynchClientTask arraylist
    ArrayList<AsynchClientTask> taskArrayList = new ArrayList<AsynchClientTask>();
    if (singleFilePanel.getFileName().length() > 0) {
        final String fileStr = singleFilePanel.getFileName();
        final String LOADING_MESSAGE = "Loading " + fileStr + "...";
        AsynchClientTask updateUIBeforeLoadTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                VirtualFrapMainFrame.updateStatus(LOADING_MESSAGE);
            }
        };
        AsynchClientTask loadTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy newFRAPStudy = null;
                File inFile = new File(fileStr);
                if (inFile != null) {
                    if (// .log (vcell log file)
                    inFile.getName().endsWith(SimDataConstants.LOGFILE_EXTENSION)) {
                        DataIdentifier[] dataIdentifiers = FrapDataUtils.getDataIdentiferListFromVCellSimulationData(inFile, 0);
                        ArrayList<String> selectedIdentifiers = new ArrayList<String>();
                        for (int i = 0; i < dataIdentifiers.length; i++) {
                            if (dataIdentifiers[i].getVariableType().equals(VariableType.VOLUME)) {
                                selectedIdentifiers.add(dataIdentifiers[i].getName());
                            }
                        }
                        String[][] rowData = new String[selectedIdentifiers.size()][1];
                        for (int i = 0; i < selectedIdentifiers.size(); i++) {
                            rowData[i][0] = selectedIdentifiers.get(i);
                        }
                        int[] selectedIndexArr = DialogUtils.showComponentOKCancelTableList(LoadFRAPData_SingleFileDescriptor.this.getPanelComponent(), "Select Volume Variable", new String[] { "Volume Variable Name" }, rowData, ListSelectionModel.SINGLE_SELECTION);
                        if (selectedIndexArr != null && selectedIndexArr.length > 0) {
                            scalePanel = getScalePanelForLoadingLogFile();
                            int choice = DialogUtils.showComponentOKCancelDialog(LoadFRAPData_SingleFileDescriptor.this.getPanelComponent(), scalePanel, "Input image maximum intensity (max: 65535)");
                            if (choice == JOptionPane.OK_OPTION) {
                                Double maxIntensity = null;
                                if (scalePanel.getInputScaleString() != null) {
                                    maxIntensity = new Double(scalePanel.getInputScaleString());
                                }
                                newFRAPStudy = FRAPWorkspace.loadFRAPDataFromVcellLogFile(inFile, selectedIdentifiers.get(selectedIndexArr[0]), null, maxIntensity, true, this.getClientTaskStatusSupport());
                                isFileLoaded = true;
                            } else {
                                throw UserCancelException.CANCEL_GENERIC;
                            }
                        } else {
                            throw UserCancelException.CANCEL_GENERIC;
                        }
                    } else if (inFile.getName().endsWith(SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_HDF5)) {
                        scalePanel = getScalePanelForLoadingLogFile();
                        int choice = DialogUtils.showComponentOKCancelDialog(LoadFRAPData_SingleFileDescriptor.this.getPanelComponent(), scalePanel, "Input data maximum value (max: 65535) which is used to avoid losing double precision when casting it to short.");
                        if (choice == JOptionPane.OK_OPTION) {
                            Double maxIntensity = null;
                            if (scalePanel.getInputScaleString() != null) {
                                maxIntensity = new Double(scalePanel.getInputScaleString());
                            }
                            newFRAPStudy = FRAPWorkspace.loadFRAPDataFromHDF5File(inFile, maxIntensity, this.getClientTaskStatusSupport());
                            isFileLoaded = true;
                        } else {
                            throw UserCancelException.CANCEL_GENERIC;
                        }
                    } else // .lsm or other image formatss
                    {
                        newFRAPStudy = FRAPWorkspace.loadFRAPDataFromImageFile(inFile, this.getClientTaskStatusSupport());
                        isFileLoaded = true;
                    }
                } else {
                    throw new RuntimeException("Input file is null.");
                }
                // for all loaded file
                hashTable.put(FRAPStudyPanel.NEW_FRAPSTUDY_KEY, newFRAPStudy);
            }
        };
        AsynchClientTask afterLoadingSwingTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy newFRAPStudy = (FRAPStudy) hashTable.get(FRAPStudyPanel.NEW_FRAPSTUDY_KEY);
                // setFrapStudy fires property change, so we have to put it in Swing thread.
                getFrapWorkspace().setFrapStudy(newFRAPStudy, true);
                VirtualFrapLoader.mf.setMainFrameTitle("");
                VirtualFrapMainFrame.updateProgress(0);
                if (isFileLoaded) {
                    VirtualFrapMainFrame.updateStatus("Loaded " + fileStr);
                } else {
                    VirtualFrapMainFrame.updateStatus("Failed loading " + fileStr + ".");
                }
            }
        };
        taskArrayList.add(updateUIBeforeLoadTask);
        taskArrayList.add(loadTask);
        taskArrayList.add(afterLoadingSwingTask);
    } else {
        DialogUtils.showErrorDialog(singleFilePanel, "Load File name is empty. Please input a file name to continue.");
        throw new RuntimeException("Load File name is empty. Please input a file name to continue.");
    }
    return taskArrayList;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) DataIdentifier(cbit.vcell.simdata.DataIdentifier) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) File(java.io.File)

Example 69 with AsynchClientTask

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);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) UserResolvedRxElements(cbit.vcell.graph.gui.BioCartoonTool.UserResolvedRxElements) Hashtable(java.util.Hashtable) BioCartoonTool(cbit.vcell.graph.gui.BioCartoonTool) SpeciesContext(cbit.vcell.model.SpeciesContext) UserResolvedRxElements(cbit.vcell.graph.gui.BioCartoonTool.UserResolvedRxElements) ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) Structure(cbit.vcell.model.Structure) DBFormalSpecies(cbit.vcell.model.DBFormalSpecies) Species(cbit.vcell.model.Species) DBNonFormalUnboundSpecies(cbit.vcell.dictionary.DBNonFormalUnboundSpecies)

Example 70 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class DBReactionWizardPanel method search.

/**
 * Comment
 */
private void search() {
    if (getDocumentManager() != null) {
        String textSearchS = getFindTextJTextField().getText();
        if (textSearchS != null && textSearchS.length() == 0) {
            textSearchS = null;
        }
        final ReactionQuerySpec reactionQuerySpec = new ReactionQuerySpec((getFindRXTextRadioButton().isSelected() ? formatLikeString(textSearchS) : null), (getKeggMoleculeJRadioButton().isSelected() ? getCurrentDBFormalSpecies() : null));
        if (getSearchUserJRadioButton().isSelected()) {
            searchUserReactions(reactionQuerySpec);
            return;
        }
        final DocumentManager docManager = getDocumentManager();
        final javax.swing.JList jlist = getReactionsJList();
        // 
        final String RXDESC_VALUE_KEY = "rxDesc";
        AsynchClientTask searchReactions = new AsynchClientTask("searching reactions", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hash) throws DataAccessException {
                ReactionDescription[] dbfr = docManager.getDictionaryReactions(reactionQuerySpec);
                if (dbfr != null && dbfr.length > 0) {
                    hash.put(RXDESC_VALUE_KEY, dbfr);
                }
            }
        };
        // 
        AsynchClientTask updateRXList = new AsynchClientTask("updateRXList", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hash) {
                ReactionDescription[] dbfr = (ReactionDescription[]) hash.get(RXDESC_VALUE_KEY);
                if (dbfr != null) {
                    jlist.setListData(dbfr);
                } else {
                    jlist.setListData(new ReactionDescription[0]);
                }
                afterSearchConfigure();
            }
        };
        // 
        Hashtable<String, Object> hashTemp = new Hashtable<String, Object>();
        ClientTaskDispatcher.dispatch(this, hashTemp, new AsynchClientTask[] { searchReactions, updateRXList }, false);
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) DocumentManager(cbit.vcell.clientdb.DocumentManager) JList(javax.swing.JList) ReactionQuerySpec(cbit.vcell.model.ReactionQuerySpec) ReactionDescription(cbit.vcell.model.ReactionDescription)

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