Search in sources :

Example 6 with TopLevelWindowManager

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;
        }
    }
}
Also used : UserPreferences(cbit.vcell.client.server.UserPreferences) MathModel(cbit.vcell.mathmodel.MathModel) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) UserCancelException(org.vcell.util.UserCancelException) Simulation(cbit.vcell.solver.Simulation) JFrame(javax.swing.JFrame) VCFileChooser(org.vcell.util.gui.VCFileChooser) File(java.io.File)

Example 7 with TopLevelWindowManager

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");
    }
}
Also used : VCDocument(org.vcell.util.document.VCDocument) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) DocumentWindowManager(cbit.vcell.client.DocumentWindowManager) VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) DocumentManager(cbit.vcell.clientdb.DocumentManager) BioModelInfo(org.vcell.util.document.BioModelInfo) GeometryInfo(cbit.vcell.geometry.GeometryInfo) MathModelInfo(org.vcell.util.document.MathModelInfo) DatabaseWindowManager(cbit.vcell.client.DatabaseWindowManager)

Aggregations

TopLevelWindowManager (cbit.vcell.client.TopLevelWindowManager)7 File (java.io.File)4 BioModel (cbit.vcell.biomodel.BioModel)3 UserPreferences (cbit.vcell.client.server.UserPreferences)3 JFrame (javax.swing.JFrame)3 FileFilter (javax.swing.filechooser.FileFilter)3 VCFileChooser (org.vcell.util.gui.VCFileChooser)3 MathModel (cbit.vcell.mathmodel.MathModel)2 Simulation (cbit.vcell.solver.Simulation)2 ArrayList (java.util.ArrayList)2 UserCancelException (org.vcell.util.UserCancelException)2 VCDocument (org.vcell.util.document.VCDocument)2 BioModelWindowManager (cbit.vcell.client.BioModelWindowManager)1 LocalVCSimulationDataIdentifier (cbit.vcell.client.ClientSimManager.LocalVCSimulationDataIdentifier)1 DatabaseWindowManager (cbit.vcell.client.DatabaseWindowManager)1 DocumentWindowManager (cbit.vcell.client.DocumentWindowManager)1 MDIManager (cbit.vcell.client.MDIManager)1 MathModelWindowManager (cbit.vcell.client.MathModelWindowManager)1 SimulationDataSetRef (cbit.vcell.client.pyvcellproxy.SimulationDataSetRef)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1