Search in sources :

Example 1 with TopLevelWindowManager

use of cbit.vcell.client.TopLevelWindowManager in project vcell by virtualcell.

the class ChooseFile method showBioModelXMLFileChooser.

/**
 * Insert the method's description here.
 * Creation date: (5/31/2004 6:04:14 PM)
 */
private File showBioModelXMLFileChooser(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    BioModel bioModel = (BioModel) hashTable.get("documentToExport");
    JFrame currentWindow = (JFrame) hashTable.get("currentWindow");
    UserPreferences userPreferences = (UserPreferences) hashTable.get("userPreferences");
    TopLevelWindowManager topLevelWindowManager = (TopLevelWindowManager) hashTable.get("topLevelWindowManager");
    SelectorExtensionFilter forceFileFilter = null;
    {
        Object obj = hashTable.get(FORCE_FILE_FILTER);
        if (obj != null) {
            VCAssert.ofType(obj, SelectorExtensionFilter.class);
            forceFileFilter = (SelectorExtensionFilter) obj;
            VCAssert.assertTrue(forceFileFilter.supports(Selector.FULL_MODEL), "only " + Selector.FULL_MODEL + " filters supported for force file filter");
        }
    }
    if (topLevelWindowManager == null) {
        throw new RuntimeException("toplLevelWindowManager required");
    }
    File defaultPath = userPreferences.getCurrentDialogPath();
    // JFileChooser fileChooser = new JFileChooser(defaultPath);
    VCFileChooser fileChooser = new VCFileChooser(defaultPath);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);
    final SimulationContext[] simContexts = bioModel.getSimulationContexts();
    boolean spatialDeterministicSim = false;
    boolean nonspatialDeterministicSim = false;
    boolean stochasticSim = false;
    @SuppressWarnings("unused") boolean // add logic to set this
    bnglSim = false;
    for (SimulationContext sc : simContexts) {
        if (sc.getApplicationType() == Application.NETWORK_STOCHASTIC) {
            stochasticSim = true;
        } else {
            if (sc.getGeometry().getDimension() > 0) {
                spatialDeterministicSim = true;
            } else {
                nonspatialDeterministicSim = true;
            }
        }
    }
    FileFilter defaultFileFilter;
    if (forceFileFilter == null) {
        List<FileFilter> dlist = FileFilters.supports(SelectorExtensionFilter.Selector.DEFAULT);
        VCAssert.assertTrue(dlist.size() == 1, "Exactly one filter must be designated default");
        defaultFileFilter = dlist.get(0);
        // use a set to avoid duplicated entries; TreeSet show listing is alphabetical
        Set<FileFilter> filters = new TreeSet<>();
        filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.FULL_MODEL));
        if (spatialDeterministicSim) {
            filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.DETERMINISTIC, SelectorExtensionFilter.Selector.SPATIAL));
        }
        if (nonspatialDeterministicSim) {
            filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.DETERMINISTIC, SelectorExtensionFilter.Selector.NONSPATIAL));
        }
        if (stochasticSim) {
            filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.STOCHASTIC));
        }
        /*add BNGL selector here
		if (bnglSim) {
			filters.addAll(FileFilters.supports(SelectorExtensionFilter.Selector.BNGL));
		}
		*/
        fileChooser.addChoosableFileFilter(defaultFileFilter);
        for (FileFilter f : filters) {
            if (f == defaultFileFilter) {
                continue;
            }
            fileChooser.addChoosableFileFilter(f);
        }
    /*
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_12);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_21);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_22);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_23);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_24);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_31_CORE);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_31_SPATIAL);
	//	fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_CELLML);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SEDML);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_VCML);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_MATLABV6);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_PDF);
		fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SMOLDYN_INPUT);
		*/
    } else {
        defaultFileFilter = forceFileFilter;
    }
    // remove all selectors
    fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
    // Set the default file filter...
    fileChooser.setFileFilter(defaultFileFilter);
    fileChooser.setSelectedFile(new java.io.File(TokenMangler.fixTokenStrict(bioModel.getName())));
    fileChooser.setDialogTitle("Export Virtual Cell BioModel As...");
    if (fileChooser.showSaveDialog(currentWindow) != JFileChooser.APPROVE_OPTION) {
        // user didn't choose save
        throw UserCancelException.CANCEL_FILE_SELECTION;
    }
    File selectedFile = fileChooser.getSelectedFile();
    FileFilter gfileFilter = fileChooser.getFileFilter();
    VCAssert.ofType(gfileFilter, SelectorExtensionFilter.class);
    // only ExtensionFilters should have been added;
    SelectorExtensionFilter fileFilter = (SelectorExtensionFilter) gfileFilter;
    if (selectedFile == null) {
        // no file selected (no name given)
        throw UserCancelException.CANCEL_FILE_SELECTION;
    }
    final File fileUserSpecified = selectedFile.getCanonicalFile();
    // /
    String selectedFileName = recordAndRemoveExtension(selectedFile.getPath());
    if (extensionUserProvided != null && !extensionUserProvided.isEmpty() && !extensionUserProvided.startsWith(".")) {
        extensionUserProvided = "." + extensionUserProvided;
    }
    if (fileFilter.isValidExtension(extensionUserProvided)) {
        selectedFileName += extensionUserProvided;
    } else {
        selectedFileName += fileFilter.getPrimaryExtension();
    }
    selectedFile = new File(selectedFileName);
    checkForOverwrites(selectedFile, topLevelWindowManager.getComponent(), userPreferences);
    // put the filter in the hash so the export task knows what to do...
    hashTable.put(FILE_FILTER, fileFilter);
    if (fileFilter.supports(SelectorExtensionFilter.Selector.FULL_MODEL)) {
        // nothing more to do in this case
        resetPreferredFilePath(selectedFile, userPreferences);
        return selectedFile;
    }
    // ArrayList<String> applicableAppNameList = new ArrayList<String>();
    ArrayList<SimulationContext> applicableSimContexts = new ArrayList<>();
    for (SimulationContext sc : simContexts) {
        if (sc.getGeometry().getDimension() == 0) {
            if (!fileFilter.supports(SelectorExtensionFilter.Selector.NONSPATIAL)) {
                continue;
            }
        } else if (!fileFilter.supports(SelectorExtensionFilter.Selector.SPATIAL)) {
            continue;
        }
        if (sc.getApplicationType() == Application.NETWORK_STOCHASTIC) {
            if (!fileFilter.supports(SelectorExtensionFilter.Selector.STOCHASTIC)) {
                continue;
            }
        } else if (!fileFilter.supports(SelectorExtensionFilter.Selector.DETERMINISTIC)) {
            continue;
        }
        applicableSimContexts.add(sc);
    }
    /*
		{} else {
			// all apps
			for (int i=0;i<simContexts.length;i++){
				applicableAppNameList.add(simContexts[i].getName());
			}
		}
	 */
    SimulationContext chosenSimContext = null;
    if (applicableSimContexts.size() == 1) {
        chosenSimContext = applicableSimContexts.get(0);
    } else /*
		else if (!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_PDF.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_12.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_21.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_22.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_23.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_24.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_31_CORE.getDescription()) &&
				!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_31_SPATIAL.getDescription())) {
			if(fileFilter.getDescription().equals(FileFilters.FILE_FILTER_BNGL.getDescription())) {
				boolean hasReactions = bioModel.getModel().getReactionSteps().length > 0 ? true : false;
				System.out.println(hasReactions);
				if(hasReactions) {					// mixed
					String errMsg = "Simple Reactions cannot be exported to .bngl format.";
					errMsg += "<br>Some information will be lost.";
					errMsg += "<br><br>Continue anyway?";
					errMsg = "<html>" + errMsg + "</html>";
					int dialogButton = JOptionPane.YES_NO_OPTION;
					int returnCode = JOptionPane.showConfirmDialog(topLevelWindowManager.getComponent(), errMsg, "Exporting to .bngl", dialogButton);
					if (returnCode != JOptionPane.YES_OPTION) {
						throw UserCancelException.CANCEL_FILE_SELECTION;
					}
				}
			}

			//String[] applicationNames = (String[])org.vcell.util.BeanUtils.getArray(applicableAppNameList,String.class);
		}	 */
    {
        // String[] applicationNames = applicableAppNameList.toArray(new String[applicableAppNameList.size()]);
        SimContextAdapter[] scarray = adapt(applicableSimContexts);
        Object choice = PopupGenerator.showListDialog(topLevelWindowManager, scarray, "Please select Application");
        if (choice == null) {
            throw UserCancelException.CANCEL_FILE_SELECTION;
        }
        VCAssert.ofType(choice, SimContextAdapter.class);
        SimContextAdapter sca = (SimContextAdapter) choice;
        chosenSimContext = sca.simCtx;
    }
    hashTable.put(SIM_CONTEXT, chosenSimContext);
    // boolean isSbml = fileFilter.supports(SelectorExtensionFilter.Selector.SBML);
    if (fileFilter.requiresMoreChoices()) {
        ExtensionFilter.ChooseContext ctx = new ExtensionFilter.ChooseContext(hashTable, topLevelWindowManager, currentWindow, chosenSimContext, selectedFile, selectedFileName);
        fileFilter.askUser(ctx);
    }
    {
        boolean showConfirm = false;
        final boolean someContextsFiltered = simContexts.length > applicableSimContexts.size();
        showConfirm = someContextsFiltered;
        if (!showConfirm) {
            final File fileAfterProcessing = selectedFile.getCanonicalFile();
            if (!fileAfterProcessing.equals(fileUserSpecified)) {
                final String nameUserSpecified = fileUserSpecified.getCanonicalPath();
                final String nameAfterProcessing = fileAfterProcessing.getCanonicalPath();
                if (FilenameUtils.indexOfExtension(nameUserSpecified) > 0) {
                    // have extension on user path
                    showConfirm = true;
                } else {
                    // don't prompt if user left extension off
                    String nameAfterNoExtension = FilenameUtils.getFullPath(nameAfterProcessing) + FilenameUtils.getBaseName(nameAfterProcessing);
                    if (!nameAfterNoExtension.equals(nameUserSpecified)) {
                        showConfirm = true;
                    }
                }
            }
        }
        if (showConfirm) {
            final String exportDesc = fileFilter.getShortDescription();
            StringBuilder sb = new StringBuilder();
            List<SimulationContext> all = new ArrayList<>(Arrays.asList(simContexts));
            all.removeAll(applicableSimContexts);
            if (!all.isEmpty()) {
                SimContextAdapter[] removed = adapt(all);
                sb.append("The following simulations are not supported by ");
                sb.append(exportDesc);
                sb.append(" and have been removed: ");
                sb.append(StringUtils.join(removed, ", "));
                sb.append(".\n\n");
            }
            SimContextAdapter[] included = adapt(applicableSimContexts);
            sb.append("Export model with simulations ");
            sb.append(StringUtils.join(included, ", "));
            sb.append(" to file of type ");
            sb.append(exportDesc);
            sb.append(' ');
            sb.append(selectedFile.getCanonicalPath());
            sb.append('?');
            String reply = DialogUtils.showOKCancelWarningDialog(currentWindow, "Verify Export", sb.toString());
            if (!SimpleUserMessage.OPTION_OK.equals(reply)) {
                throw UserCancelException.CANCEL_GENERIC;
            }
        }
    }
    resetPreferredFilePath(selectedFile, userPreferences);
    return selectedFile;
}
Also used : UserPreferences(cbit.vcell.client.server.UserPreferences) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) ArrayList(java.util.ArrayList) JFrame(javax.swing.JFrame) TreeSet(java.util.TreeSet) ExtensionFilter(org.vcell.util.gui.exporter.ExtensionFilter) SelectorExtensionFilter(org.vcell.util.gui.exporter.SelectorExtensionFilter) VCFileChooser(org.vcell.util.gui.VCFileChooser) ArrayList(java.util.ArrayList) List(java.util.List) FileFilter(javax.swing.filechooser.FileFilter) SelectorExtensionFilter(org.vcell.util.gui.exporter.SelectorExtensionFilter) SimulationContext(cbit.vcell.mapping.SimulationContext) File(java.io.File) BioModel(cbit.vcell.biomodel.BioModel) File(java.io.File)

