use of org.vcell.util.document.ExternalDataIdentifier in project vcell by virtualcell.
the class FieldDataGUIPanel method copyMethod.
private void copyMethod(int copyMode) {
String delimiter = "";
if (copyMode == COPY_NL) {
delimiter = "\n";
} else if (copyMode == COPY_CRNL) {
delimiter = "\r\n";
} else if (copyMode == COPY_CSV) {
delimiter = ",";
} else if (copyMode == COPY_SPACE) {
delimiter = " ";
}
String copyString = "";
javax.swing.tree.TreePath selPath = getJTree1().getSelectionPath();
if (selPath != null) {
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 += delimiter;
}
copyString += ((FieldDataMainList) ((DefaultMutableTreeNode) lastPathComponent.getChildAt(i)).getUserObject()).externalDataIdentifier.getName();
}
} else if (lastPathComponent.getUserObject() instanceof FieldDataOriginList) {
Origin origin = ((FieldDataOriginList) lastPathComponent.getUserObject()).origin;
copyString = origin.getX() + delimiter + origin.getY() + delimiter + origin.getZ();
} else if (lastPathComponent.getUserObject() instanceof FieldDataExtentList) {
Extent extent = ((FieldDataExtentList) lastPathComponent.getUserObject()).extent;
copyString = extent.getX() + delimiter + extent.getY() + delimiter + extent.getZ();
} else if (lastPathComponent.getUserObject() instanceof FieldDataISizeList) {
ISize isize = ((FieldDataISizeList) lastPathComponent.getUserObject()).isize;
copyString = isize.getX() + delimiter + isize.getY() + delimiter + 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 += delimiter;
}
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 += delimiter;
}
copyString += ((FieldDataVarList) ((DefaultMutableTreeNode) lastPathComponent.getChildAt(i)).getUserObject()).dataIdentifier.getName();
}
}
if (copyString.length() > 0) {
VCellTransferable.sendToClipboard(copyString);
}
}
}
use of org.vcell.util.document.ExternalDataIdentifier 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 };
}
use of org.vcell.util.document.ExternalDataIdentifier in project vcell by virtualcell.
the class FieldDataGUIPanel method updateJTree.
public void updateJTree(final RequestManager clientRequestManager) {
if (clientRequestManager == null) {
DefaultMutableTreeNode emptyNode = new DefaultMutableTreeNode("No Info Available");
getJTree1().setModel(new DefaultTreeModel(emptyNode));
} else {
DefaultMutableTreeNode startupNode = new DefaultMutableTreeNode("Gathering Field Data Information... (Please wait)");
getJTree1().setModel(new DefaultTreeModel(startupNode));
AsynchClientTask gatherInfo = new AsynchClientTask("gatherInfo", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
try {
DocumentManager documentManager = clientRequestManager.getDocumentManager();
FieldDataDBOperationSpec fdos = FieldDataDBOperationSpec.createGetExtDataIDsSpec(documentManager.getUser());
FieldDataDBOperationResults fieldDataDBOperationResults = documentManager.fieldDataDBOperation(fdos);
ExternalDataIdentifier[] externalDataIdentifierArr = fieldDataDBOperationResults.extDataIDArr;
String[] extDataAnnotArr = fieldDataDBOperationResults.extDataAnnotArr;
TreeMap<ExternalDataIdentifier, String> sortedExtDataIDTreeMap = new TreeMap<ExternalDataIdentifier, String>(new Comparator<ExternalDataIdentifier>() {
public int compare(ExternalDataIdentifier o1, ExternalDataIdentifier o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
for (int i = 0; i < externalDataIdentifierArr.length; i += 1) {
sortedExtDataIDTreeMap.put(externalDataIdentifierArr[i], extDataAnnotArr[i]);
}
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(new InitializedRootNode("Field Data Info" + (externalDataIdentifierArr.length == 0 ? " (None Defined)" : "")));
Iterator<Entry<ExternalDataIdentifier, String>> sortIter = sortedExtDataIDTreeMap.entrySet().iterator();
while (sortIter.hasNext()) {
Entry<ExternalDataIdentifier, String> entry = sortIter.next();
DefaultMutableTreeNode mainNode = new DefaultMutableTreeNode(new FieldDataMainList(entry.getKey(), entry.getValue()));
mainNode.add(new DefaultMutableTreeNode(new FieldDataVarMainList()));
rootNode.add(mainNode);
}
hashTable.put("rootNode", rootNode);
} catch (Exception e) {
DefaultMutableTreeNode errorNode = new DefaultMutableTreeNode("Error Getting Field Data Information");
hashTable.put("rootNode", errorNode);
throw e;
}
}
};
AsynchClientTask updateTree = new AsynchClientTask("updateTree", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) hashTable.get("rootNode");
getJTree1().setModel(new DefaultTreeModel(rootNode));
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { gatherInfo, updateTree });
}
}
use of org.vcell.util.document.ExternalDataIdentifier in project vcell by virtualcell.
the class VFrapXmlHelper method VFRAPToBioModel.
public static BioModel VFRAPToBioModel(Hashtable<String, Object> hashTable, XMLSource xmlSource, DocumentManager documentManager, final TopLevelWindowManager requester) throws XmlParseException, IOException, DataAccessException, MathException, DivideByZeroException, ExpressionException, ImageException, UtilCancelException {
Component requesterComponent = requester.getComponent();
File vFrapFile = xmlSource.getXmlFile();
// ---
// ex ccc8.vfrap
String vFrapFileNameExtended = vFrapFile.getName();
{
// we want to make sure to reload these strings from the hash later on
String initialFieldDataName = vFrapFileNameExtended.substring(0, vFrapFileNameExtended.indexOf(".vfrap"));
// we'll save here the "special" vFrap images (prebleach_avg, ...)
String mixedFieldDataName = initialFieldDataName + "Mx";
hashTable.put("mixedFieldDataName", mixedFieldDataName);
hashTable.put("initialFieldDataName", initialFieldDataName);
}
if (vFrapFileNameExtended.indexOf(".vfrap") < 0) {
throw new RuntimeException("File extension must be .vfrap");
}
// VFrapXmlHelper vFrapXmlHelper = new VFrapXmlHelper();
checkNameAvailability(hashTable, true, documentManager, requesterComponent);
System.out.println("Loading " + vFrapFileNameExtended + " ...");
String xmlString = XmlUtil.getXMLString(vFrapFile.getAbsolutePath());
MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
Element vFrapRoot = XmlUtil.stringToXML(xmlString, null).getRootElement();
// ----- read the biomodel from Virtual FRAP xml file ----------
BioModel bioModel = null;
XmlReader vcellXMLReader = new XmlReader(true);
Element bioModelElement = vFrapRoot.getChild(XMLTags.BioModelTag);
if (bioModelElement == null) {
throw new RuntimeException("Unable to load biomodel.");
}
String docSoftwareVersion = vFrapRoot.getAttributeValue(XMLTags.SoftwareVersionAttrTag);
bioModel = vcellXMLReader.getBioModel(bioModelElement, (docSoftwareVersion == null ? null : VCellSoftwareVersion.fromString(docSoftwareVersion)));
// ------ locate the special images within the vFrap files and load them in memory
if (!LoadVFrapSpecialImages(hashTable, vFrapRoot)) {
// just return the biomodel if image loading fails for some reason
return bioModel;
}
// ------- save the special images in the database as field data ------------
ExternalDataIdentifier vfrapMisc = SaveVFrapSpecialImagesAsFieldData(hashTable, documentManager);
// ------- create and save data symbols for the vFrap "special" images -----------
CreateSaveVFrapDataSymbols(hashTable, bioModel, vfrapMisc);
// -------- replace vFrap default names in field function arguments with data symbol names -----
ReplaceVFrapNamesWithSymbolNames(bioModel);
return bioModel;
}
use of org.vcell.util.document.ExternalDataIdentifier in project vcell by virtualcell.
the class VFrapXmlHelper method isAlreadyImported.
// double[] firstPostBleach = null;
// double[] prebleachAvg = null;
// BufferedImage[] roiComposite = null;
//
// public double[] getFirstPostBleach() {
// if(firstPostBleach == null) {
// throw new RuntimeException("Missing vFrap FirstPostbleach Image");
// } else {
// return firstPostBleach;
// }
// }
// public double[] getPrebleachAvg() {
// if(prebleachAvg == null) {
// throw new RuntimeException("Missing vFrap PrebleachAverage Image");
// } else {
// return prebleachAvg;
// }
// }
// public BufferedImage[] getRoiComposite() {
// if(roiComposite == null) {
// throw new RuntimeException("Missing vFrap RoiComposite Image");
// } else {
// return roiComposite;
// }
// }
public static boolean isAlreadyImported(String candidateName, DocumentManager documentManager) throws DataAccessException {
FieldDataDBOperationSpec fdos = FieldDataDBOperationSpec.createGetExtDataIDsSpec(documentManager.getUser());
FieldDataDBOperationResults fieldDataDBOperationResults = documentManager.fieldDataDBOperation(fdos);
ExternalDataIdentifier[] externalDataIdentifierArr = fieldDataDBOperationResults.extDataIDArr;
for (ExternalDataIdentifier edi : externalDataIdentifierArr) {
if (candidateName.equals(edi.getName())) {
return true;
}
}
return false;
}
Aggregations