Search in sources :

Example 1 with ChildWindow

use of cbit.vcell.client.ChildWindowManager.ChildWindow 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.BothNativeAndPython || 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);
                    }
                }
                try {
                    if (viewerType == ViewerType.PythonViewer_only || viewerType == ViewerType.BothNativeAndPython) {
                        VtkManager vtkManager = null;
                        if (!isLocal) {
                            vtkManager = documentWindowManager.getRequestManager().getVtkManager(outputContext, new VCSimulationDataIdentifier(vcSimulationIdentifier, 0));
                        } 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());
                            VCSimulationDataIdentifier simulationDataIdentifier = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
                            vtkManager = new VtkManager(outputContext, vcDataManager, simulationDataIdentifier);
                        }
                        // 
                        // test ability to read data
                        // 
                        VtuVarInfo[] vtuVarInfos = vtkManager.getVtuVarInfos();
                        double[] times = vtkManager.getDataSetTimes();
                        // 
                        // create the SimulationDataSetRef
                        // 
                        VCDocument modelDocument = null;
                        if (documentWindowManager instanceof BioModelWindowManager) {
                            modelDocument = ((BioModelWindowManager) documentWindowManager).getBioModel();
                        } else if (documentWindowManager instanceof MathModelWindowManager) {
                            modelDocument = ((MathModelWindowManager) documentWindowManager).getMathModel();
                        }
                        SimulationDataSetRef simulationDataSetRef = VCellClientDataServiceImpl.createSimulationDataSetRef(sim, modelDocument, 0, isLocal);
                        // Hashtable<VCSimulationIdentifier, SimulationDataSetRef> simDataSetRefs = (Hashtable<VCSimulationIdentifier, SimulationDataSetRef>)hashTable.get(H_SIM_DATASET_REFS);
                        // if (simDataSetRefs == null) {
                        // simDataSetRefs = new Hashtable<VCSimulationIdentifier, SimulationDataSetRef>();
                        // hashTable.put(H_SIM_DATASET_REFS, simDataSetRefs);
                        // }
                        // simDataSetRefs.put(vcSimulationIdentifier, simulationDataSetRef);
                        File visitExe = VCellConfiguration.getFileProperty(PropertyLoader.visitExe);
                        if (visitExe != null) {
                            VisitSupport.launchVisTool(visitExe, simulationDataSetRef);
                        }
                    }
                } 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.BothNativeAndPython || 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) DataViewerController(cbit.vcell.client.data.DataViewerController) SimulationMessage(cbit.vcell.solver.server.SimulationMessage) Enumeration(java.util.Enumeration) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow) EventObject(java.util.EventObject) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) Vector(java.util.Vector) DataViewer(cbit.vcell.client.data.DataViewer) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) SmoldynSolver(org.vcell.solver.smoldyn.SmoldynSolver) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) SimulationContext(cbit.vcell.mapping.SimulationContext) PrintWriter(java.io.PrintWriter) VisitSupport(cbit.vcell.resource.VisitSupport) Simulation(cbit.vcell.solver.Simulation) NetworkGenerationRequirements(cbit.vcell.mapping.SimulationContext.NetworkGenerationRequirements) VCDataManager(cbit.vcell.simdata.VCDataManager) BeanUtils(org.vcell.util.BeanUtils) Solver(cbit.vcell.solver.server.Solver) Collection(java.util.Collection) SimulationWorkspace(cbit.vcell.client.desktop.simulation.SimulationWorkspace) SolverListener(cbit.vcell.solver.server.SolverListener) VtkManager(cbit.vcell.simdata.VtkManager) SolverEvent(cbit.vcell.solver.server.SolverEvent) AsynchClientTaskFunction(cbit.vcell.client.task.AsynchClientTaskFunction) Dimension(java.awt.Dimension) SimulationJob(cbit.vcell.solver.SimulationJob) ClientTaskDispatcher(cbit.vcell.client.task.ClientTaskDispatcher) VCellConfiguration(cbit.vcell.resource.VCellConfiguration) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) DataProcessingInstructions(cbit.vcell.solver.DataProcessingInstructions) SimulationOwner(cbit.vcell.solver.SimulationOwner) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) SimulationWorkspaceModelInfo(cbit.vcell.client.data.SimulationWorkspaceModelInfo) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) VCellClientDataServiceImpl(cbit.vcell.client.data.VCellClientDataServiceImpl) OutputContext(cbit.vcell.simdata.OutputContext) SimulationTask(cbit.vcell.messaging.server.SimulationTask) VCDocument(org.vcell.util.document.VCDocument) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) TempSimulation(cbit.vcell.solver.TempSimulation) ArrayList(java.util.ArrayList) LocalState(cbit.vcell.client.desktop.simulation.SimulationWindow.LocalState) SolverFactory(cbit.vcell.solver.server.SolverFactory) SolverStatus(cbit.vcell.solver.server.SolverStatus) 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) PDEDataManager(cbit.vcell.simdata.PDEDataManager) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) ResourceUtil(cbit.vcell.resource.ResourceUtil) ODEDataManager(cbit.vcell.simdata.ODEDataManager) SmoldynFileWriter(org.vcell.solver.smoldyn.SmoldynFileWriter) IOException(java.io.IOException) PropertyLoader(cbit.vcell.resource.PropertyLoader) InputStreamReader(java.io.InputStreamReader) File(java.io.File) SolverUtilities(cbit.vcell.solver.SolverUtilities) TokenMangler(org.vcell.util.TokenMangler) SolverDescription(cbit.vcell.solver.SolverDescription) DialogUtils(org.vcell.util.gui.DialogUtils) 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) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) User(org.vcell.util.document.User) ArrayList(java.util.ArrayList) SimulationDataSetRef(cbit.vcell.client.pyvcellproxy.SimulationDataSetRef) 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) VCDocument(org.vcell.util.document.VCDocument) 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) VtkManager(cbit.vcell.simdata.VtkManager) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) OutputContext(cbit.vcell.simdata.OutputContext) Simulation(cbit.vcell.solver.Simulation) TempSimulation(cbit.vcell.solver.TempSimulation) 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 ChildWindow

