Search in sources :

Example 1 with SimulationWindow

use of cbit.vcell.client.desktop.simulation.SimulationWindow in project vcell by virtualcell.

the class ClientSimManager method showSimulationResults0.

private AsynchClientTask[] showSimulationResults0(final boolean isLocal, final ViewerType viewerType) {
    // Create the AsynchClientTasks
    ArrayList<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
    taskList.add(new AsynchClientTaskFunction(h -> {
        h.put(H_LOCAL_SIM, isLocal);
        h.put(H_VIEWER_TYPE, viewerType);
    }, "setLocal", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING));
    final DocumentWindowManager documentWindowManager = getDocumentWindowManager();
    AsynchClientTask retrieveResultsTask = new AsynchClientTask("Retrieving results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @SuppressWarnings("unchecked")
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
            for (int i = 0; i < simsToShow.length; i++) {
                final Simulation sim = simsToShow[i];
                final VCSimulationIdentifier vcSimulationIdentifier = sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
                final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
                OutputContext outputContext = (OutputContext) hashTable.get("outputContext");
                if (simWindow == null && (viewerType == ViewerType.NativeViewer_only)) {
                    try {
                        // make the manager and wire it up
                        DataViewerController dataViewerController = null;
                        if (!isLocal) {
                            dataViewerController = documentWindowManager.getRequestManager().getDataViewerController(outputContext, sim, 0);
                            // For changes in time or variable
                            documentWindowManager.addDataListener(dataViewerController);
                        } else {
                            // ---- preliminary : construct the localDatasetControllerProvider
                            File primaryDir = ResourceUtil.getLocalRootDir();
                            User usr = sim.getVersion().getOwner();
                            DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
                            ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
                            LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
                            VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
                            File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
                            LocalVCDataIdentifier vcDataId = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
                            DataManager dataManager = null;
                            if (sim.isSpatial()) {
                                dataManager = new PDEDataManager(outputContext, vcDataManager, vcDataId);
                            } else {
                                dataManager = new ODEDataManager(outputContext, vcDataManager, vcDataId);
                            }
                            dataViewerController = new SimResultsViewerController(dataManager, sim);
                            dataSetControllerImpl.addDataJobListener(documentWindowManager);
                        }
                        // make the viewer
                        Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
                        if (dataViewerControllers == null) {
                            dataViewerControllers = new Hashtable<VCSimulationIdentifier, DataViewerController>();
                            hashTable.put(H_DATA_VIEWER_CONTROLLERS, dataViewerControllers);
                        }
                        dataViewerControllers.put(vcSimulationIdentifier, dataViewerController);
                    } catch (Throwable exc) {
                        exc.printStackTrace(System.out);
                        saveFailure(hashTable, sim, exc);
                    }
                }
            }
        }
    };
    taskList.add(retrieveResultsTask);
    AsynchClientTask displayResultsTask = new AsynchClientTask("Showing results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @SuppressWarnings("unchecked")
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            boolean isLocal = fetch(hashTable, H_LOCAL_SIM, Boolean.class, true);
            SimulationWindow.LocalState localState = isLocal ? LocalState.LOCAL : LocalState.SERVER;
            Hashtable<Simulation, Throwable> failures = (Hashtable<Simulation, Throwable>) hashTable.get(H_FAILURES);
            Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
            for (int i = 0; i < simsToShow.length; i++) {
                final Simulation sim = simsToShow[i];
                if (failures != null && failures.containsKey(sim)) {
                    continue;
                }
                final VCSimulationIdentifier vcSimulationIdentifier = simsToShow[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
                final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
                if (simWindow != null) {
                    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(documentWindowManager.getComponent());
                    ChildWindow childWindow = childWindowManager.getChildWindowFromContext(simWindow);
                    if (childWindow == null) {
                        childWindow = childWindowManager.addChildWindow(simWindow.getDataViewer(), simWindow);
                        childWindow.pack();
                        childWindow.setIsCenteredOnParent();
                        childWindow.show();
                    }
                    setFinalWindow(hashTable, childWindow);
                    simWindow.setLocalState(localState);
                } else {
                    // wire it up the viewer
                    Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
                    DataViewerController viewerController = dataViewerControllers.get(vcSimulationIdentifier);
                    Throwable ex = (failures == null ? null : failures.get(sim));
                    if (viewerController != null && ex == null) {
                        // no failure
                        DataViewer viewer = viewerController.createViewer();
                        getSimWorkspace().getSimulationOwner().getOutputFunctionContext().addPropertyChangeListener(viewerController);
                        documentWindowManager.addExportListener(viewer);
                        // For data related activities such as calculating statistics
                        documentWindowManager.addDataJobListener(viewer);
                        viewer.setSimulationModelInfo(new SimulationWorkspaceModelInfo(getSimWorkspace().getSimulationOwner(), sim.getName()));
                        viewer.setDataViewerManager(documentWindowManager);
                        SimulationWindow newWindow = new SimulationWindow(vcSimulationIdentifier, sim, getSimWorkspace().getSimulationOwner(), viewer);
                        BeanUtils.addCloseWindowKeyboardAction(newWindow.getDataViewer());
                        documentWindowManager.addResultsFrame(newWindow);
                        setFinalWindow(hashTable, viewer);
                        newWindow.setLocalState(localState);
                    }
                }
            }
            StringBuffer failMessage = new StringBuffer();
            if (failures != null) {
                if (!failures.isEmpty()) {
                    failMessage.append("Error, " + failures.size() + " of " + simsToShow.length + " sim results failed to display:\n");
                    Enumeration<Simulation> en = failures.keys();
                    while (en.hasMoreElements()) {
                        Simulation sim = en.nextElement();
                        Throwable exc = (Throwable) failures.get(sim);
                        failMessage.append("'" + sim.getName() + "' - " + exc.getMessage());
                    }
                }
            }
            if (failMessage.length() > 0) {
                PopupGenerator.showErrorDialog(ClientSimManager.this.getDocumentWindowManager(), failMessage.toString());
            }
        }
    };
    if (viewerType == ViewerType.NativeViewer_only) {
        taskList.add(displayResultsTask);
    }
    // Dispatch the tasks using the ClientTaskDispatcher.
    AsynchClientTask[] taskArray = new AsynchClientTask[taskList.size()];
    taskList.toArray(taskArray);
    return taskArray;
}
Also used : User(org.vcell.util.document.User) SimulationMessage(cbit.vcell.solver.server.SimulationMessage) Enumeration(java.util.Enumeration) Version(org.vcell.util.document.Version) Vector(java.util.Vector) Map(java.util.Map) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) SimulationContext(cbit.vcell.mapping.SimulationContext) PrintWriter(java.io.PrintWriter) NetworkGenerationRequirements(cbit.vcell.mapping.SimulationContext.NetworkGenerationRequirements) VCDataManager(cbit.vcell.simdata.VCDataManager) BeanUtils(org.vcell.util.BeanUtils) ODESimData(cbit.vcell.solver.ode.ODESimData) WindowAdapter(java.awt.event.WindowAdapter) SimulationWorkspace(cbit.vcell.client.desktop.simulation.SimulationWorkspace) SolverListener(cbit.vcell.solver.server.SolverListener) VtkManager(cbit.vcell.simdata.VtkManager) SimulationJob(cbit.vcell.solver.SimulationJob) VCellClientTest(cbit.vcell.client.test.VCellClientTest) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) DataProcessingInstructions(cbit.vcell.solver.DataProcessingInstructions) VCellClientDataServiceImpl(cbit.vcell.client.data.VCellClientDataServiceImpl) OutputContext(cbit.vcell.simdata.OutputContext) SimulationTask(cbit.vcell.messaging.server.SimulationTask) VCDocument(org.vcell.util.document.VCDocument) TempSimulation(cbit.vcell.solver.TempSimulation) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SolverFactory(cbit.vcell.solver.server.SolverFactory) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationInfo(cbit.vcell.solver.SimulationInfo) Container(java.awt.Container) PDEDataManager(cbit.vcell.simdata.PDEDataManager) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) UserPreferences(cbit.vcell.client.server.UserPreferences) BioModel(cbit.vcell.biomodel.BioModel) BufferedWriter(java.io.BufferedWriter) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException) Window(java.awt.Window) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) PropertyLoader(cbit.vcell.resource.PropertyLoader) InputStreamReader(java.io.InputStreamReader) File(java.io.File) SolverUtilities(cbit.vcell.solver.SolverUtilities) DialogUtils(org.vcell.util.gui.DialogUtils) DataViewerController(cbit.vcell.client.data.DataViewerController) SimResultsViewer(cbit.vcell.client.data.SimResultsViewer) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow) EventObject(java.util.EventObject) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) DataViewer(cbit.vcell.client.data.DataViewer) ColumnDescription(cbit.vcell.util.ColumnDescription) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) SmoldynSolver(org.vcell.solver.smoldyn.SmoldynSolver) Simulation(cbit.vcell.solver.Simulation) Solver(cbit.vcell.solver.server.Solver) Collection(java.util.Collection) UtilCancelException(org.vcell.util.UtilCancelException) WindowEvent(java.awt.event.WindowEvent) FileNotFoundException(java.io.FileNotFoundException) SolverEvent(cbit.vcell.solver.server.SolverEvent) AsynchClientTaskFunction(cbit.vcell.client.task.AsynchClientTaskFunction) Dimension(java.awt.Dimension) List(java.util.List) ClientTaskDispatcher(cbit.vcell.client.task.ClientTaskDispatcher) VCellConfiguration(cbit.vcell.resource.VCellConfiguration) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) SimulationOwner(cbit.vcell.solver.SimulationOwner) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) SimulationWorkspaceModelInfo(cbit.vcell.client.data.SimulationWorkspaceModelInfo) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) DataSetController(cbit.vcell.server.DataSetController) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) LocalState(cbit.vcell.client.desktop.simulation.SimulationWindow.LocalState) SwingUtilities(javax.swing.SwingUtilities) SimDataConstants(cbit.vcell.simdata.SimDataConstants) SolverException(cbit.vcell.solver.SolverException) Hashtable(java.util.Hashtable) SimulationStatusDetailsPanel(cbit.vcell.client.desktop.simulation.SimulationStatusDetailsPanel) SimulationStatus(cbit.vcell.server.SimulationStatus) SimulationDataSetRef(cbit.vcell.client.pyvcellproxy.SimulationDataSetRef) ClientServerManager(cbit.vcell.client.server.ClientServerManager) ResourceUtil(cbit.vcell.resource.ResourceUtil) ODEDataManager(cbit.vcell.simdata.ODEDataManager) FileWriter(java.io.FileWriter) SmoldynFileWriter(org.vcell.solver.smoldyn.SmoldynFileWriter) ExpressionException(cbit.vcell.parser.ExpressionException) TokenMangler(org.vcell.util.TokenMangler) SolverDescription(cbit.vcell.solver.SolverDescription) SimulationStatusDetails(cbit.vcell.client.desktop.simulation.SimulationStatusDetails) ProgressDialogListener(org.vcell.util.ProgressDialogListener) DataManager(cbit.vcell.simdata.DataManager) InputStream(java.io.InputStream) UserCancelException(org.vcell.util.UserCancelException) LocalState(cbit.vcell.client.desktop.simulation.SimulationWindow.LocalState) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) User(org.vcell.util.document.User) ArrayList(java.util.ArrayList) AsynchClientTaskFunction(cbit.vcell.client.task.AsynchClientTaskFunction) DataViewerController(cbit.vcell.client.data.DataViewerController) DataViewer(cbit.vcell.client.data.DataViewer) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) VCDataManager(cbit.vcell.simdata.VCDataManager) SimulationWorkspaceModelInfo(cbit.vcell.client.data.SimulationWorkspaceModelInfo) Hashtable(java.util.Hashtable) VCDataManager(cbit.vcell.simdata.VCDataManager) PDEDataManager(cbit.vcell.simdata.PDEDataManager) ODEDataManager(cbit.vcell.simdata.ODEDataManager) DataManager(cbit.vcell.simdata.DataManager) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) OutputContext(cbit.vcell.simdata.OutputContext) TempSimulation(cbit.vcell.solver.TempSimulation) Simulation(cbit.vcell.solver.Simulation) PDEDataManager(cbit.vcell.simdata.PDEDataManager) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) ODEDataManager(cbit.vcell.simdata.ODEDataManager) File(java.io.File)

