use of cbit.vcell.client.RequestManager in project vcell by virtualcell.
the class FieldDataGUIPanel method refreshMainNode.
private void refreshMainNode(final DefaultMutableTreeNode mainNode) {
final boolean isMainExpanded = getJTree1().isExpanded(new TreePath(mainNode.getPath()));
final boolean isVarExpanded = getJTree1().isExpanded(new TreePath(((DefaultMutableTreeNode) mainNode.getLastChild()).getPath()));
// Remove all children from Main node in a Tree safe way
DefaultMutableTreeNode root = (DefaultMutableTreeNode) getJTree1().getModel().getRoot();
int mainNodeIndex = ((DefaultTreeModel) getJTree1().getModel()).getIndexOfChild(root, mainNode);
((DefaultTreeModel) getJTree1().getModel()).removeNodeFromParent(mainNode);
mainNode.removeAllChildren();
final DefaultMutableTreeNode varNode = new DefaultMutableTreeNode(new FieldDataVarMainList());
mainNode.add(varNode);
((DefaultTreeModel) getJTree1().getModel()).insertNodeInto(mainNode, root, mainNodeIndex);
//
// Create thread-safe tasks to get Field Data Info and update JTree
//
final String FDOR_INFO = "FDOR_INFO";
final RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager();
AsynchClientTask FieldDataInfoTask = new AsynchClientTask("Gather Field Data info", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hash) throws Exception {
FieldDataMainList fieldDataMainList = (FieldDataMainList) mainNode.getUserObject();
final FieldDataFileOperationResults fieldDataFileOperationResults = clientRequestManager.getDocumentManager().fieldDataFileOperation(FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec(fieldDataMainList.externalDataIdentifier.getKey(), clientRequestManager.getDocumentManager().getUser(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT));
hash.put(FDOR_INFO, fieldDataFileOperationResults);
}
};
AsynchClientTask FieldDataInfoTreeUpdate = new AsynchClientTask("Update Field Data GUI", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hash) {
try {
FieldDataFileOperationResults fieldDataFileOperationResults = (FieldDataFileOperationResults) hash.get(FDOR_INFO);
Arrays.sort(fieldDataFileOperationResults.dataIdentifierArr, new Comparator<DataIdentifier>() {
public int compare(DataIdentifier o1, DataIdentifier o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
FieldDataMainList fieldDataMainList = (FieldDataMainList) mainNode.getUserObject();
final DefaultMutableTreeNode isizeNode = new DefaultMutableTreeNode(new FieldDataISizeList(fieldDataFileOperationResults.iSize));
final DefaultMutableTreeNode originNode = new DefaultMutableTreeNode(new FieldDataOriginList(fieldDataFileOperationResults.origin));
final DefaultMutableTreeNode extentNode = new DefaultMutableTreeNode(new FieldDataExtentList(fieldDataFileOperationResults.extent));
final DefaultMutableTreeNode timeNode = new DefaultMutableTreeNode(new FieldDataTimeList(fieldDataFileOperationResults.times));
final DefaultMutableTreeNode idNode = new DefaultMutableTreeNode(new FieldDataIDList(fieldDataMainList.externalDataIdentifier.getKey()));
((DefaultTreeModel) getJTree1().getModel()).insertNodeInto(isizeNode, mainNode, 0);
((DefaultTreeModel) getJTree1().getModel()).insertNodeInto(originNode, mainNode, 1);
((DefaultTreeModel) getJTree1().getModel()).insertNodeInto(extentNode, mainNode, 2);
((DefaultTreeModel) getJTree1().getModel()).insertNodeInto(timeNode, mainNode, 3);
((DefaultTreeModel) getJTree1().getModel()).insertNodeInto(idNode, mainNode, 4);
for (int i = 0; i < fieldDataFileOperationResults.dataIdentifierArr.length; i += 1) {
((DefaultTreeModel) getJTree1().getModel()).insertNodeInto(new DefaultMutableTreeNode(new FieldDataVarList(fieldDataFileOperationResults.dataIdentifierArr[i])), varNode, varNode.getChildCount());
}
if (isMainExpanded) {
getJTree1().expandPath(new TreePath(mainNode.getPath()));
}
if (isVarExpanded) {
getJTree1().expandPath(new TreePath(varNode.getPath()));
}
} catch (Throwable e) {
hash.put(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR, e);
}
}
};
//
// Execute Field Data Info - JTree tasks
//
AsynchClientTask[] tasks = new AsynchClientTask[] { FieldDataInfoTask, FieldDataInfoTreeUpdate };
Hashtable<String, Object> hash = new Hashtable<String, Object>();
ClientTaskDispatcher.dispatch(this, hash, tasks, false);
}
use of cbit.vcell.client.RequestManager in project vcell by virtualcell.
the class DisplayTimeSeriesOp method displayImageTimeSeries.
public void displayImageTimeSeries(final ImageTimeSeries<? extends Image> imageTimeSeries, final String title, final WindowListener windowListener) throws ImageException, IOException {
try {
System.out.println("starting to prepare data for time series viewing");
final PDEDataViewer pdeDataViewer = new PDEDataViewer();
DataSetControllerProvider dataSetControllerProvider;
try {
dataSetControllerProvider = getDataSetControllerProvider(imageTimeSeries, pdeDataViewer);
} catch (ImageException | IOException e1) {
e1.printStackTrace();
throw new RuntimeException(e1.getMessage(), e1);
}
VCDataManager vcDataManager = new VCDataManager(dataSetControllerProvider);
OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
final VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {
public User getOwner() {
return new User("nouser", null);
}
public KeyValue getDataKey() {
return null;
}
public String getID() {
return "mydata";
}
};
PDEDataManager pdeDataManager = new PDEDataManager(outputContext, vcDataManager, vcDataIdentifier);
final ClientPDEDataContext myPdeDataContext = new ClientPDEDataContext(pdeDataManager);
final RequestManager requestManager = new RequestManagerAdapter() {
};
final DataViewerManager dataViewerManager = new DataViewerManager() {
public void dataJobMessage(DataJobEvent event) {
}
public void exportMessage(ExportEvent event) {
}
public void addDataListener(DataListener newListener) {
}
public UserPreferences getUserPreferences() {
// getRequestManager().getUserPreferences();
return null;
}
public void removeDataListener(DataListener newListener) {
}
public void startExport(Component requester, OutputContext outputContext, ExportSpecs exportSpecs) {
// getLocalRequestManager().startExport(outputContext, FieldDataWindowManager.this, exportSpecs);
}
public void simStatusChanged(SimStatusEvent simStatusEvent) {
}
public User getUser() {
return new User("dummy", new KeyValue("123"));
// return getRequestManager().getDocumentManager().getUser();
}
public RequestManager getRequestManager() {
return requestManager;
}
};
System.out.println("ready to display time series");
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
JFrame jframe = new TopLevelFrame();
jframe.setTitle(title);
jframe.getContentPane().add(pdeDataViewer);
jframe.setSize(1000, 600);
jframe.setVisible(true);
if (windowListener != null) {
jframe.addWindowListener(windowListener);
}
try {
pdeDataViewer.setDataViewerManager(dataViewerManager);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
pdeDataViewer.setPdeDataContext(myPdeDataContext);
}
});
} catch (InvocationTargetException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of cbit.vcell.client.RequestManager in project vcell by virtualcell.
the class NetworkConstraintsPanel method createModel.
private void createModel() {
if (!checkBnglRequirements()) {
return;
}
DocumentWindow dw = (DocumentWindow) BeanUtils.findTypeParentOfComponent(this, DocumentWindow.class);
BioModelWindowManager bmwm = (BioModelWindowManager) (dw.getTopLevelWindowManager());
RequestManager rm = dw.getTopLevelWindowManager().getRequestManager();
rm.createBioModelFromApplication(bmwm, "Test", fieldSimulationContext);
}
use of cbit.vcell.client.RequestManager in project vcell by virtualcell.
the class SaveDocument method run.
/**
* Insert the method's description here.
* Creation date: (5/31/2004 6:04:14 PM)
* @param hashTable java.util.Hashtable
* @param clientWorker cbit.vcell.desktop.controls.ClientWorker
*/
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
long l1 = System.currentTimeMillis();
DocumentWindowManager documentWindowManager = (DocumentWindowManager) hashTable.get(CommonTask.DOCUMENT_WINDOW_MANAGER.name);
VCDocument currentDocument = documentWindowManager.getVCDocument();
DocumentManager documentManager = (DocumentManager) hashTable.get(CommonTask.DOCUMENT_MANAGER.name);
RequestManager requestManager = (RequestManager) hashTable.get("requestManager");
boolean bAsNew = hashTable.containsKey("newName");
String newName = bAsNew ? (String) hashTable.get("newName") : null;
Simulation[] simulationsToRun = (Simulation[]) hashTable.get("simulations");
String[] independentSims = null;
if (simulationsToRun != null && simulationsToRun.length > 0) {
independentSims = new String[simulationsToRun.length];
for (int i = 0; i < simulationsToRun.length; i++) {
independentSims[i] = simulationsToRun[i].getName();
}
}
VCDocument savedDocument = null;
switch(currentDocument.getDocumentType()) {
case BIOMODEL_DOC:
{
if (bAsNew) {
// Substitute Field Func Names-----
VersionableTypeVersion originalVersionableTypeVersion = null;
if (currentDocument.getVersion() != null) {
// From Opened...
originalVersionableTypeVersion = new VersionableTypeVersion(VersionableType.BioModelMetaData, currentDocument.getVersion());
}
documentManager.substituteFieldFuncNames((BioModel) currentDocument, originalVersionableTypeVersion);
// --------------------------------
savedDocument = documentManager.saveAsNew((BioModel) currentDocument, newName, independentSims);
} else {
savedDocument = documentManager.save((BioModel) currentDocument, independentSims);
}
break;
}
case MATHMODEL_DOC:
{
if (bAsNew) {
// Substitute Field Func Names-----
VersionableTypeVersion originalVersionableTypeVersion = ((MathModelWindowManager) documentWindowManager).getCopyFromBioModelAppVersionableTypeVersion();
if (originalVersionableTypeVersion == null && currentDocument.getVersion() != null) {
// From Opened...
originalVersionableTypeVersion = new VersionableTypeVersion(VersionableType.MathModelMetaData, currentDocument.getVersion());
}
documentManager.substituteFieldFuncNames((MathModel) currentDocument, originalVersionableTypeVersion);
// --------------------------------
savedDocument = documentManager.saveAsNew((MathModel) currentDocument, newName, independentSims);
} else {
savedDocument = documentManager.save((MathModel) currentDocument, independentSims);
}
break;
}
case GEOMETRY_DOC:
{
if (bAsNew) {
savedDocument = documentManager.saveAsNew((Geometry) currentDocument, newName);
} else {
savedDocument = documentManager.save((Geometry) currentDocument);
}
break;
}
default:
{
throw new RuntimeException("unexpected document type " + currentDocument.getDocumentType().name());
}
}
documentWindowManager.prepareDocumentToLoad(savedDocument, false);
hashTable.put(SaveDocument.DOC_KEY, savedDocument);
// generate PerformanceMonitorEvent
long l2 = System.currentTimeMillis();
double duration = ((double) (l2 - l1)) / 1000;
// requestManager.getAsynchMessageManager().reportPerformanceMonitorEvent(
// new PerformanceMonitorEvent(
// this, documentManager.getUser(), new PerformanceData(
// "SaveDocument.run()",
// MessageEvent.SAVING_STAT,
// new PerformanceDataEntry[] {
// new PerformanceDataEntry("document saved", savedDocument.getName()),
// new PerformanceDataEntry("remote call duration", Double.toString(duration))
// }
// )
// )
// );
}
use of cbit.vcell.client.RequestManager in project vcell by virtualcell.
the class FieldDataGUIPanel method addNewExternalData.
public static AsynchClientTask[] addNewExternalData(final Component requester, final FieldDataGUIPanel fieldDataGUIPanel, final boolean isFromSimulation) {
final RequestManager clientRequestManager = fieldDataGUIPanel.fieldDataWindowManager.getLocalRequestManager();
AsynchClientTask task1 = new AsynchClientTask("creating field data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec) hashTable.get("fdos");
String initialExtDataName = (String) hashTable.get("initFDName");
fdos.specEDI = null;
FieldDataInfoPanel fdip = new FieldDataInfoPanel();
fdip.setSimulationMode(isFromSimulation);
fdip.initISize(fdos.isize);
fdip.initIOrigin(fdos.origin);
fdip.initIExtent(fdos.extent);
fdip.initTimes(fdos.times);
fdip.initNames(TokenMangler.fixTokenStrict(initialExtDataName), fdos.varNames);
fdip.setAnnotation(fdos.annotation);
FieldDataFileOperationSpec userDefinedFDOS = new FieldDataFileOperationSpec();
while (true) {
int choice = PopupGenerator.showComponentOKCancelDialog(requester, fdip, "Create new field data");
if (choice == JOptionPane.OK_OPTION) {
// Check values
try {
userDefinedFDOS.extent = fdip.getExtent();
} catch (Exception e) {
PopupGenerator.showErrorDialog(requester, "Problem with Extent values. Please re-enter.\n" + e.getMessage() + "\nTry Again.", e);
continue;
}
try {
userDefinedFDOS.origin = fdip.getOrigin();
} catch (Exception e) {
PopupGenerator.showErrorDialog(requester, "Problem with Origin values. Please re-enter.\n" + e.getMessage() + "\nTry Again.", e);
continue;
}
try {
userDefinedFDOS.varNames = fdip.getVariableNames();
} catch (Exception e) {
PopupGenerator.showErrorDialog(requester, "Problem with Variable names. Please re-enter.\n" + e.getMessage() + "\nTry Again.", e);
continue;
}
userDefinedFDOS.annotation = fdip.getAnnotation();
userDefinedFDOS.times = fdip.getTimes();
try {
if (fdip.getFieldName() == null || fdip.getFieldName().length() == 0 || !fdip.getFieldName().equals(TokenMangler.fixTokenStrict(fdip.getFieldName()))) {
throw new Exception("Field Data names can contain only letters,digits and underscores");
}
// Check to see if this name is already used
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) fieldDataGUIPanel.getJTree1().getModel().getRoot();
for (int i = 0; i < rootNode.getChildCount(); i += 1) {
ExternalDataIdentifier extDataID = ((FieldDataMainList) ((DefaultMutableTreeNode) rootNode.getChildAt(i)).getUserObject()).externalDataIdentifier;
if (fdip.getFieldName().equals(extDataID.getName())) {
throw new Exception("New Field Data name " + fdip.getFieldName() + " already used.");
}
}
} catch (Exception e) {
PopupGenerator.showErrorDialog(requester, "Error saving Field Data Name to Database. Try again.\n" + e.getMessage(), e);
continue;
}
hashTable.put("userDefinedFDOS", userDefinedFDOS);
hashTable.put("fieldName", fdip.getFieldName());
break;
} else {
throw UserCancelException.CANCEL_GENERIC;
}
}
}
};
AsynchClientTask task2 = new AsynchClientTask("saving field data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// Add to Server Disk
// save Database
FieldDataFileOperationSpec tempFDOS = (FieldDataFileOperationSpec) hashTable.get("userDefinedFDOS");
String fieldName = (String) hashTable.get("fieldName");
FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec) hashTable.get("fdos");
DocumentManager documentManager = clientRequestManager.getDocumentManager();
FieldDataDBOperationSpec newExtDataIDSpec = FieldDataDBOperationSpec.createSaveNewExtDataIDSpec(documentManager.getUser(), fieldName, tempFDOS.annotation);
tempFDOS.specEDI = documentManager.fieldDataDBOperation(newExtDataIDSpec).extDataID;
fdos.specEDI = tempFDOS.specEDI;
fdos.annotation = tempFDOS.annotation;
try {
if (!isFromSimulation) {
fdos.extent = tempFDOS.extent;
fdos.origin = tempFDOS.origin;
fdos.varNames = tempFDOS.varNames;
fdos.times = tempFDOS.times;
//
// Subvolumes and Regions NOT implemented now
//
fdos.cartesianMesh = CartesianMesh.createSimpleCartesianMesh(fdos.origin, fdos.extent, fdos.isize, new RegionImage(new // empty regions
VCImageUncompressed(// empty regions
null, // empty regions
new byte[fdos.isize.getXYZ()], fdos.extent, fdos.isize.getX(), fdos.isize.getY(), fdos.isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
}
// Add to Server Disk
documentManager.fieldDataFileOperation(fdos);
} catch (Exception e) {
try {
// try to cleanup new ExtDataID
documentManager.fieldDataDBOperation(FieldDataDBOperationSpec.createDeleteExtDataIDSpec(fdos.specEDI));
} catch (Exception e2) {
// ignore
}
fdos.specEDI = null;
throw e;
}
}
};
AsynchClientTask task3 = new AsynchClientTask("refreshing field data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec) hashTable.get("fdos");
DefaultMutableTreeNode root = ((DefaultMutableTreeNode) fieldDataGUIPanel.getJTree1().getModel().getRoot());
if (root.getChildCount() == 0) {
fieldDataGUIPanel.updateJTree(clientRequestManager);
} else {
int alphabeticalIndex = -1;
for (int i = 0; i < root.getChildCount(); i += 1) {
if ((((FieldDataMainList) ((DefaultMutableTreeNode) root.getChildAt(i)).getUserObject())).externalDataIdentifier.getName().compareToIgnoreCase(fdos.specEDI.getName()) > 0) {
alphabeticalIndex = i;
break;
}
}
if (alphabeticalIndex == -1) {
alphabeticalIndex = root.getChildCount();
}
DefaultMutableTreeNode mainNode = new DefaultMutableTreeNode(new FieldDataMainList(fdos.specEDI, fdos.annotation));
mainNode.add(new DefaultMutableTreeNode(new FieldDataVarMainList()));
((DefaultTreeModel) fieldDataGUIPanel.getJTree1().getModel()).insertNodeInto(mainNode, root, alphabeticalIndex);
}
}
};
return new AsynchClientTask[] { task1, task2, task3 };
}
Aggregations