Search in sources :

Example 36 with AsynchClientTask

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

the class PDEPlotControlPanel method filterVariableNames.

private void filterVariableNames() throws Exception {
    AsynchClientTask[] filterVarNamesTasks = getFilterVarNamesTasks();
    Hashtable<String, Object> hashTable = new Hashtable<>();
    for (int i = 0; i < filterVarNamesTasks.length; i++) {
        final AsynchClientTask nextTask = filterVarNamesTasks[i];
        nextTask.run(hashTable);
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable)

Example 37 with AsynchClientTask

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

the class PDEPlotControlPanel method getFilterVarNamesTasks.

private AsynchClientTask[] getFilterVarNamesTasks() {
    final Object oldselection = getPlotVariableJList().getSelectedValue();
    final ArrayList<DataIdentifier> displayDataIdentifiers = new ArrayList<DataIdentifier>();
    AsynchClientTask task2 = new AsynchClientTask("filter variables", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (PDEPlotControlPanel.this.getName().equals("PostProcessPDEPCP")) {
                System.out.println("PostProcessPDEPCP");
            }
            getViewFunctionButton().setVisible(bHasOldUserDefinedFunctions);
            if (myDataIdentifiers != null && myDataIdentifiers.length > 0) {
                DataIdentifier[] dataIdentifierArr = new DataIdentifier[myDataIdentifiers.length];
                System.arraycopy(myDataIdentifiers, 0, dataIdentifierArr, 0, myDataIdentifiers.length);
                Arrays.sort(dataIdentifierArr, new Comparator<DataIdentifier>() {

                    public int compare(DataIdentifier o1, DataIdentifier o2) {
                        int bEqualIgnoreCase = o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
                        if (bEqualIgnoreCase == 0) {
                            return o1.getDisplayName().compareTo(o2.getDisplayName());
                        }
                        return bEqualIgnoreCase;
                    }
                });
                if (dataIdentifierFilter == null) {
                    displayDataIdentifiers.addAll(Arrays.asList(dataIdentifierArr));
                } else {
                    ArrayList<DataIdentifier> acceptedDataIdentifiers = dataIdentifierFilter.accept((String) filterComboBox.getSelectedItem(), Arrays.asList(myAnnotFunctions), dataIdentifierArr);
                    if (acceptedDataIdentifiers != null) {
                        displayDataIdentifiers.addAll(acceptedDataIdentifiers);
                    }
                }
            }
        }
    };
    AsynchClientTask task3 = new AsynchClientTask("Update filtered variables", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (PDEPlotControlPanel.this.getName().equals("PostProcessPDEPCP")) {
                System.out.println("PostProcessPDEPCP");
            }
            getDefaultListModelCivilized1().removeListDataListener(ivjEventHandler);
            getDefaultListModelCivilized1().setContents(displayDataIdentifiers.size() == 0 ? null : displayDataIdentifiers.toArray(new DataIdentifier[0]));
            getPlotVariableJList().clearSelection();
            getDefaultListModelCivilized1().addListDataListener(ivjEventHandler);
            if (getPlotVariableJList().getModel().getSize() > 0) {
                if (oldselection == null) {
                    getPlotVariableJList().setSelectedIndex(0);
                } else {
                    boolean bFound = false;
                    for (int i = 0; i < getPlotVariableJList().getModel().getSize(); i++) {
                        if (oldselection.equals(getPlotVariableJList().getModel().getElementAt(i))) {
                            getPlotVariableJList().setSelectedIndex(i);
                            bFound = true;
                            break;
                        }
                    }
                    if (!bFound) {
                        getPlotVariableJList().setSelectedIndex(0);
                    }
                }
            }
        }
    };
    return new AsynchClientTask[] { task2, task3 };
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) DataIdentifier(cbit.vcell.simdata.DataIdentifier) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList)

Example 38 with AsynchClientTask

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

the class VirtualFrapBatchRunFrame method save.

