use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class TestingFrameworkPanel method selectInTreeView.
public void selectInTreeView(final BigDecimal testSuiteKey, final BigDecimal testCaseKey, final BigDecimal testCriteriaKey) {
new Thread(new Runnable() {
public void run() {
long WAIT_TIME_MILLISEC = 20000;
long startTime = System.currentTimeMillis();
boolean UPDATE_IN_PROGRESS = false;
do {
if ((System.currentTimeMillis() - startTime) >= WAIT_TIME_MILLISEC) {
return;
}
final BioModelNode testSuiteRootNode = TestingFrmwkTreeModel.getTestSuiteRoot((DefaultTreeModel) getJTree1().getModel());
for (int i = 0; i < testSuiteRootNode.getChildCount(); i++) {
final int finalI = i;
TestSuiteInfoNew tsInfo = (TestSuiteInfoNew) ((BioModelNode) testSuiteRootNode.getChildAt(i)).getUserObject();
if (tsInfo.getTSKey().equals(testSuiteKey)) {
if (testCaseKey != null) {
if (TestingFrameworkPanel.hasNullChild((BioModelNode) testSuiteRootNode.getChildAt(i))) {
if (UPDATE_IN_PROGRESS) {
break;
}
AsynchClientTask[] tasksArr = new AsynchClientTask[] { new TFUpdateRunningStatus(getTestingFrameworkWindowManager(), tsInfo), new TFRefresh(getTestingFrameworkWindowManager(), tsInfo) };
ClientTaskDispatcher.dispatch(TestingFrameworkPanel.this, new Hashtable<String, Object>(), tasksArr, true);
UPDATE_IN_PROGRESS = true;
break;
}
UPDATE_IN_PROGRESS = false;
for (int j = 0; j < testSuiteRootNode.getChildAt(i).getChildCount(); j++) {
final int finalJ = j;
TestCaseNew tcase = (TestCaseNew) ((BioModelNode) testSuiteRootNode.getChildAt(i).getChildAt(j)).getUserObject();
if (tcase.getTCKey().equals(testCaseKey)) {
if (testCriteriaKey != null) {
for (int k = 0; k < testSuiteRootNode.getChildAt(i).getChildAt(j).getChildCount(); k++) {
final int finalK = k;
TestCriteriaNew tcrit = (TestCriteriaNew) ((BioModelNode) testSuiteRootNode.getChildAt(i).getChildAt(j).getChildAt(k)).getUserObject();
if (tcrit.getTCritKey().equals(testCriteriaKey)) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
TreePath treePath = new TreePath(((DefaultTreeModel) getJTree1().getModel()).getPathToRoot(testSuiteRootNode.getChildAt(finalI).getChildAt(finalJ).getChildAt(finalK)));
getJTree1().setSelectionPath(treePath);
getJTree1().scrollPathToVisible(treePath);
}
});
break;
}
}
;
} else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
TreePath treePath = new TreePath(((DefaultTreeModel) getJTree1().getModel()).getPathToRoot(testSuiteRootNode.getChildAt(finalI).getChildAt(finalJ)));
getJTree1().setSelectionPath(treePath);
getJTree1().scrollPathToVisible(treePath);
}
});
break;
}
}
}
} else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
TreePath treePath = new TreePath(((DefaultTreeModel) getJTree1().getModel()).getPathToRoot(testSuiteRootNode.getChildAt(finalI)));
getJTree1().setSelectionPath(treePath);
getJTree1().scrollPathToVisible(treePath);
}
});
break;
}
}
}
} while (UPDATE_IN_PROGRESS);
}
}).start();
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class VCDocumentDbTreePanel method search.
public void search(final boolean bShowAll) {
final Object[] status = new Object[] { null };
class SearchCancel implements ProgressDialogListener {
public void cancelButton_actionPerformed(EventObject newEvent) {
status[0] = UserCancelException.CANCEL_GENERIC;
}
}
final SearchCancel searchCancel = new SearchCancel();
final ArrayList<SearchCriterion> searchCriterionListFinal = new ArrayList<DatabaseSearchPanel.SearchCriterion>();
AsynchClientTask searchCriteriaTask = new AsynchClientTask("Creating search criteria...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING, true) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (bShowAll) {
return;
}
new Thread(new Runnable() {
public void run() {
try {
ArrayList<SearchCriterion> searchCriterionList = getDatabaseSearchPanel().getSearchCriterionList(getDocumentManager());
if (status[0] == null) {
// update status only if no one else has
if (searchCriterionList != null && searchCriterionList.size() > 0) {
searchCriterionListFinal.addAll(searchCriterionList);
}
status[0] = "OK";
return;
} else {
return;
}
} catch (Exception e) {
status[0] = e;
}
}
}).start();
long startTime = System.currentTimeMillis();
while ((System.currentTimeMillis() - startTime) < 60000) {
if (status[0] != null) {
if (status[0] instanceof Exception) {
// User cancelled or there was an exception in search criteria thread
throw (Exception) status[0];
}
// search criteria thread completed with 'OK'
return;
}
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
// ignore
}
}
throw new Exception("getSearchCriterionList timed out");
}
};
AsynchClientTask refreshTask = new AsynchClientTask("Refreshing tree...", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (searchCriterionListFinal.size() > 0) {
// show with search criteria
refresh(searchCriterionListFinal);
} else {
// show all
refresh(null);
}
}
};
Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
if (!bShowAll && getDatabaseSearchPanel().hasRemoteDatabaseSearchDefined()) {
ClientTaskDispatcher.dispatch(this, hashTable, new AsynchClientTask[] { searchCriteriaTask, refreshTask }, true, false, true, searchCancel, true);
} else {
try {
searchCriteriaTask.run(hashTable);
refreshTask.run(hashTable);
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(this, e.getMessage());
}
}
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class FieldDataGUIPanel method getJButtonCreateGeom.
/**
* This method initializes jButtonCopyInfo
*
* @return javax.swing.JButton
*/
private JButton getJButtonCreateGeom() {
if (jButtonCreateGeom == null) {
jButtonCreateGeom = new JButton();
jButtonCreateGeom.setEnabled(false);
jButtonCreateGeom.setText("Create Geom");
jButtonCreateGeom.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager();
javax.swing.tree.TreePath selPath = getJTree1().getSelectionPath();
javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode) selPath.getLastPathComponent();
if (lastPathComponent.getUserObject() instanceof FieldDataVarList) {
DataIdentifier dataIdentifier = ((FieldDataVarList) lastPathComponent.getUserObject()).dataIdentifier;
TreePath ppPath = selPath.getParentPath().getParentPath();
javax.swing.tree.DefaultMutableTreeNode ppLastPathComp = (javax.swing.tree.DefaultMutableTreeNode) ppPath.getLastPathComponent();
if (ppLastPathComp.getUserObject() instanceof FieldDataMainList) {
ExternalDataIdentifier extDataID = ((FieldDataMainList) ppLastPathComp.getUserObject()).externalDataIdentifier;
final OpenModelInfoHolder openModelInfoHolder = FieldDataWindowManager.selectOpenModelsFromDesktop(FieldDataGUIPanel.this, fieldDataWindowManager.getRequestManager(), false, "Select BioModel or MathModel to receive new geometry", false);
if (openModelInfoHolder == null) {
DialogUtils.showErrorDialog(FieldDataGUIPanel.this, "Before proceeding, please open a Biomodel application or Mathmodel you wish to apply a new Field Data Geometry to");
return;
}
AsynchClientTask applyGeomTask = new AsynchClientTask("apply geometry", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Geometry newGeom = (Geometry) hashTable.get("doc");
final String OK_OPTION = "Ok";
if (openModelInfoHolder instanceof FDSimMathModelInfo) {
Version version = ((FDSimMathModelInfo) openModelInfoHolder).getMathModelVersion();
String modelName = (version == null ? "NoName" : version.getName());
if (newGeom.getName() == null) {
newGeom.setName(modelName + "_" + BeanUtils.generateDateTimeString());
}
String message = "Confirm Setting new FieldData derived geometry on MathModel '" + modelName + "'";
if (DialogUtils.showWarningDialog(FieldDataGUIPanel.this, message, new String[] { OK_OPTION, "Cancel" }, OK_OPTION).equals(OK_OPTION)) {
((FDSimMathModelInfo) openModelInfoHolder).getMathDescription().setGeometry(newGeom);
}
} else if (openModelInfoHolder instanceof FDSimBioModelInfo) {
Version version = ((FDSimBioModelInfo) openModelInfoHolder).getBioModelVersion();
String modelName = (version == null ? "NoName" : version.getName());
String simContextName = ((FDSimBioModelInfo) openModelInfoHolder).getSimulationContext().getName();
if (newGeom.getName() == null) {
newGeom.setName(modelName + "_" + simContextName + "_" + BeanUtils.generateDateTimeString());
}
String message = "Confirm Setting new FieldData derived geometry on BioModel '" + modelName + "' , Application '" + simContextName + "'";
if (DialogUtils.showWarningDialog(FieldDataGUIPanel.this, message, new String[] { OK_OPTION, "Cancel" }, OK_OPTION).equals(OK_OPTION)) {
((FDSimBioModelInfo) openModelInfoHolder).getSimulationContext().setGeometry(newGeom);
}
}
}
};
VCDocument.GeomFromFieldDataCreationInfo geomFromFieldDataCreationInfo = new VCDocument.GeomFromFieldDataCreationInfo(extDataID, dataIdentifier.getName());
AsynchClientTask[] createGeomTask = clientRequestManager.createNewGeometryTasks(fieldDataWindowManager, geomFromFieldDataCreationInfo, new AsynchClientTask[] { applyGeomTask }, "Apply Geometry");
Hashtable<String, Object> hash = new Hashtable<String, Object>();
hash.put(ClientRequestManager.GUI_PARENT, fieldDataWindowManager.getComponent());
ClientTaskDispatcher.dispatch(FieldDataGUIPanel.this, hash, createGeomTask, false, false, null, true);
}
}
} catch (UserCancelException e1) {
// ignore
} catch (Exception e1) {
e1.printStackTrace();
DialogUtils.showErrorDialog(FieldDataGUIPanel.this, e1.getMessage());
}
// jButtonFDCopyRef_ActionPerformed(e);
// fieldDataWindowManager.newDocument(VCDocument.GEOMETRY_DOC, option);
// copyMethod(COPY_CRNL);
// // javax.swing.tree.TreePath selPath = getJTree1().getSelectionPath();
// // if(selPath != null){
// // javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode)selPath.getLastPathComponent();
// // copyMethod(lastPathComponent, copyMode);
// // }
// // String copyString = "";
// // javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode)selPath.getLastPathComponent();
// // if(lastPathComponent.equals(getJTree1().getModel().getRoot())){
// // int childCount = lastPathComponent.getChildCount();
// // for(int i=0;i<childCount;i+= 1){
// // if(i != 0){
// // copyString+="\n";
// // }
// // copyString+=
// // ((FieldDataMainList)((DefaultMutableTreeNode)lastPathComponent.getChildAt(i)).getUserObject()).externalDataIdentifier.getName();
// // }
// // }else if(lastPathComponent.getUserObject() instanceof FieldDataOriginList){
// // Origin origin = ((FieldDataOriginList)lastPathComponent.getUserObject()).origin;
// // copyString = origin.getX()+","+origin.getY()+","+origin.getZ();
// // }else if(lastPathComponent.getUserObject() instanceof FieldDataExtentList){
// // Extent extent = ((FieldDataExtentList)lastPathComponent.getUserObject()).extent;
// // copyString = extent.getX()+","+extent.getY()+","+extent.getZ();
// // }else if(lastPathComponent.getUserObject() instanceof FieldDataISizeList){
// // ISize isize = ((FieldDataISizeList)lastPathComponent.getUserObject()).isize;
// // copyString = isize.getX()+","+isize.getY()+","+isize.getZ();
// // }else if(lastPathComponent.getUserObject() instanceof FieldDataTimeList){
// // double[] times = ((FieldDataTimeList)lastPathComponent.getUserObject()).times;
// // for(int i=0;i<times.length;i+= 1){
// // if(i != 0){
// // copyString+="\n";
// // }
// // copyString+= times[i]+"";
// // }
// // }else if(lastPathComponent.getUserObject() instanceof FieldDataMainList){
// // ExternalDataIdentifier extDataID =
// // ((FieldDataMainList)lastPathComponent.getUserObject()).externalDataIdentifier;
// // copyString = extDataID.getName();
// // }else if(lastPathComponent.getUserObject() instanceof FieldDataVarList){
// // DataIdentifier dataIdentifier =
// // ((FieldDataVarList)lastPathComponent.getUserObject()).dataIdentifier;
// // copyString = dataIdentifier.getName();
// // }else if(lastPathComponent.getUserObject() instanceof FieldDataVarMainList){
// // int childCount = lastPathComponent.getChildCount();
// // for(int i=0;i<childCount;i+= 1){
// // if(i != 0){
// // copyString+="\n";
// // }
// // copyString+=
// // ((FieldDataVarList)((DefaultMutableTreeNode)lastPathComponent.getChildAt(i)).getUserObject()).dataIdentifier.getName();
// // }
// // }
// // if(copyString.length() > 0 ){
// // VCellTransferable.sendToClipboard(copyString);
// // }
// // }
}
});
}
return jButtonCreateGeom;
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class FieldDataGUIPanel method jButtonFDFromSim_ActionPerformed.
private void jButtonFDFromSim_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
try {
final RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager();
final FieldDataWindowManager.OpenModelInfoHolder simInfoHolder = FieldDataWindowManager.selectOpenModelsFromDesktop(this, fieldDataWindowManager.getRequestManager(), true, "Select Simulation for Field Data", true);
if (simInfoHolder == null) {
PopupGenerator.showErrorDialog(this, "Please open a Bio or Math model containing the spatial (non-compartmental) simulation you wish to use to create a new Field Data");
return;
}
// Check that the sim is in a state that can be copied
final SimulationInfo simInfo = simInfoHolder.getSimInfo();
if (simInfo == null) {
throw new Exception("Selected sim '" + simInfoHolder.getSimName() + "' has no simInfo (save your model and retry).");
}
SimulationStatus simStatus = clientRequestManager.getServerSimulationStatus(simInfo);
if (simStatus != null && (simStatus.isRunning() || simStatus.isStartRequested())) {
throw new Exception("Can't copy 'running' simulation data from sim '" + simInfo.getName() + "'");
}
final FieldDataFileOperationSpec fdos = FieldDataFileOperationSpec.createCopySimFieldDataFileOperationSpec(null, (simInfo.getParentSimulationReference() != null ? simInfo.getParentSimulationReference() : simInfo.getSimulationVersion().getVersionKey()), simInfo.getOwner(), simInfoHolder.getJobIndex(), clientRequestManager.getDocumentManager().getUser());
AsynchClientTask[] addTasks = addNewExternalData(this, this, true);
AsynchClientTask[] taskArray = new AsynchClientTask[1 + addTasks.length];
// add to the end
System.arraycopy(addTasks, 0, taskArray, 1, addTasks.length);
taskArray[0] = new AsynchClientTask("Create Field Data from Simulation", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FieldDataFileOperationResults fdor = clientRequestManager.getDocumentManager().fieldDataFileOperation(FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec((simInfo.getParentSimulationReference() != null ? simInfo.getParentSimulationReference() : simInfo.getSimulationVersion().getVersionKey()), simInfo.getOwner(), simInfoHolder.getJobIndex()));
// Create (non-editable) info for display
fdos.origin = fdor.origin;
fdos.extent = fdor.extent;
fdos.isize = fdor.iSize;
fdos.times = fdor.times;
fdos.varNames = new String[fdor.dataIdentifierArr.length];
for (int i = 0; i < fdor.dataIdentifierArr.length; i += 1) {
fdos.varNames[i] = (fdor.dataIdentifierArr[i].getVariableType().equals(VariableType.VOLUME) ? "(vol) " : "") + (fdor.dataIdentifierArr[i].getVariableType().equals(VariableType.MEMBRANE) ? "(mbr) " : "") + fdor.dataIdentifierArr[i].getName();
}
hashTable.put("fdos", fdos);
hashTable.put("initFDName", simInfo.getName());
// addNewExternalData(clientRequestManager, fdos, simInfoHolder.simInfo.getName(), true);
}
};
Hashtable<String, Object> hash = new Hashtable<String, Object>();
ClientTaskDispatcher.dispatch(this, hash, taskArray, false);
} catch (UserCancelException e) {
return;
} catch (Exception e) {
PopupGenerator.showErrorDialog(this, "Error creating Field Data from simulation\n" + e.getMessage(), e);
}
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class FieldDataGUIPanel method jButtonFDDelete_ActionPerformed.
private void jButtonFDDelete_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
final RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager();
TreePath selPath = getJTree1().getSelectionPath();
final DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode) selPath.getLastPathComponent();
final FieldDataMainList fieldDataMainList = (FieldDataMainList) mainNode.getUserObject();
if (!fieldDataMainList.externalDataIdentifier.getOwner().equals(clientRequestManager.getDocumentManager().getUser())) {
DialogUtils.showErrorDialog(this, "Delete failed: User " + clientRequestManager.getDocumentManager().getUser().getName() + "does not own FieldData '" + fieldDataMainList.externalDataIdentifier.getName() + "'");
}
if (PopupGenerator.showComponentOKCancelDialog(this, new JLabel("Delete " + fieldDataMainList.externalDataIdentifier.getName() + "?"), "Confirm Delete") != JOptionPane.OK_OPTION) {
return;
}
AsynchClientTask CheckRemoveFromDBTask = new AsynchClientTask("Check Field Data references in DB", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hash) throws Exception {
if (fieldDataWindowManager.findReferencingModels(fieldDataMainList.externalDataIdentifier, false)) {
throw new Exception("Cannot delete Field Data '" + fieldDataMainList.externalDataIdentifier.getName() + "' because it is referenced in a Model(s) or Function(s) file.");
}
}
};
AsynchClientTask RemoveNodeTreeTask = new AsynchClientTask("Remove FieldData tree node", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hash) throws Exception {
((DefaultTreeModel) getJTree1().getModel()).removeNodeFromParent(mainNode);
if (((DefaultMutableTreeNode) getJTree1().getModel().getRoot()).getChildCount() == 0) {
updateJTree(clientRequestManager);
}
}
};
AsynchClientTask RemoveFromDiskAndDBTask = new AsynchClientTask("Remove Field Data from Disk and DB", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hash) throws Exception {
// Remove from Disk
FieldDataMainList fieldDataMainList = (FieldDataMainList) mainNode.getUserObject();
FieldDataFileOperationSpec fdos = FieldDataFileOperationSpec.createDeleteFieldDataFileOperationSpec(fieldDataMainList.externalDataIdentifier);
clientRequestManager.getDocumentManager().fieldDataFileOperation(fdos);
// Remove from DB
fieldDataWindowManager.deleteExternalDataIdentifier(fieldDataMainList.externalDataIdentifier);
}
};
//
// Execute Field Data Info - JTree tasks
//
AsynchClientTask[] tasks = new AsynchClientTask[] { CheckRemoveFromDBTask, RemoveFromDiskAndDBTask, RemoveNodeTreeTask };
Hashtable<String, Object> hash = new Hashtable<String, Object>();
ClientTaskDispatcher.dispatch(this, hash, tasks, false);
}
Aggregations