use of cbit.vcell.client.TopLevelWindowManager in project vcell by virtualcell.
the class ChooseFile method showMathModelXMLFileChooser.
/**
* 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
*/
private File showMathModelXMLFileChooser(Hashtable<String, Object> hashTable) throws java.lang.Exception {
// for mathmodels:
MathModel mathModel = (MathModel) hashTable.get("documentToExport");
JFrame currentWindow = (JFrame) hashTable.get("currentWindow");
UserPreferences userPreferences = (UserPreferences) hashTable.get("userPreferences");
TopLevelWindowManager topLevelWindowManager = (TopLevelWindowManager) hashTable.get("topLevelWindowManager");
if (topLevelWindowManager == null) {
throw new RuntimeException("toplLevelWindowManager required");
}
File defaultPath = userPreferences.getCurrentDialogPath();
VCFileChooser fileChooser = new VCFileChooser(defaultPath);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
// fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_21); // Can export Mathmodel to L2V1 ??
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_23);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_24);
// fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_CELLML);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_MATLABV6);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_PDF);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SMOLDYN_INPUT);
// remove all selector
fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
// set the default file filter...
fileChooser.setFileFilter(FileFilters.FILE_FILTER_VCML);
fileChooser.setSelectedFile(new java.io.File(TokenMangler.fixTokenStrict(mathModel.getName())));
fileChooser.setDialogTitle("Export Virtual Cell MathModel As...");
if (fileChooser.showSaveDialog(currentWindow) != JFileChooser.APPROVE_OPTION) {
// user didn't choose save
throw UserCancelException.CANCEL_FILE_SELECTION;
} else {
File selectedFile = fileChooser.getSelectedFile();
javax.swing.filechooser.FileFilter fileFilter = fileChooser.getFileFilter();
if (selectedFile == null) {
// no file selected (no name given)
throw UserCancelException.CANCEL_FILE_SELECTION;
} else {
// /
String selectedFileName = recordAndRemoveExtension(selectedFile.getPath());
String n = selectedFile.getPath().toLowerCase();
if (fileFilter == FileFilters.FILE_FILTER_CELLML && !n.endsWith(".xml")) {
selectedFile = new File(selectedFileName + ".xml");
} else if (fileFilter == FileFilters.FILE_FILTER_VCML && !n.endsWith(".vcml")) {
selectedFile = new File(selectedFileName + ".vcml");
} else if ((fileFilter == FileFilters.FILE_FILTER_SBML_23 || (fileFilter == FileFilters.FILE_FILTER_SBML_24)) && !n.endsWith(".xml")) {
selectedFile = new File(selectedFileName + ".xml");
} else if (fileFilter == FileFilters.FILE_FILTER_MATLABV6 && !n.endsWith(".m")) {
selectedFile = new File(selectedFileName + ".m");
} else if (fileFilter == FileFilters.FILE_FILTER_PDF && !n.endsWith(".pdf")) {
selectedFile = new File(selectedFileName + ".pdf");
} else if (fileFilter == FileFilters.FILE_FILTER_SMOLDYN_INPUT && !(n.endsWith(SMOLDYN_INPUT_FILE_EXTENSION) || (n.endsWith(".txt")))) {
selectedFile = new File(selectedFileName + SMOLDYN_INPUT_FILE_EXTENSION);
}
checkForOverwrites(selectedFile, topLevelWindowManager.getComponent(), userPreferences);
// put the filter in the hash so the export task knows what to do...
hashTable.put("fileFilter", fileFilter);
// only non-spatial math models can be exported to CellML.
if (fileFilter == FileFilters.FILE_FILTER_CELLML && mathModel.getMathDescription().getGeometry().getDimension() != 0) {
throw new Exception("No non-spatial applications, can only export to this format the math from a non-spatial application");
} else // Select a spatial stochastic simulation to export
if (fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SMOLDYN_INPUT.getDescription())) {
Simulation[] sims = mathModel.getSimulations();
if (sims == null || sims.length == 0) {
DialogUtils.showWarningDialog(topLevelWindowManager.getComponent(), "MathModel '" + mathModel.getName() + "' has no simulations to export");
throw UserCancelException.CANCEL_GENERIC;
}
String[][] rowData = new String[sims.length][2];
for (int i = 0; i < sims.length; i++) {
rowData[i][0] = sims[i].getName();
rowData[i][1] = sims[i].getSolverTaskDescription().getSolverDescription().getDisplayLabel();
}
int[] selectedRow = PopupGenerator.showComponentOKCancelTableList(topLevelWindowManager.getComponent(), "Select a simulation to export", new String[] { "Simulation Name", "Solver" }, rowData, ListSelectionModel.SINGLE_SELECTION);
if (selectedRow == null) {
throw UserCancelException.CANCEL_GENERIC;
}
String chosenSimulationName = rowData[selectedRow[0]][0];
Simulation chosenSimulation = mathModel.getSimulation(chosenSimulationName);
if (chosenSimulation != null) {
hashTable.put("selectedSimulation", chosenSimulation);
} else {
throw new Exception("Couldn't match selection '" + chosenSimulationName + "' with simulation");
}
}
resetPreferredFilePath(selectedFile, userPreferences);
return selectedFile;
}
}
}
use of cbit.vcell.client.TopLevelWindowManager in project vcell by virtualcell.
the class DocumentToExport 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
*/
@Override
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
TopLevelWindowManager topLevelWindowManager = extractRequired(hashTable, TopLevelWindowManager.class, "topLevelWindowManager");
VCDocument doc = null;
if (topLevelWindowManager instanceof DocumentWindowManager) {
doc = ((DocumentWindowManager) topLevelWindowManager).getVCDocument();
} else if (topLevelWindowManager instanceof DatabaseWindowManager) {
DocumentManager documentManager = extractRequired(hashTable, DocumentManager.class, CommonTask.DOCUMENT_MANAGER.name);
VCDocumentInfo documentInfo = ((DatabaseWindowManager) topLevelWindowManager).getPanelSelection();
if (documentInfo instanceof BioModelInfo) {
BioModelInfo bmi = (BioModelInfo) documentInfo;
doc = documentManager.getBioModel(bmi);
} else if (documentInfo instanceof MathModelInfo) {
MathModelInfo mmi = (MathModelInfo) documentInfo;
doc = documentManager.getMathModel(mmi);
} else if (documentInfo instanceof GeometryInfo) {
GeometryInfo gmi = (GeometryInfo) documentInfo;
doc = documentManager.getGeometry(gmi);
}
if (doc == null) {
throw new IllegalStateException("export called on DatabaseWindowManager with selection " + documentInfo);
}
}
if (doc != null) {
hashTable.put(EXPORT_DOCUMENT, doc);
} else {
throw new UnsupportedOperationException("TopLevelWindowManager subclass " + topLevelWindowManager.getClass().getName() + " does not support exporting to document");
}
}
Aggregations