Example 2 with TopLevelWindowManager

use of cbit.vcell.client.TopLevelWindowManager in project vcell by virtualcell.

the class FinishExport 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 {
    MDIManager mdiManager = (MDIManager) hashTable.get("mdiManager");
    TopLevelWindowManager topLevelWindowManager = (TopLevelWindowManager) hashTable.get("topLevelWindowManager");
    Object obj = hashTable.get(RENAME_KEY);
    if (obj != null) {
        String fn = obj.toString();
        DialogUtils.showInfoDialog(topLevelWindowManager.getComponent(), "Export saved as  " + fn);
    }
    mdiManager.unBlockWindow(topLevelWindowManager.getManagerID());
    mdiManager.showWindow(topLevelWindowManager.getManagerID());
}
Also used : MDIManager(cbit.vcell.client.MDIManager) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager)

Example 3 with TopLevelWindowManager

use of cbit.vcell.client.TopLevelWindowManager in project vcell by virtualcell.

the class VCellClientDataServiceImpl method getSimsFromOpenModels.

@Override
public List<SimulationDataSetRef> getSimsFromOpenModels() {
    ArrayList<SimulationDataSetRef> simulationDataSetRefs = new ArrayList<SimulationDataSetRef>();
    for (TopLevelWindowManager windowManager : vcellClient.getMdiManager().getWindowManagers()) {
        Simulation[] simulations = null;
        VCDocument modelDocument = null;
        if (windowManager instanceof BioModelWindowManager) {
            BioModelWindowManager selectedBioWindowManager = (BioModelWindowManager) windowManager;
            BioModel bioModel = selectedBioWindowManager.getBioModel();
            simulations = bioModel.getSimulations();
            modelDocument = bioModel;
        // simOwnerCount = bioModel.getNumSimulationContexts();
        } else if (windowManager instanceof MathModelWindowManager) {
            MathModelWindowManager selectedMathWindowManager = (MathModelWindowManager) windowManager;
            MathModel mathModel = selectedMathWindowManager.getMathModel();
            simulations = mathModel.getSimulations();
            modelDocument = mathModel;
        // simOwnerCount = 1;
        }
        if (simulations != null) {
            for (Simulation simulation : simulations) {
                if (!isVtkSupported(simulation)) {
                    continue;
                }
                Origin origin = simulation.getMathDescription().getGeometry().getOrigin();
                Extent extent = simulation.getMathDescription().getGeometry().getExtent();
                SimulationInfo simInfo = simulation.getSimulationInfo();
                SimulationStatus simStatus = vcellClient.getRequestManager().getServerSimulationStatus(simInfo);
                for (int jobIndex = 0; jobIndex < simulation.getScanCount(); jobIndex++) {
                    if (simStatus != null && simStatus.getHasData()) {
                        SimulationDataSetRef simulationDataSetReference = VCellClientDataServiceImpl.createSimulationDataSetRef(simulation, modelDocument, jobIndex, false);
                        simulationDataSetRefs.add(simulationDataSetReference);
                    }
                }
            }
        }
    }
    File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
    String[] simtaskFilenames = localSimDir.list((dir, name) -> (name.endsWith(".simtask.xml")));
    for (String simtaskFilename : simtaskFilenames) {
        try {
            SimulationTask simTask = XmlHelper.XMLToSimTask(org.apache.commons.io.FileUtils.readFileToString(new File(localSimDir, simtaskFilename)));
            VCDocument modelDocument = null;
            SimulationDataSetRef simulationDataSetReference = VCellClientDataServiceImpl.createSimulationDataSetRef(simTask.getSimulation(), modelDocument, simTask.getSimulationJob().getJobIndex(), true);
            simulationDataSetRefs.add(simulationDataSetReference);
        } catch (ExpressionException | XmlParseException | IOException e) {
            e.printStackTrace();
        }
    }
    return simulationDataSetRefs;
}
Also used : Origin(org.vcell.util.Origin) MathModel(cbit.vcell.mathmodel.MathModel) SimulationTask(cbit.vcell.messaging.server.SimulationTask) VCDocument(org.vcell.util.document.VCDocument) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) Extent(org.vcell.util.Extent) ArrayList(java.util.ArrayList) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) SimulationDataSetRef(cbit.vcell.client.pyvcellproxy.SimulationDataSetRef) MathModelWindowManager(cbit.vcell.client.MathModelWindowManager) ExpressionException(cbit.vcell.parser.ExpressionException) Simulation(cbit.vcell.solver.Simulation) BioModelWindowManager(cbit.vcell.client.BioModelWindowManager) SimulationStatus(cbit.vcell.server.SimulationStatus) BioModel(cbit.vcell.biomodel.BioModel) File(java.io.File) SimulationInfo(cbit.vcell.solver.SimulationInfo)