public AsynchClientTask[] save() {
    ArrayList<AsynchClientTask> saveTasks = new ArrayList<AsynchClientTask>();
    AsynchClientTask beforeSaveTask = new AsynchClientTask("Saving file ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (batchRunWorkspace.getFrapStudies() == null || batchRunWorkspace.getFrapStudies().size() < 1) {
                throw new Exception("No Data exists to save");
            } else {
                File outputFile = null;
                String saveFileName = batchRunWorkspace.getBatchRunXmlFileName();
                if (saveFileName == null) {
                    int choice = VirtualFrapLoader.saveFileChooser_batchRun.showSaveDialog(VirtualFrapBatchRunFrame.this);
                    if (choice != JFileChooser.APPROVE_OPTION) {
                        throw UserCancelException.CANCEL_FILE_SELECTION;
                    }
                    saveFileName = VirtualFrapLoader.saveFileChooser_batchRun.getSelectedFile().getPath();
                    if (saveFileName != null) {
                        File tempOutputFile = new File(saveFileName);
                        if (!VirtualFrapLoader.filter_vfbatch.accept(tempOutputFile)) {
                            if (tempOutputFile.getName().indexOf(".") == -1) {
                                tempOutputFile = new File(tempOutputFile.getParentFile(), tempOutputFile.getName() + "." + VirtualFrapLoader.VFRAP_BATCH_EXTENSION);
                            } else {
                                // return?
                                throw new Exception("Virtual FRAP Batchrun document names must have an extension of ." + VirtualFrapLoader.VFRAP_BATCH_EXTENSION);
                            }
                        }
                        if (tempOutputFile.exists()) {
                            String overwriteChoice = DialogUtils.showWarningDialog(VirtualFrapBatchRunFrame.this, "OverWrite file\n" + tempOutputFile.getAbsolutePath(), new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CANCEL);
                            if (overwriteChoice.equals(UserMessage.OPTION_CANCEL)) {
                                throw UserCancelException.CANCEL_GENERIC;
                            } else {
                                // Remove single vfrap files in the overwritten batchRun
                                try {
                                // TODO
                                } catch (Exception e) {
                                    System.out.println("Error deleting externalData and simulation files for overwritten vfrap document " + tempOutputFile.getAbsolutePath() + "  " + e.getMessage());
                                    e.printStackTrace();
                                }
                            }
                        }
                        outputFile = tempOutputFile;
                    }
                } else {
                    outputFile = new File(saveFileName);
                }
                if (outputFile != null) {
                    updateStatus("Saving file " + outputFile.getAbsolutePath() + " ...");
                    hashTable.put(FRAPStudyPanel.SAVE_FILE_NAME_KEY, outputFile);
                }
            }
        }
    };
    saveTasks.add(beforeSaveTask);
    // add saving each single vfrap files in the batchrun
    saveTasks.add(batchRunWorkspace.getSaveSingleFilesTask());
    // write batch run file
    saveTasks.add(batchRunWorkspace.getSaveBatchRunFileTask());
    AsynchClientTask afterSaveTask = new AsynchClientTask("Saving file ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            File outFile = (File) hashTable.get(FRAPStudyPanel.SAVE_FILE_NAME_KEY);
            VirtualFrapBatchRunFrame.updateStatus("File " + outFile.getAbsolutePath() + " has been saved.");
            VirtualFrapLoader.mf.setBatchRunFrameTitle(outFile.getName());
        }
    };
    saveTasks.add(afterSaveTask);
    return saveTasks.toArray(new AsynchClientTask[saveTasks.size()]);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) File(java.io.File) UserCancelException(org.vcell.util.UserCancelException)

Example 39 with AsynchClientTask

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

the class VirtualFrapBatchRunFrame method open.

public AsynchClientTask[] open(final File inFile) {
    ArrayList<AsynchClientTask> totalTasks = new ArrayList<AsynchClientTask>();
    // check if save is needed before loading batch run file
    if (batchRunWorkspace.isSaveNeeded()) {
        String choice = DialogUtils.showWarningDialog(VirtualFrapBatchRunFrame.this, "There are unsaved changes. Save current document before loading new document?", new String[] { FRAPStudyPanel.SAVE_CONTINUE_MSG, FRAPStudyPanel.NO_THANKS_MSG }, FRAPStudyPanel.SAVE_CONTINUE_MSG);
        if (choice.equals(FRAPStudyPanel.SAVE_CONTINUE_MSG)) {
            AsynchClientTask[] saveTasks = save();
            for (int i = 0; i < saveTasks.length; i++) {
                totalTasks.add(saveTasks[i]);
            }
        }
    }
    AsynchClientTask preOpenTask = new AsynchClientTask("Loading " + inFile.getAbsolutePath() + "...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            VirtualFrapBatchRunFrame.updateStatus("Loading " + inFile.getAbsolutePath() + "...");
        }
    };
    totalTasks.add(preOpenTask);
    // load frap batch run file
    totalTasks.add(batchRunWorkspace.getLoadBatchRunFileTask(inFile));
    // load each single vfrap file
    totalTasks.add(batchRunWorkspace.getLoadSingleFilesTask(localWorkspace));
    // after loading task
    AsynchClientTask updateUIAfterLoadingTask = new AsynchClientTask("Updating User Interface ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FRAPBatchRunWorkspace tempBatchRunWorkspace = (FRAPBatchRunWorkspace) hashTable.get(FRAPBatchRunWorkspace.BATCH_RUN_WORKSPACE_KEY);
            // if loaded successfully, update the batchrunworkspace with the temporary one.
            batchRunWorkspace.update(tempBatchRunWorkspace);
            // update tree
            getBatchRunDetailsPanel().updateViewTreeForNewBatchRunFile(batchRunWorkspace);
            // update ui
            VirtualFrapLoader.mf.setBatchRunFrameTitle(batchRunWorkspace.getBatchRunXmlFileName());
            VirtualFrapBatchRunFrame.updateStatus("Loaded " + tempBatchRunWorkspace.getBatchRunXmlFileName());
        }
    };
    totalTasks.add(updateUIAfterLoadingTask);
    return totalTasks.toArray(new AsynchClientTask[totalTasks.size()]);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) FRAPBatchRunWorkspace(cbit.vcell.microscopy.batchrun.FRAPBatchRunWorkspace)

Example 40 with AsynchClientTask

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

the class BackgroundROIDescriptor method preBackProcess.

public ArrayList<AsynchClientTask> preBackProcess() {
    // create AsynchClientTask arraylist
    ArrayList<AsynchClientTask> taskArrayList = new ArrayList<AsynchClientTask>();
    final String backROIStr = FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name();
    AsynchClientTask setCurrentROITask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // save current ROI and load ROI in the panel it backs to
            ((BatchRunROIImgPanel) imgPanel).setCurrentROI(backROIStr, true);
        }
    };
    taskArrayList.add(setCurrentROITask);
    return taskArrayList;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList)

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