Example 2 with SimulationWindow

use of cbit.vcell.client.desktop.simulation.SimulationWindow in project vcell by virtualcell.

the class ApplicationComponents method getDataViewerFrames.

/**
 * Insert the method's description here.
 * Creation date: (6/3/2004 4:40:40 PM)
 */
public ChildWindow[] getDataViewerFrames(Component component) {
    SimulationWindow[] simWindows = (SimulationWindow[]) BeanUtils.getArray(simulationWindowsHash.elements(), SimulationWindow.class);
    ArrayList<ChildWindow> childWindows = new ArrayList<ChildWindow>();
    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(component);
    for (int i = 0; i < simWindows.length; i++) {
        ChildWindow childWindow = childWindowManager.getChildWindowFromContext(simWindows[i]);
        if (childWindow != null) {
            childWindows.add(childWindow);
        }
    }
    return childWindows.toArray(new ChildWindow[childWindows.size()]);
}
Also used : ArrayList(java.util.ArrayList) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow) ChildWindowManager(cbit.vcell.client.ChildWindowManager) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow)

Example 3 with SimulationWindow

use of cbit.vcell.client.desktop.simulation.SimulationWindow in project vcell by virtualcell.

the class ApplicationComponents method cleanSimWindowsHash.

/**
 * Remove server side sim results windows that are no longer in use
 */