Example 4 with TopLevelWindowManager

use of cbit.vcell.client.TopLevelWindowManager in project vcell by virtualcell.

the class VCellClientDataServiceImpl method displayPostProcessingDataInVCell.

@Override
public void displayPostProcessingDataInVCell(SimulationDataSetRef simulationDataSetRef) throws NumberFormatException, DataAccessException {
    User vcUser = vcellClient.getRequestManager().getDocumentManager().getUser();
    VCSimulationIdentifier vcSimId = new VCSimulationIdentifier(new KeyValue(simulationDataSetRef.getSimId()), vcUser);
    ClientDocumentManager clientDocumentManager = (ClientDocumentManager) vcellClient.getClientServerManager().getDocumentManager();
    SimulationOwner simulationOwner = null;
    if (simulationDataSetRef.isMathModel) {
        simulationOwner = clientDocumentManager.getMathModel(new KeyValue(simulationDataSetRef.getModelId()));
    } else {
        BioModel bioModel = clientDocumentManager.getBioModel(new KeyValue(simulationDataSetRef.getModelId()));
        simulationOwner = bioModel.getSimulationContext(simulationDataSetRef.getSimulationContextName());
    }
    ArrayList<AnnotatedFunction> outputFunctionsList = simulationOwner.getOutputFunctionContext().getOutputFunctionsList();
    OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
    VCSimulationDataIdentifier vcSimDataId = new VCSimulationDataIdentifier(vcSimId, simulationDataSetRef.getJobIndex());
    PDEDataManager pdeDataManager = (PDEDataManager) vcellClient.getRequestManager().getDataManager(outputContext, vcSimDataId, true);
    final ClientPDEDataContext newClientPDEDataContext = pdeDataManager.getPDEDataContext();
    // this was the code before the windows refactoring; appears to just always get the first window???
    // Enumeration<TopLevelWindowManager> windowManagers = vcellClient.getMdiManager().getWindowManagers();
    // final Window window = FindWindow.getWindow(windowManagers.nextElement().getComponent());
    Optional<TopLevelWindowManager> first = vcellClient.getMdiManager().getWindowManagers().stream().findFirst();
    VCAssert.assertTrue(first.isPresent(), "window manager not present?");
    final Window window = getWindow(first.get().getComponent());
    AsynchClientTask task = new AsynchClientTask("Display Post Processing Statistics", AsynchClientTask.TASKTYPE_SWING_NONBLOCKING, false, false) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            DataProcessingResultsPanel dataProcessingResultsPanel = new DataProcessingResultsPanel();
            dataProcessingResultsPanel.update(newClientPDEDataContext);
            DialogUtils.showComponentOKCancelDialog(window, dataProcessingResultsPanel, "Post Processing Statistics");
        }
    };
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    Vector<AsynchClientTask> tasksV = new Vector<AsynchClientTask>();
    tasksV.add(task);
    AsynchClientTask[] tasks = new AsynchClientTask[tasksV.size()];
    tasksV.copyInto(tasks);
    ClientTaskDispatcher.dispatch(window, hash, tasks, true);
}
Also used : Window(java.awt.Window) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) Hashtable(java.util.Hashtable) ClientDocumentManager(cbit.vcell.clientdb.ClientDocumentManager) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) LocalVCSimulationDataIdentifier(cbit.vcell.client.ClientSimManager.LocalVCSimulationDataIdentifier) OutputContext(cbit.vcell.simdata.OutputContext) SimulationOwner(cbit.vcell.solver.SimulationOwner) PDEDataManager(cbit.vcell.simdata.PDEDataManager) BioModel(cbit.vcell.biomodel.BioModel) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) Vector(java.util.Vector) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 5 with TopLevelWindowManager

