Search in sources :

Example 1 with OpenModelInfoHolder

use of cbit.vcell.client.TopLevelWindowManager.OpenModelInfoHolder 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;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ActionListener(java.awt.event.ActionListener) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) JButton(javax.swing.JButton) UserCancelException(org.vcell.util.UserCancelException) RequestManager(cbit.vcell.client.RequestManager) ClientRequestManager(cbit.vcell.client.ClientRequestManager) Version(org.vcell.util.document.Version) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCDocument(org.vcell.util.document.VCDocument) Hashtable(java.util.Hashtable) FDSimMathModelInfo(cbit.vcell.client.TopLevelWindowManager.FDSimMathModelInfo) OpenModelInfoHolder(cbit.vcell.client.TopLevelWindowManager.OpenModelInfoHolder) ActionEvent(java.awt.event.ActionEvent) DataFormatException(java.util.zip.DataFormatException) UserCancelException(org.vcell.util.UserCancelException) Geometry(cbit.vcell.geometry.Geometry) TreePath(javax.swing.tree.TreePath) FDSimBioModelInfo(cbit.vcell.client.TopLevelWindowManager.FDSimBioModelInfo)

Example 2 with OpenModelInfoHolder

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

the class ClientRequestManager method getOpenDesktopDocumentInfos.

public OpenModelInfoHolder[] getOpenDesktopDocumentInfos(boolean bIncludeSimulations) throws DataAccessException {
    Vector<OpenModelInfoHolder> simInfoHolderV = new Vector<OpenModelInfoHolder>();
    for (TopLevelWindowManager tlwm : getMdiManager().getWindowManagers()) {
        if (tlwm instanceof DocumentWindowManager) {
            DocumentWindowManager dwm = (DocumentWindowManager) tlwm;
            VCDocument vcDoc = dwm.getVCDocument();
            // if(vcDoc.getVersion() != null){
            if (vcDoc.getDocumentType() == VCDocumentType.BIOMODEL_DOC) {
                BioModel bioModel = (BioModel) vcDoc;
                // getDocumentManager().getBioModel(vcDoc.getVersion().getVersionKey());
                SimulationContext[] simContexts = bioModel.getSimulationContexts();
                for (int i = 0; i < simContexts.length; i += 1) {
                    if (bIncludeSimulations) {
                        if (simContexts[i].getGeometry() == null) {
                            throw new DataAccessException("Error gathering document info (isCompartmental check failed):\nOpen BioModel document " + bioModel.getName() + " has no Geometry");
                        }
                        Simulation[] sims = simContexts[i].getSimulations();
                        for (int j = 0; j < sims.length; j += 1) {
                            for (int k = 0; k < sims[j].getScanCount(); k += 1) {
                                FieldDataWindowManager.OpenModelInfoHolder simInfoHolder = new FieldDataWindowManager.FDSimBioModelInfo(sims[j].getName(), bioModel.getVersion(), simContexts[i], sims[j].getSimulationInfo(), k, // !sims[j].getSolverTaskDescription().getSolverDescription().hasVariableTimestep(),
                                simContexts[i].getGeometry().getDimension() == 0);
                                simInfoHolderV.add(simInfoHolder);
                            }
                        }
                    } else {
                        FieldDataWindowManager.OpenModelInfoHolder simInfoHolder = new FieldDataWindowManager.FDSimBioModelInfo(null, bioModel.getVersion(), simContexts[i], null, -1, simContexts[i].getGeometry().getDimension() == 0);
                        simInfoHolderV.add(simInfoHolder);
                    }
                }
            } else if (vcDoc.getDocumentType() == VCDocumentType.MATHMODEL_DOC) {
                MathModel mathModel = (MathModel) vcDoc;
                // getDocumentManager().getMathModel(vcDoc.getVersion().getVersionKey());
                if (bIncludeSimulations) {
                    if (mathModel.getMathDescription() == null || mathModel.getMathDescription().getGeometry() == null) {
                        throw new DataAccessException("Error gathering document info (isCompartmental check failed):\nOpen MathModel document " + mathModel.getName() + " has either no MathDescription or no Geometry");
                    }
                    Simulation[] sims = mathModel.getSimulations();
                    for (int i = 0; i < sims.length; i += 1) {
                        for (int k = 0; k < sims[i].getScanCount(); k += 1) {
                            FieldDataWindowManager.OpenModelInfoHolder simInfoHolder = new FieldDataWindowManager.FDSimMathModelInfo(sims[i].getName(), mathModel.getVersion(), mathModel.getMathDescription(), sims[i].getSimulationInfo(), k, // !sims[i].getSolverTaskDescription().getSolverDescription().hasVariableTimestep(),
                            mathModel.getMathDescription().getGeometry().getDimension() == 0);
                            simInfoHolderV.add(simInfoHolder);
                        }
                    }
                } else {
                    FieldDataWindowManager.OpenModelInfoHolder simInfoHolder = new FieldDataWindowManager.FDSimMathModelInfo(null, mathModel.getVersion(), mathModel.getMathDescription(), null, -1, mathModel.getMathDescription().getGeometry().getDimension() == 0);
                    simInfoHolderV.add(simInfoHolder);
                }
            }
        // }
        }
    }
    OpenModelInfoHolder[] simInfoHolderArr = new OpenModelInfoHolder[simInfoHolderV.size()];
    simInfoHolderV.copyInto(simInfoHolderArr);
    return simInfoHolderArr;
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) VCDocument(org.vcell.util.document.VCDocument) OpenModelInfoHolder(cbit.vcell.client.TopLevelWindowManager.OpenModelInfoHolder) SimulationContext(cbit.vcell.mapping.SimulationContext) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) Vector(java.util.Vector) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

OpenModelInfoHolder (cbit.vcell.client.TopLevelWindowManager.OpenModelInfoHolder)2 VCDocument (org.vcell.util.document.VCDocument)2 BioModel (cbit.vcell.biomodel.BioModel)1 ClientRequestManager (cbit.vcell.client.ClientRequestManager)1 RequestManager (cbit.vcell.client.RequestManager)1 FDSimBioModelInfo (cbit.vcell.client.TopLevelWindowManager.FDSimBioModelInfo)1 FDSimMathModelInfo (cbit.vcell.client.TopLevelWindowManager.FDSimMathModelInfo)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 Geometry (cbit.vcell.geometry.Geometry)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 MathModel (cbit.vcell.mathmodel.MathModel)1 DataIdentifier (cbit.vcell.simdata.DataIdentifier)1 Simulation (cbit.vcell.solver.Simulation)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Hashtable (java.util.Hashtable)1 Vector (java.util.Vector)1 DataFormatException (java.util.zip.DataFormatException)1 JButton (javax.swing.JButton)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1