public void cleanSimWindowsHash() {
    Iterator<Entry<VCSimulationIdentifier, SimulationWindow>> iter = simulationWindowsHash.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<VCSimulationIdentifier, SimulationWindow> es = iter.next();
        SimulationWindow sw = es.getValue();
        if (!sw.isShowingLocalSimulation()) {
            VCSimulationIdentifier vcsid = es.getKey();
            Simulation[] sims = simulationWorkspace.getSimulations();
            boolean bFound = false;
            for (int i = 0; i < sims.length; i += 1) {
                if (sims[i].getSimulationInfo() != null && sims[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier().equals(vcsid)) {
                    bFound = true;
                    break;
                }
            }
            if (!bFound) {
                iter.remove();
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) Simulation(cbit.vcell.solver.Simulation) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow)

Example 4 with SimulationWindow

use of cbit.vcell.client.desktop.simulation.SimulationWindow in project vcell by virtualcell.

the class BioModelWindowManager method haveSimulationWindow.

/**
 * Insert the method's description here.
 * Creation date: (6/11/2004 7:57:44 AM)
 * @return cbit.vcell.document.VCDocument
 */
public SimulationWindow haveSimulationWindow(VCSimulationIdentifier vcSimulationIdentifier) {
    Enumeration<ApplicationComponents> en = getApplicationsHash().elements();
    while (en.hasMoreElements()) {
        ApplicationComponents appComponents = en.nextElement();
        SimulationWindow window = appComponents.haveSimulationWindow(vcSimulationIdentifier);
        if (window != null) {
            return window;
        }
    }
    return null;
}
Also used : ApplicationComponents(cbit.vcell.client.desktop.biomodel.ApplicationComponents) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow)

Example 5 with SimulationWindow

use of cbit.vcell.client.desktop.simulation.SimulationWindow in project vcell by virtualcell.

the class BioModelWindowManager method updateSimulationDataViewers.

/**
 * Insert the method's description here.
 * Creation date: (7/20/2004 1:13:06 PM)
 */
private void updateSimulationDataViewers(ApplicationComponents appComponents, SimulationContext found) {
    SimulationWindow[] simWindows = appComponents.getSimulationWindows();
    Simulation[] sims = found.getSimulations();
    Hashtable<VCSimulationIdentifier, Simulation> hash = new Hashtable<VCSimulationIdentifier, Simulation>();
    for (int i = 0; i < sims.length; i++) {
        SimulationInfo simInfo = sims[i].getSimulationInfo();
        if (simInfo != null) {
            VCSimulationIdentifier vcSimulationIdentifier = simInfo.getAuthoritativeVCSimulationIdentifier();
            hash.put(vcSimulationIdentifier, sims[i]);
        }
    }
    for (int i = 0; i < simWindows.length; i++) {
        SimulationWindow sw = simWindows[i];
        if (hash.containsKey(simWindows[i].getVcSimulationIdentifier())) {
            sw.resetSimulation((Simulation) hash.get(sw.getVcSimulationIdentifier()));
        } else if (sw.isShowingLocalSimulation()) {
            sw.setLocalState(LocalState.LOCAL_SIMMODFIED);
        } else {
            ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(getJPanel());
            ChildWindow childWindow = childWindowManager.getChildWindowFromContext(sw);
            if (childWindow != null) {
                childWindowManager.closeChildWindow(childWindow);
            }
        }
    }
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) Simulation(cbit.vcell.solver.Simulation) Hashtable(java.util.Hashtable) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) SimulationInfo(cbit.vcell.solver.SimulationInfo)

Aggregations

SimulationWindow (cbit.vcell.client.desktop.simulation.SimulationWindow)8 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)5 Simulation (cbit.vcell.solver.Simulation)4 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)3 Hashtable (java.util.Hashtable)3 SimResultsViewer (cbit.vcell.client.data.SimResultsViewer)2 SimulationWorkspaceModelInfo (cbit.vcell.client.data.SimulationWorkspaceModelInfo)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)2 SimulationContext (cbit.vcell.mapping.SimulationContext)2 RemoteProxyException (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)2 SimulationTask (cbit.vcell.messaging.server.SimulationTask)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 OutputContext (cbit.vcell.simdata.OutputContext)2 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)2 SimulationInfo (cbit.vcell.solver.SimulationInfo)2 ArrayList (java.util.ArrayList)2 BioModel (cbit.vcell.biomodel.BioModel)1 BioModelWindowManager (cbit.vcell.client.BioModelWindowManager)1 ChildWindowManager (cbit.vcell.client.ChildWindowManager)1