use of cbit.vcell.client.TopLevelWindowManager in project vcell by virtualcell.

the class ChooseFile method showGeometryModelXMLFileChooser.

// // Check structure sized and select a simulation to export to SBML
// if (isSbml) {
// // get user choice of structure and its size and computes absolute sizes of compartments using the StructureSizeSolver.
// Structure[] structures = bioModel.getModel().getStructures();
// // get the nonspatial simulationContexts corresponding to names in applicableAppNameList
// // This is needed in ApplnSelectionAndStructureSizeInputPanel
// 
// SimulationContext[] applicableSimContexts = applicableSimContext.toArray(new SimulationContext[applicableSimContext.size()]);
// 
// String strucName = null;
// double structSize = 1.0;
// int structSelection = -1;
// int option = JOptionPane.CANCEL_OPTION;
// Simulation chosenSimulation = null;
// 
// ApplnSelectionAndStructureSizeInputPanel applnStructInputPanel = null;
// while (structSelection < 0) {
// applnStructInputPanel = new ApplnSelectionAndStructureSizeInputPanel();
// applnStructInputPanel.setSimContexts(applicableSimContexts);
// applnStructInputPanel.setStructures(structures);
// applnStructInputPanel.setPreferredSize(new java.awt.Dimension(350, 400));
// applnStructInputPanel.setMaximumSize(new java.awt.Dimension(350, 400));
// option = DialogUtils.showComponentOKCancelDialog(currentWindow, applnStructInputPanel, "Select Application and Specify Structure Size to Export:");
// structSelection = applnStructInputPanel.getStructSelectionIndex();
// if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
// break;
// } else if (option == JOptionPane.OK_OPTION && structSelection < 0) {
// DialogUtils.showErrorDialog(currentWindow, "Please select a structure and set its size");
// }
// }
// 
// if (option == JOptionPane.OK_OPTION) {
// applnStructInputPanel.applyStructureNameAndSizeValues();
// strucName = applnStructInputPanel.getSelectedStructureName();
// chosenSimContext = applnStructInputPanel.getSelectedSimContext();
// hashTable.put("selectedSimContext", chosenSimContext);
// 
// GeometryContext geoContext = chosenSimContext.getGeometryContext();
// if (!fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SBML_31_SPATIAL.getDescription())) {
// // calculate structure Sizes only if appln is not spatial
// structSize = applnStructInputPanel.getStructureSize();
// // Invoke StructureSizeEvaluator to compute absolute sizes of compartments if all sizes are not set
// if ( (geoContext.isAllSizeSpecifiedNull() && geoContext.isAllVolFracAndSurfVolSpecifiedNull()) ||
// ((strucName == null || structSize <= 0.0) && (geoContext.isAllSizeSpecifiedNull() && geoContext.isAllVolFracAndSurfVolSpecified())) ||
// (!geoContext.isAllSizeSpecifiedPositive() && geoContext.isAllVolFracAndSurfVolSpecifiedNull()) ||
// (!geoContext.isAllSizeSpecifiedPositive() && !geoContext.isAllVolFracAndSurfVolSpecified()) ||
// (geoContext.isAllSizeSpecifiedNull() && !geoContext.isAllVolFracAndSurfVolSpecified()) ) {
// DialogUtils.showErrorDialog(currentWindow, "Cannot export to SBML without compartment sizes being set. This can be automatically " +
// " computed if the absolute size of at least one compartment and the relative sizes (Surface-to-volume-ratio/Volume-fraction) " +
// " of all compartments are known. Sufficient information is not available to perform this computation." +
// "\n\nThis can be fixed by going back to the application '" + chosenSimContext.getName() + "' and setting structure sizes in the 'StructureMapping' tab.");
// throw UserCancelException.CANCEL_XML_TRANSLATION;
// }
// if (!geoContext.isAllSizeSpecifiedPositive() && geoContext.isAllVolFracAndSurfVolSpecified()) {
// Structure chosenStructure = chosenSimContext.getModel().getStructure(strucName);
// StructureMapping chosenStructMapping = chosenSimContext.getGeometryContext().getStructureMapping(chosenStructure);
// StructureSizeSolver.updateAbsoluteStructureSizes(chosenSimContext, chosenStructure, structSize, chosenStructMapping.getSizeParameter().getUnitDefinition());
// }
// } else {
// if (!geoContext.isAllUnitSizeParameterSetForSpatial()) {
// DialogUtils.showErrorDialog(currentWindow, "Cannot export to SBML without compartment size ratios being set."  +
// "\n\nThis can be fixed by going back to the application '" + chosenSimContext.getName() + "' and setting structure" +
// " size ratios in the 'StructureMapping' tab.");
// throw UserCancelException.CANCEL_XML_TRANSLATION;
// }
// }
// 
// // Select simulation whose overrides need to be exported
// // If simContext doesn't have simulations, don't pop up simulationSelectionPanel
// Simulation[] sims = bioModel.getSimulations(chosenSimContext);
// // display only those simulations that have overrides in the simulationSelectionPanel.
// Vector<Simulation> orSims = new Vector<Simulation>();
// for (int s = 0; (sims != null) && (s < sims.length); s++) {
// if (sims[s].getMathOverrides().hasOverrides()) {
// orSims.addElement(sims[s]);
// }
// }
// Simulation[] overriddenSims = (Simulation[])BeanUtils.getArray(orSims, Simulation.class);
// if (overriddenSims.length > 0) {
// SimulationSelectionPanel simSelectionPanel = new SimulationSelectionPanel();
// simSelectionPanel.setPreferredSize(new java.awt.Dimension(600, 400));
// simSelectionPanel.setMaximumSize(new java.awt.Dimension(600, 400));
// simSelectionPanel.setSimulations(overriddenSims);
// int simOption = DialogUtils.showComponentOKCancelDialog(currentWindow, simSelectionPanel, "Select Simulation whose overrides should be exported:");
// if (simOption == JOptionPane.OK_OPTION) {
// chosenSimulation = simSelectionPanel.getSelectedSimulation();
// if (chosenSimulation != null) {
// hashTable.put("selectedSimulation", chosenSimulation);
// }
// } else if (simOption == JOptionPane.CANCEL_OPTION || simOption == JOptionPane.CLOSED_OPTION) {
// // User did not choose a simulation whose overrides are required to be exported.
// // Without that information, cannot export successfully into SBML,
// // Hence canceling the entire export to SBML operation.
// throw UserCancelException.CANCEL_XML_TRANSLATION;
// }
// }
// } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
// // User did not choose to set size for any structure.
// // Without that information, cannot export successfully into SBML,
// // Hence canceling the entire export to SBML operation.
// throw UserCancelException.CANCEL_XML_TRANSLATION;
// }
// 
// if (chosenSimulation != null) {
// // rename file to contain exported simulation.
// String ext = FilenameUtils.getExtension(selectedFileName);
// String base = FilenameUtils.getBaseName(selectedFileName);
// String path = FilenameUtils.getPath(selectedFileName);
// base += "_"  + TokenMangler.mangleToSName(chosenSimulation.getName());
// selectedFileName = path + base + ext;
// selectedFile.renameTo(new File(selectedFileName));
// }
// resetPreferredFilePath(selectedFile, userPreferences);
// return selectedFile;
// }
/**
 * Export to Geometry
 * Creation date: (5/31/2004 6:04:14 PM)
 * @param hashTable java.util.Hashtable
 * @param clientWorker cbit.vcell.desktop.controls.ClientWorker
 */