use of cbit.vcell.client.ChildWindowManager.ChildWindow in project vcell by virtualcell.

the class GeometryWindowManager method propertyChange.

/**
 * This method gets called when a bound property is changed.
 * @param evt A PropertyChangeEvent object describing the event source
 *   	and the property that has changed.
 */
public void propertyChange(java.beans.PropertyChangeEvent evt) {
    if (evt.getSource() instanceof GeometrySpec) {
        getGeometryEditor().setToggleButtonSelected("Surface Viewer", false);
        // do this because button.setSelected does not fire action event
        ChildWindow childWindow = ChildWindowManager.findChildWindowManager(getComponent()).getChildWindowFromContentPane(surfaceViewer);
        if (childWindow != null && childWindow.isShowing()) {
            surfaceViewerButtonPressed(false);
        }
    }
}
Also used : GeometrySpec(cbit.vcell.geometry.GeometrySpec) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow)

Example 3 with ChildWindow

use of cbit.vcell.client.ChildWindowManager.ChildWindow in project vcell by virtualcell.

the class GeometryWindowManager method hideSurfaceViewer.

private void hideSurfaceViewer() {
    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(getComponent());
    ChildWindow childWindow = childWindowManager.getChildWindowFromContentPane(surfaceViewer);
    if (childWindow != null) {
        childWindow.close();
    }
}
Also used : ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow)

Example 4 with ChildWindow

use of cbit.vcell.client.ChildWindowManager.ChildWindow in project vcell by virtualcell.

the class GeometryWindowManager method hideGeometryViewer.

private void hideGeometryViewer() {
    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(getComponent());
    ChildWindow childWindow = childWindowManager.getChildWindowFromContentPane(geoViewer);
    if (childWindow != null) {
        childWindow.close();
    }
}
Also used : ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow)

Example 5 with ChildWindow

use of cbit.vcell.client.ChildWindowManager.ChildWindow in project vcell by virtualcell.

the class TestingFrameworkWindowManager method queryTCritCrossRef.

