use of cbit.vcell.client.data.DataViewer 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;
}
use of cbit.vcell.client.data.DataViewer in project vcell by virtualcell.
the class TestingFrameworkWindowManager method viewResults.
/**
* Insert the method's description here.
* Creation date: (1/20/2003 11:52:18 AM)
* @return boolean
* @param mathDesc cbit.vcell.math.MathDescription
*/
public void viewResults(TestCriteriaNew testCriteria) {
VCDataIdentifier vcdID = new VCSimulationDataIdentifier(testCriteria.getSimInfo().getAuthoritativeVCSimulationIdentifier(), 0);
// get the data manager and wire it up
try (SuppressRemote sr = new VCellThreadChecker.SuppressRemote()) {
// okay to call remote from Swing for testing
Simulation sim = ((ClientDocumentManager) getRequestManager().getDocumentManager()).getSimulation(testCriteria.getSimInfo());
DataViewerController dataViewerCtr = getRequestManager().getDataViewerController(null, sim, 0);
addDataListener(dataViewerCtr);
// make the viewer
DataViewer viewer = dataViewerCtr.createViewer();
viewer.setDataViewerManager(this);
addExportListener(viewer);
// create the simCompareWindow - this is just a lightweight window to display the simResults.
// It was created originally to compare 2 sims, it can also be used here instead of creating the more heavy-weight SimWindow.
ChildWindowManager childWindowManager = TFWFinder.findChildWindowManager(getComponent());
ChildWindow childWindow = childWindowManager.addChildWindow(viewer, vcdID, "Comparing ... " + vcdID, true);
childWindow.setIsCenteredOnParent();
childWindow.pack();
childWindow.show();
} catch (Throwable e) {
PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, e.getMessage());
}
}
use of cbit.vcell.client.data.DataViewer in project vcell by virtualcell.
the class TestingFrameworkWindowManager method compare.
/**
* Insert the method's description here.
* Creation date: (1/20/2003 11:52:18 AM)
* @return boolean
* @param mathDesc cbit.vcell.math.MathDescription
*/
public void compare(final TestCriteriaNew testCriteria, final SimulationInfo userDefinedRegrSimInfo) {
final String KEY_MERGEDDATAINFO = "KEY_MERGEDDATAINFO";
final String KEY_MERGEDDATASETVIEWERCNTRLR = "KEY_MERGEDDATASETVIEWERCNTRLR";
AsynchClientTask gatherDataTask = new AsynchClientTask("Gathering compare Dta...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// create the merged data for the simulationInfo in testCriteria and the regression simInfo
SimulationInfo simInfo = testCriteria.getSimInfo();
SimulationInfo regrSimInfo = null;
if (userDefinedRegrSimInfo != null) {
regrSimInfo = userDefinedRegrSimInfo;
} else {
regrSimInfo = testCriteria.getRegressionSimInfo();
}
if (regrSimInfo == null) {
return;
}
VCDataIdentifier vcSimId1 = new VCSimulationDataIdentifier(simInfo.getAuthoritativeVCSimulationIdentifier(), 0);
VCDataIdentifier vcSimId2 = new VCSimulationDataIdentifier(regrSimInfo.getAuthoritativeVCSimulationIdentifier(), 0);
User user = simInfo.getOwner();
VCDataIdentifier[] vcIdentifierArray = new VCDataIdentifier[] { vcSimId2, vcSimId1 };
MergedDataInfo mergedDataInfo = new MergedDataInfo(user, vcIdentifierArray, MergedDataInfo.createDefaultPrefixNames(vcIdentifierArray.length));
hashTable.put(KEY_MERGEDDATAINFO, mergedDataInfo);
// get the data manager and wire it up
//
// get all "Data1.XXX" data identifiers ... and remove those which are functions
// add functions of the form DIFF_XXX = (Data1.XXX - Data2.XXX) for convenience in comparing results.
//
Simulation sim1 = ((ClientDocumentManager) getRequestManager().getDocumentManager()).getSimulation(simInfo);
Simulation sim2 = ((ClientDocumentManager) getRequestManager().getDocumentManager()).getSimulation(regrSimInfo);
boolean isSpatial = sim1.isSpatial();
if (sim2.isSpatial() != isSpatial) {
throw new RuntimeException("Cannot compare spatial and non-spatial data sets : " + simInfo + "& " + regrSimInfo);
}
DataManager mergedDataManager = getRequestManager().getDataManager(null, mergedDataInfo, isSpatial);
DataManager data1Manager = getRequestManager().getDataManager(null, vcSimId1, isSpatial);
DataManager data2Manager = getRequestManager().getDataManager(null, vcSimId2, isSpatial);
Vector<AnnotatedFunction> functionList = new Vector<AnnotatedFunction>();
AnnotatedFunction[] data1Functions = data1Manager.getFunctions();
AnnotatedFunction[] existingFunctions = mergedDataManager.getFunctions();
DataIdentifier[] data1Identifiers = data1Manager.getDataIdentifiers();
DataIdentifier[] data2Identifiers = data2Manager.getDataIdentifiers();
for (int i = 0; i < data1Identifiers.length; i++) {
//
// make sure dataIdentifier is not already a function
//
boolean bIsFunction = false;
for (int j = 0; j < data1Functions.length; j++) {
if (data1Identifiers[i].getName().equals(data1Functions[j].getName())) {
bIsFunction = true;
}
}
if (bIsFunction) {
continue;
}
//
// make sure corresponding identifier exists in "Data2"
//
boolean bIsInData2 = false;
for (int j = 0; j < data2Identifiers.length; j++) {
if (data2Identifiers[j].getName().equals(data1Identifiers[i].getName())) {
bIsInData2 = true;
}
}
if (!bIsInData2) {
continue;
}
//
// create "Diff" function
//
String data1Name = "Data1." + data1Identifiers[i].getName();
String data2Name = "Data2." + data1Identifiers[i].getName();
String functionName = "DIFF_" + data1Identifiers[i].getName();
VariableType varType = data1Identifiers[i].getVariableType();
Expression exp = new Expression(data1Name + "-" + data2Name);
AnnotatedFunction newFunction = new AnnotatedFunction(functionName, exp, data1Identifiers[i].getDomain(), "", varType, FunctionCategory.OUTPUTFUNCTION);
//
// make sure new "Diff" function isn't already in existing function list.
//
boolean bDiffFunctionAlreadyHere = false;
for (int j = 0; j < existingFunctions.length; j++) {
if (newFunction.getName().equals(existingFunctions[j].getName())) {
bDiffFunctionAlreadyHere = true;
}
}
if (bDiffFunctionAlreadyHere) {
continue;
}
functionList.add(newFunction);
}
OutputContext outputContext = null;
if (functionList.size() > 0) {
AnnotatedFunction[] newDiffFunctions = (AnnotatedFunction[]) BeanUtils.getArray(functionList, AnnotatedFunction.class);
outputContext = new OutputContext(newDiffFunctions);
}
MergedDatasetViewerController mergedDatasetViewerCtr = getRequestManager().getMergedDatasetViewerController(outputContext, mergedDataInfo, !isSpatial);
hashTable.put(KEY_MERGEDDATASETVIEWERCNTRLR, mergedDatasetViewerCtr);
}
};
AsynchClientTask showResultsTask = new AsynchClientTask("Showing Compare Results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// make the viewer
MergedDatasetViewerController mergedDatasetViewerCtr = (MergedDatasetViewerController) hashTable.get(KEY_MERGEDDATASETVIEWERCNTRLR);
addDataListener(mergedDatasetViewerCtr);
DataViewer viewer = mergedDatasetViewerCtr.createViewer();
viewer.setDataViewerManager(TestingFrameworkWindowManager.this);
addExportListener(viewer);
VCDataIdentifier vcDataIdentifier = (MergedDataInfo) hashTable.get(KEY_MERGEDDATAINFO);
ChildWindowManager childWindowManager = TFWFinder.findChildWindowManager(getComponent());
ChildWindow childWindow = childWindowManager.addChildWindow(viewer, vcDataIdentifier, "Comparing ... " + vcDataIdentifier.getID());
childWindow.pack();
// childWindow.setSize(450, 450);
childWindow.setIsCenteredOnParent();
childWindow.show();
}
};
ClientTaskDispatcher.dispatch(getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { gatherDataTask, showResultsTask }, false);
}
Aggregations