private File showGeometryModelXMLFileChooser(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    Geometry geom = (Geometry) hashTable.get("documentToExport");
    JFrame currentWindow = (JFrame) hashTable.get("currentWindow");
    UserPreferences userPreferences = (UserPreferences) hashTable.get("userPreferences");
    TopLevelWindowManager topLevelWindowManager = (TopLevelWindowManager) hashTable.get("topLevelWindowManager");
    Component comp = (Component) hashTable.get("component");
    comp = (comp == null ? (currentWindow == null ? (topLevelWindowManager == null ? null : topLevelWindowManager.getComponent()) : currentWindow) : comp);
    File defaultPath = userPreferences.getCurrentDialogPath();
    VCFileChooser fileChooser = new VCFileChooser(defaultPath);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);
    // fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_VCML);
    fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_PDF);
    if (geom.getDimension() > 0) {
        fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_AVS);
        fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_STL);
        fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_PLY);
    }
    // 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(geom.getName())));
    fileChooser.setDialogTitle("Export Virtual Cell Geometry As...");
    if (fileChooser.showSaveDialog(comp) != 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_VCML && !n.endsWith(".vcml")) {
                selectedFile = new File(selectedFileName + ".vcml");
            } else if (fileFilter == FileFilters.FILE_FILTER_PDF && !n.endsWith(".pdf")) {
                selectedFile = new File(selectedFileName + ".pdf");
            }
            if (fileFilter == null) {
                throw new Exception("No file save type was selected.");
            }
            checkForOverwrites(selectedFile, comp, userPreferences);
            // put the filter in the hash so the export task knows what to do...
            hashTable.put("fileFilter", fileFilter);
            resetPreferredFilePath(selectedFile, userPreferences);
            return selectedFile;
        }
    }
}
Also used : UserPreferences(cbit.vcell.client.server.UserPreferences) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) UserCancelException(org.vcell.util.UserCancelException) Geometry(cbit.vcell.geometry.Geometry) JFrame(javax.swing.JFrame) VCFileChooser(org.vcell.util.gui.VCFileChooser) Component(java.awt.Component) File(java.io.File)

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