@SuppressWarnings("serial")
public void queryTCritCrossRef(final TestSuiteInfoNew tsin, final TestCriteriaNew tcrit, final String varName) {
    try {
        QueryTestCriteriaCrossRefOP queryTestCriteriaCrossRefOP = new QueryTestCriteriaCrossRefOP(tsin.getTSKey(), tcrit.getTCritKey(), varName);
        TestCriteriaCrossRefOPResults testCriteriaCrossRefOPResults = (TestCriteriaCrossRefOPResults) getRequestManager().getDocumentManager().doTestSuiteOP(queryTestCriteriaCrossRefOP);
        final Vector<TestCriteriaCrossRefOPResults.CrossRefData> xrefDataV = testCriteriaCrossRefOPResults.getCrossRefData();
        final TestSuiteInfoNew[] testSuiteInfos = getRequestManager().getDocumentManager().getTestSuiteInfos();
        Vector<TestSuiteInfoNew> missingTestSuites = new Vector<TestSuiteInfoNew>();
        for (int i = 0; i < testSuiteInfos.length; i++) {
            boolean bFound = false;
            for (int j = 0; j < xrefDataV.size(); j++) {
                if (xrefDataV.elementAt(j).tsVersion.equals(testSuiteInfos[i].getTSID())) {
                    bFound = true;
                    break;
                }
            }
            if (!bFound) {
                missingTestSuites.add(testSuiteInfos[i]);
            }
        }
        TestCriteriaCrossRefOPResults.CrossRefData xrefDataSource = null;
        for (int i = 0; i < xrefDataV.size(); i++) {
            if (xrefDataV.elementAt(i).tcritKey.equals(tcrit.getTCritKey())) {
                xrefDataSource = xrefDataV.elementAt(i);
                break;
            }
        }
        if (xrefDataSource == null) {
            throw new RuntimeException("Couldn't find source Test Criteria in query results.");
        }
        final int numColumns = 8;
        final int XREFDATA_ALLOWANCE = 1;
        final int TSKEY_ALLOWANCE = 1;
        final int XREFDATA_OFFSET = numColumns;
        final int TSDATE_OFFSET = 1;
        final int VARNAME_OFFSET = 3;
        final int TSKEYMISSING_OFFSET = numColumns + 1;
        final String[] colNames = new String[numColumns];
        final Object[][] sourceRows = new Object[xrefDataV.size() + missingTestSuites.size()][numColumns + XREFDATA_ALLOWANCE + TSKEY_ALLOWANCE];
        String sourceTestSuite = null;
        colNames[0] = "tsVersion";
        colNames[1] = "tsDate";
        colNames[2] = "tsBaseVersion";
        colNames[3] = "varName";
        colNames[4] = "RelErorr";
        colNames[5] = "limitRelErorr";
        colNames[6] = "limitAbsErorr";
        colNames[7] = "AbsErorr";
        for (int i = 0; i < xrefDataV.size(); i++) {
            sourceRows[i][colNames.length] = xrefDataV.elementAt(i);
            if (xrefDataV.elementAt(i).tcritKey.equals(queryTestCriteriaCrossRefOP.getTestCriterium())) {
                sourceTestSuite = xrefDataV.elementAt(i).tsVersion;
            }
            sourceRows[i][0] = xrefDataV.elementAt(i).tsVersion;
            sourceRows[i][2] = (xrefDataV.elementAt(i).tsRefVersion == null ? (xrefDataV.elementAt(i).regressionModelID == null ? /* && xrefDataV.elementAt(i).regressionMMref==null*/
            "" : "Ref Model exist BUT outside of TestSuites") : xrefDataV.elementAt(i).tsRefVersion);
            sourceRows[i][6] = xrefDataV.elementAt(i).maxAbsErorr;
            sourceRows[i][5] = xrefDataV.elementAt(i).maxRelErorr;
            if (xrefDataV.elementAt(i).varName != null) {
                sourceRows[i][VARNAME_OFFSET] = xrefDataV.elementAt(i).varName;
                sourceRows[i][4] = xrefDataV.elementAt(i).varCompSummary.getRelativeError();
                sourceRows[i][7] = xrefDataV.elementAt(i).varCompSummary.getAbsoluteError();
            } else {
                sourceRows[i][VARNAME_OFFSET] = "-No Report-";
                // "No Report";
                sourceRows[i][4] = null;
                // "No Report";
                sourceRows[i][7] = null;
            }
            for (int j = 0; j < testSuiteInfos.length; j++) {
                if (xrefDataV.elementAt(i).tsVersion.equals(testSuiteInfos[j].getTSID())) {
                    sourceRows[i][1] = testSuiteInfos[j].getTSDate();
                    break;
                }
            }
        }
        for (int i = xrefDataV.size(); i < sourceRows.length; i++) {
            sourceRows[i][0] = missingTestSuites.elementAt(i - xrefDataV.size()).getTSID();
            sourceRows[i][TSDATE_OFFSET] = missingTestSuites.elementAt(i - xrefDataV.size()).getTSDate();
            sourceRows[i][TSKEYMISSING_OFFSET] = missingTestSuites.elementAt(i - xrefDataV.size()).getTSKey();
        }
        // Arrays.sort(rows,
        // new Comparator<Object[]>(){
        // public int compare(Object[] o1, Object[] o2) {
        // return ((String)o1[0]).compareToIgnoreCase((String)o2[0]);
        // //						if(o1[0].equals(o2[0])){
        // //							return o1[3].compareToIgnoreCase(o2[3]);
        // //						}
        // //						return o1[0].compareToIgnoreCase(o2[0]);
        // }
        // }
        // );
        final VCellSortTableModel<Object[]> tableModel = new VCellSortTableModel<Object[]>(colNames) {

            public Class<?> getColumnClass(int columnIndex) {
                if (columnIndex == TSDATE_OFFSET) {
                    return Date.class;
                } else if (columnIndex >= 4 && columnIndex <= 7) {
                    return Double.class;
                }
                return String.class;
            }

            public boolean isCellEditable(int row, int column) {
                return false;
            }

            public Object getValueAt(int rowIndex, int columnIndex) {
                return getValueAt(rowIndex)[columnIndex];
            }

            public Comparator<Object[]> getComparator(final int col, final boolean ascending) {
                return new Comparator<Object[]>() {

                    public int compare(Object[] o1, Object[] o2) {
                        if (o1[col] == null && o2[col] == null) {
                            return 0;
                        }
                        // if(ascending){
                        if (o1[col] == null) {
                            return 1;
                        }
                        if (o2[col] == null) {
                            return -1;
                        }
                        // }
                        if (getColumnClass(col).equals(String.class)) {
                            if (ascending) {
                                return ((String) o1[col]).compareToIgnoreCase(((String) o2[col]));
                            } else {
                                return ((String) o2[col]).compareToIgnoreCase(((String) o1[col]));
                            }
                        } else if (getColumnClass(col).equals(Date.class)) {
                            if (ascending) {
                                return ((Date) o1[col]).compareTo(((Date) o2[col]));
                            }
                            return ((Date) o2[col]).compareTo(((Date) o1[col]));
                        } else if (getColumnClass(col).equals(Double.class)) {
                            if (ascending) {
                                return ((Double) o1[col]).compareTo(((Double) o2[col]));
                            }
                            return ((Double) o2[col]).compareTo(((Double) o1[col]));
                        }
                        throw new RuntimeException("TestSuite XRef Query unexpecte column class " + getColumnClass(col).getName());
                    }
                };
            }
        };
        tableModel.setData(Arrays.asList(sourceRows));
        // Create table
        final JSortTable table = new JSortTable();
        table.setModel(tableModel);
        table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        final JScrollPane scrollPaneContentPane = new JScrollPane(table);
        table.setPreferredScrollableViewportSize(new Dimension(500, 250));
        table.getColumnModel().getColumn(TSDATE_OFFSET).setCellRenderer(new DefaultTableCellRenderer() {

            // DateFormat formatter = DateFormat.getDateTimeInstance();
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                return super.getTableCellRendererComponent(table, (value == null ? null : ((Date) value).toString()), /*formatter.format((Date)value)*/
                isSelected, hasFocus, row, column);
            }
        });
        DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer() {

            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                return super.getTableCellRendererComponent(table, (value == null ? null : ((Double) value).toString()), /*formatter.format((Date)value)*/
                isSelected, hasFocus, row, column);
            }
        };
        table.getColumnModel().getColumn(4).setCellRenderer(dtcr);
        table.getColumnModel().getColumn(5).setCellRenderer(dtcr);
        table.getColumnModel().getColumn(6).setCellRenderer(dtcr);
        table.getColumnModel().getColumn(7).setCellRenderer(dtcr);
        // table.getColumnModel().getColumn(4).setCellRenderer(
        // new DefaultTableCellRenderer(){
        // public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        // return super.getTableCellRendererComponent(table,(value == null?null:((Double)value).toString())/*formatter.format((Date)value)*/, isSelected, hasFocus, row, column);
        // }
        // }
        // );
        // table.getTableHeader().setReorderingAllowed(false);
        // Popup Menu
        final TestCriteriaCrossRefOPResults.CrossRefData xrefDataSourceFinal = xrefDataSource;
        final JPopupMenu queryPopupMenu = new JPopupMenu();
        final JMenuItem changeLimitsMenuItem = new JMenuItem("Change Selected Error Limits...");
        final String OPEN_MODEL = "Open Model(s)";
        final JMenuItem openModelMenuItem = new JMenuItem(OPEN_MODEL);
        final String OPEN_REGRREFMODEL = "Open Regr Ref Model(s)";
        final JMenuItem openRegrRefModelMenuItem = new JMenuItem(OPEN_REGRREFMODEL);
        final String SELECT_REF_IN_TREE = "Select in Tree View";
        final JMenuItem showInTreeMenuItem = new JMenuItem(SELECT_REF_IN_TREE);
        final String SELECT_REGR_REF_IN_TREE = "Select RegrRef TCase in Tree View";
        final JMenuItem showRegrRefInTreeMenuItem = new JMenuItem(SELECT_REGR_REF_IN_TREE);
        queryPopupMenu.add(changeLimitsMenuItem);
        queryPopupMenu.add(openModelMenuItem);
        queryPopupMenu.add(openRegrRefModelMenuItem);
        queryPopupMenu.add(showInTreeMenuItem);
        queryPopupMenu.add(showRegrRefInTreeMenuItem);
        ActionListener showInTreeActionListener = new ActionListener() {

            public void actionPerformed(ActionEvent actionEvent) {
                int[] selectedRows = table.getSelectedRows();
                if (selectedRows == null || selectedRows.length != 1) {
                    PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Action " + actionEvent.getActionCommand() + " accepts only single selection!");
                    return;
                }
                TestCriteriaCrossRefOPResults.CrossRefData xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(selectedRows[0], XREFDATA_OFFSET);
                BigDecimal missingTSKey = (BigDecimal) tableModel.getValueAt(selectedRows[0], TSKEYMISSING_OFFSET);
                if (actionEvent.getActionCommand().equals(SELECT_REF_IN_TREE)) {
                    getTestingFrameworkWindowPanel().selectInTreeView((xrefData != null ? xrefData.tsKey : missingTSKey), (xrefData != null ? xrefData.tcaseKey : null), (xrefData != null ? xrefData.tcritKey : null));
                } else if (actionEvent.getActionCommand().equals(SELECT_REGR_REF_IN_TREE)) {
                    if (xrefData == null) {
                        PopupGenerator.showErrorDialog(getComponent(), "No Regression Reference info available.");
                        return;
                    }
                    getTestingFrameworkWindowPanel().selectInTreeView((xrefData != null ? xrefData.regressionModelTSuiteID : null), (xrefData != null ? xrefData.regressionModelTCaseID : null), (xrefData != null ? xrefData.regressionModelTCritID : null));
                }
                ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                if (childWindow != null) {
                    childWindow.show();
                }
            }
        };
        showInTreeMenuItem.addActionListener(showInTreeActionListener);
        showRegrRefInTreeMenuItem.addActionListener(showInTreeActionListener);
        ActionListener openModelsActionListener = new ActionListener() {

            public void actionPerformed(ActionEvent actionEvent) {
                int[] selectedRows = table.getSelectedRows();
                String failureS = "";
                TestCriteriaCrossRefOPResults.CrossRefData xrefData = null;
                int openCount = 0;
                for (int i = 0; i < selectedRows.length; i++) {
                    try {
                        xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(selectedRows[i], XREFDATA_OFFSET);
                        if (xrefData != null && (actionEvent.getActionCommand().equals(OPEN_REGRREFMODEL) ? xrefData.regressionModelID != null : true)) {
                            openCount += 1;
                            VCDocumentInfo vcDocInfo = null;
                            if (xrefData.isBioModel) {
                                vcDocInfo = getRequestManager().getDocumentManager().getBioModelInfo(new KeyValue((actionEvent.getActionCommand().equals(OPEN_REGRREFMODEL) ? xrefData.regressionModelID : xrefData.modelID)));
                            } else {
                                vcDocInfo = getRequestManager().getDocumentManager().getMathModelInfo(new KeyValue((actionEvent.getActionCommand().equals(OPEN_REGRREFMODEL) ? xrefData.regressionModelID : xrefData.modelID)));
                            }
                            getRequestManager().openDocument(vcDocInfo, TestingFrameworkWindowManager.this, true);
                        }
                    } catch (Exception e) {
                        failureS += failureS + "key=" + xrefData.modelID + " " + e.getMessage() + "\n";
                        e.printStackTrace();
                    }
                }
                if (failureS.length() > 0 || openCount == 0) {
                    PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Failed to open some models\n" + failureS + (openCount == 0 ? "Selection(s) had no model(s)" : ""));
                }
                ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                if (childWindow != null) {
                    childWindow.show();
                }
            }
        };
        openModelMenuItem.addActionListener(openModelsActionListener);
        openRegrRefModelMenuItem.addActionListener(openModelsActionListener);
        changeLimitsMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent actionEvent) {
                int[] selectedRows = table.getSelectedRows();
                Vector<TestCriteriaCrossRefOPResults.CrossRefData> changeTCritV = new Vector<TestCriteriaCrossRefOPResults.CrossRefData>();
                for (int i = 0; i < selectedRows.length; i++) {
                    TestCriteriaCrossRefOPResults.CrossRefData xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(selectedRows[i], XREFDATA_OFFSET);
                    if (xrefData != null) {
                        boolean bFound = false;
                        for (int j = 0; j < changeTCritV.size(); j++) {
                            if (changeTCritV.elementAt(j).tcritKey.equals(xrefData.tcritKey)) {
                                bFound = true;
                                break;
                            }
                        }
                        if (!bFound) {
                            changeTCritV.add(xrefData);
                        }
                    }
                }
                if (changeTCritV.size() > 0) {
                    Double relativeErrorLimit = null;
                    Double absoluteErrorLimit = null;
                    while (true) {
                        try {
                            String ret = PopupGenerator.showInputDialog(getComponent(), "Enter new TestCriteria Error Limits for '" + xrefDataSourceFinal.simName + "'.  '-'(dash) to keep original value.", "RelativeErrorLimit,AbsoluteErrorLimit");
                            int commaPosition = ret.indexOf(',');
                            if (commaPosition == -1) {
                                throw new Exception("No comma found separating RelativeErrorLimit AbsoluteErrorLimit");
                            }
                            if (commaPosition != ret.lastIndexOf(',')) {
                                throw new Exception("Only 1 comma allowed separating RelativeErrorLimit and AbsoluteErrorLimit");
                            }
                            final String KEEP_ORIGINAL_VALUE = "-";
                            String relativeErrorS = ret.substring(0, commaPosition);
                            String absoluteErrorS = ret.substring(commaPosition + 1, ret.length());
                            if (!relativeErrorS.equals(KEEP_ORIGINAL_VALUE)) {
                                relativeErrorLimit = Double.parseDouble(relativeErrorS);
                            }
                            if (!absoluteErrorS.equals(KEEP_ORIGINAL_VALUE)) {
                                absoluteErrorLimit = Double.parseDouble(absoluteErrorS);
                            }
                            if ((relativeErrorLimit != null && relativeErrorLimit <= 0) || (absoluteErrorLimit != null && absoluteErrorLimit <= 0)) {
                                throw new Exception("Error limits must be greater than 0");
                            }
                            break;
                        } catch (UserCancelException e) {
                            ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                            if (childWindow != null) {
                                childWindow.show();
                            }
                            return;
                        } catch (Exception e) {
                            PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Error parsing Error Limits\n" + e.getMessage());
                        }
                    }
                    double[] relErrorLimitArr = new double[changeTCritV.size()];
                    double[] absErrorLimitArr = new double[changeTCritV.size()];
                    Object[][] rows = new Object[changeTCritV.size()][5];
                    for (int j = 0; j < changeTCritV.size(); j++) {
                        relErrorLimitArr[j] = (relativeErrorLimit != null ? relativeErrorLimit.doubleValue() : changeTCritV.elementAt(j).maxRelErorr);
                        absErrorLimitArr[j] = (absoluteErrorLimit != null ? absoluteErrorLimit.doubleValue() : changeTCritV.elementAt(j).maxAbsErorr);
                        rows[j][2] = new Double(relErrorLimitArr[j]);
                        rows[j][4] = new Double(absErrorLimitArr[j]);
                        rows[j][1] = new Double(changeTCritV.elementAt(j).maxRelErorr);
                        rows[j][3] = new Double(changeTCritV.elementAt(j).maxAbsErorr);
                        rows[j][0] = changeTCritV.elementAt(j).tsVersion;
                    }
                    try {
                        PopupGenerator.showComponentOKCancelTableList(getComponent(), "Confirm Error Limit Changes", new String[] { "TSVersion", "Orig RelErrorLimit", "New RelErrorLimit", "Orig AbsErrorLimit", "New AbsErrorLimit" }, rows, null);
                    } catch (UserCancelException e) {
                        ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                        if (childWindow != null) {
                            childWindow.show();
                        }
                        return;
                    }
                    // Get information needed to generate new TestCriteria Reports
                    final String YES_ANSWER = "Yes";
                    Hashtable<TestSuiteInfoNew, Vector<TestCriteriaCrossRefOPResults.CrossRefData>> genReportHash = null;
                    String genRepResult = PopupGenerator.showWarningDialog(getComponent(), "Generate Reports for changed Test Criterias?", new String[] { YES_ANSWER, "No" }, YES_ANSWER);
                    if (genRepResult != null && genRepResult.equals(YES_ANSWER)) {
                        genReportHash = new Hashtable<TestSuiteInfoNew, Vector<TestCriteriaCrossRefOPResults.CrossRefData>>();
                        for (int i = 0; i < changeTCritV.size(); i++) {
                            boolean bFound = false;
                            for (int j = 0; j < testSuiteInfos.length; j++) {
                                if (changeTCritV.elementAt(i).tsVersion.equals(testSuiteInfos[j].getTSID())) {
                                    bFound = true;
                                    Vector<TestCriteriaCrossRefOPResults.CrossRefData> tempV = genReportHash.get(testSuiteInfos[j]);
                                    if (tempV == null) {
                                        tempV = new Vector<TestCriteriaCrossRefOPResults.CrossRefData>();
                                        genReportHash.put(testSuiteInfos[j], tempV);
                                    }
                                    tempV.add(changeTCritV.elementAt(i));
                                }
                            }
                            if (!bFound) {
                                PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Couldn't find testsuiteinfo for testcriteria");
                                return;
                            }
                        }
                    }
                    BigDecimal[] changeTCritBDArr = new BigDecimal[changeTCritV.size()];
                    for (int i = 0; i < changeTCritV.size(); i++) {
                        changeTCritBDArr[i] = changeTCritV.elementAt(i).tcritKey;
                    }
                    ChangeTestCriteriaErrorLimitOP changeTestCriteriaErrorLimitOP = new ChangeTestCriteriaErrorLimitOP(changeTCritBDArr, absErrorLimitArr, relErrorLimitArr);
                    try {
                        getTestingFrameworkWindowPanel().getDocumentManager().doTestSuiteOP(changeTestCriteriaErrorLimitOP);
                    } catch (Exception e) {
                        PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Failed Changing Error limits for selected " + xrefDataSourceFinal.simName + "\n" + e.getMessage());
                        return;
                    }
                    ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                    if (childWindow != null) {
                        childWindow.close();
                    }
                    getTestingFrameworkWindowPanel().refreshTree((TestSuiteInfoNew) null);
                    if (genReportHash != null) {
                        updateReports(genReportHash);
                    } else {
                        new Thread(new Runnable() {

                            public void run() {
                                TestingFrameworkWindowManager.this.queryTCritCrossRef(tsin, tcrit, varName);
                            }
                        }).start();
                    }
                } else {
                    PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "No selected rows contain Test Criteria.");
                }
            }
        });
        table.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                checkPopup(e);
            }

            @Override
            public void mousePressed(MouseEvent e) {
                super.mousePressed(e);
                checkPopup(e);
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                super.mouseReleased(e);
                checkPopup(e);
            }

            private void checkPopup(MouseEvent mouseEvent) {
                if (mouseEvent.isPopupTrigger()) {
                    // Not use because popupmenu will not show at edge
                    // if(table.getSelectedRowCount() <= 1){
                    // table.getSelectionModel().setSelectionInterval(table.rowAtPoint(mouseEvent.getPoint()),table.rowAtPoint(mouseEvent.getPoint()));
                    // }
                    doPopup(mouseEvent);
                } else {
                    queryPopupMenu.setVisible(false);
                }
            }

            private void doPopup(MouseEvent mouseEvent) {
                // queryPopupMenu.add(showInTreeMenuItem);
                if (table.getSelectedRowCount() == 0) {
                    changeLimitsMenuItem.setEnabled(false);
                    openModelMenuItem.setEnabled(false);
                    openRegrRefModelMenuItem.setEnabled(false);
                    showInTreeMenuItem.setEnabled(false);
                    showRegrRefInTreeMenuItem.setEnabled(false);
                } else {
                    changeLimitsMenuItem.setEnabled(true);
                    openModelMenuItem.setEnabled(true);
                    openRegrRefModelMenuItem.setEnabled(true);
                    showInTreeMenuItem.setEnabled(true);
                    if (table.getSelectedRowCount() == 1) {
                        TestCriteriaCrossRefOPResults.CrossRefData xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(table.getSelectedRow(), numColumns);
                        showRegrRefInTreeMenuItem.setEnabled(xrefData != null && xrefData.regressionModelID != null && xrefData.tsRefVersion != null);
                    }
                }
                queryPopupMenu.show(mouseEvent.getComponent(), mouseEvent.getPoint().x, mouseEvent.getPoint().y);
            }
        });
        String title = (xrefDataSource.isBioModel ? "BM" : "MM") + " " + xrefDataSource.tcSolutionType + " (" + sourceTestSuite + ") " + " \"" + (xrefDataSource.isBioModel ? xrefDataSource.bmName : xrefDataSource.mmName) + "\"  ::  " + (xrefDataSource.isBioModel ? "app=\"" + xrefDataSource.bmAppName + "\"  ::  sim=\"" + xrefDataSource.simName + "\"" : "sim=\"" + xrefDataSource.simName + "\"");
        ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).addChildWindow(scrollPaneContentPane, scrollPaneContentPane, title);
        // childWindow.setSize(600,400);
        childWindow.setIsCenteredOnParent();
        childWindow.pack();
        childWindow.setResizable(true);
        childWindow.show();
    } catch (DataAccessException e) {
        e.printStackTrace();
        PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Error Query TestCriteria Cross Ref:\n" + e.getMessage());
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) ActionEvent(java.awt.event.ActionEvent) UserCancelException(org.vcell.util.UserCancelException) Comparator(java.util.Comparator) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) Component(java.awt.Component) JComponent(javax.swing.JComponent) JMenuItem(javax.swing.JMenuItem) Vector(java.util.Vector) CrossRefData(cbit.vcell.numericstest.TestCriteriaCrossRefOPResults.CrossRefData) DataAccessException(org.vcell.util.DataAccessException) JScrollPane(javax.swing.JScrollPane) QueryTestCriteriaCrossRefOP(cbit.vcell.numericstest.QueryTestCriteriaCrossRefOP) MouseEvent(java.awt.event.MouseEvent) Hashtable(java.util.Hashtable) MouseAdapter(java.awt.event.MouseAdapter) TestCriteriaCrossRefOPResults(cbit.vcell.numericstest.TestCriteriaCrossRefOPResults) Dimension(java.awt.Dimension) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Date(java.util.Date) JPopupMenu(javax.swing.JPopupMenu) BigDecimal(java.math.BigDecimal) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException) CrossRefData(cbit.vcell.numericstest.TestCriteriaCrossRefOPResults.CrossRefData) JSortTable(org.vcell.util.gui.sorttable.JSortTable) ActionListener(java.awt.event.ActionListener) VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) ChangeTestCriteriaErrorLimitOP(cbit.vcell.numericstest.ChangeTestCriteriaErrorLimitOP) JTable(javax.swing.JTable) TestSuiteInfoNew(cbit.vcell.numericstest.TestSuiteInfoNew)

Aggregations

ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)35 ChildWindowManager (cbit.vcell.client.ChildWindowManager)14 Hashtable (java.util.Hashtable)10 Dimension (java.awt.Dimension)8 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)7 Vector (java.util.Vector)5 UserCancelException (org.vcell.util.UserCancelException)5 SimulationWindow (cbit.vcell.client.desktop.simulation.SimulationWindow)4 SinglePoint (cbit.vcell.geometry.SinglePoint)4 Simulation (cbit.vcell.solver.Simulation)4 Point (java.awt.Point)4 PlotPane (cbit.plot.gui.PlotPane)3 DataViewer (cbit.vcell.client.data.DataViewer)3 VariableType (cbit.vcell.math.VariableType)3 SpatialSelection (cbit.vcell.simdata.SpatialSelection)3 SpatialSelectionVolume (cbit.vcell.simdata.SpatialSelectionVolume)3 SimulationInfo (cbit.vcell.solver.SimulationInfo)3 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)3 PropertyVetoException (java.beans.PropertyVetoException)3 DataAccessException (org.vcell.util.DataAccessException)3