Search in sources :

Example 26 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class SaveDocument 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 {
    long l1 = System.currentTimeMillis();
    DocumentWindowManager documentWindowManager = (DocumentWindowManager) hashTable.get(CommonTask.DOCUMENT_WINDOW_MANAGER.name);
    VCDocument currentDocument = documentWindowManager.getVCDocument();
    DocumentManager documentManager = (DocumentManager) hashTable.get(CommonTask.DOCUMENT_MANAGER.name);
    RequestManager requestManager = (RequestManager) hashTable.get("requestManager");
    boolean bAsNew = hashTable.containsKey("newName");
    String newName = bAsNew ? (String) hashTable.get("newName") : null;
    Simulation[] simulationsToRun = (Simulation[]) hashTable.get("simulations");
    String[] independentSims = null;
    if (simulationsToRun != null && simulationsToRun.length > 0) {
        independentSims = new String[simulationsToRun.length];
        for (int i = 0; i < simulationsToRun.length; i++) {
            independentSims[i] = simulationsToRun[i].getName();
        }
    }
    VCDocument savedDocument = null;
    switch(currentDocument.getDocumentType()) {
        case BIOMODEL_DOC:
            {
                if (bAsNew) {
                    // Substitute Field Func Names-----
                    VersionableTypeVersion originalVersionableTypeVersion = null;
                    if (currentDocument.getVersion() != null) {
                        // From Opened...
                        originalVersionableTypeVersion = new VersionableTypeVersion(VersionableType.BioModelMetaData, currentDocument.getVersion());
                    }
                    documentManager.substituteFieldFuncNames((BioModel) currentDocument, originalVersionableTypeVersion);
                    // --------------------------------
                    savedDocument = documentManager.saveAsNew((BioModel) currentDocument, newName, independentSims);
                } else {
                    savedDocument = documentManager.save((BioModel) currentDocument, independentSims);
                }
                break;
            }
        case MATHMODEL_DOC:
            {
                if (bAsNew) {
                    // Substitute Field Func Names-----
                    VersionableTypeVersion originalVersionableTypeVersion = ((MathModelWindowManager) documentWindowManager).getCopyFromBioModelAppVersionableTypeVersion();
                    if (originalVersionableTypeVersion == null && currentDocument.getVersion() != null) {
                        // From Opened...
                        originalVersionableTypeVersion = new VersionableTypeVersion(VersionableType.MathModelMetaData, currentDocument.getVersion());
                    }
                    documentManager.substituteFieldFuncNames((MathModel) currentDocument, originalVersionableTypeVersion);
                    // --------------------------------
                    savedDocument = documentManager.saveAsNew((MathModel) currentDocument, newName, independentSims);
                } else {
                    savedDocument = documentManager.save((MathModel) currentDocument, independentSims);
                }
                break;
            }
        case GEOMETRY_DOC:
            {
                if (bAsNew) {
                    savedDocument = documentManager.saveAsNew((Geometry) currentDocument, newName);
                } else {
                    savedDocument = documentManager.save((Geometry) currentDocument);
                }
                break;
            }
        default:
            {
                throw new RuntimeException("unexpected document type " + currentDocument.getDocumentType().name());
            }
    }
    documentWindowManager.prepareDocumentToLoad(savedDocument, false);
    hashTable.put(SaveDocument.DOC_KEY, savedDocument);
    // generate PerformanceMonitorEvent
    long l2 = System.currentTimeMillis();
    double duration = ((double) (l2 - l1)) / 1000;
// requestManager.getAsynchMessageManager().reportPerformanceMonitorEvent(
// new PerformanceMonitorEvent(
// this, documentManager.getUser(), new PerformanceData(
// "SaveDocument.run()",
// MessageEvent.SAVING_STAT,
// new PerformanceDataEntry[] {
// new PerformanceDataEntry("document saved", savedDocument.getName()),
// new PerformanceDataEntry("remote call duration", Double.toString(duration))
// }
// )
// )
// );
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) VCDocument(org.vcell.util.document.VCDocument) VersionableTypeVersion(org.vcell.util.document.VersionableTypeVersion) DocumentManager(cbit.vcell.clientdb.DocumentManager) RequestManager(cbit.vcell.client.RequestManager) Simulation(cbit.vcell.solver.Simulation) DocumentWindowManager(cbit.vcell.client.DocumentWindowManager) BioModel(cbit.vcell.biomodel.BioModel)

Example 27 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager 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 };
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Hashtable(java.util.Hashtable) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) DocumentManager(cbit.vcell.clientdb.DocumentManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) DataFormatException(java.util.zip.DataFormatException) UserCancelException(org.vcell.util.UserCancelException) RequestManager(cbit.vcell.client.RequestManager) ClientRequestManager(cbit.vcell.client.ClientRequestManager) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) RegionImage(cbit.vcell.geometry.RegionImage) FieldDataDBOperationSpec(cbit.vcell.field.FieldDataDBOperationSpec)

Example 28 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager 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 });
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Hashtable(java.util.Hashtable) DocumentManager(cbit.vcell.clientdb.DocumentManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeMap(java.util.TreeMap) DataFormatException(java.util.zip.DataFormatException) UserCancelException(org.vcell.util.UserCancelException) Entry(java.util.Map.Entry) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FieldDataDBOperationResults(cbit.vcell.field.FieldDataDBOperationResults) FieldDataDBOperationSpec(cbit.vcell.field.FieldDataDBOperationSpec)

Example 29 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class GeometryMetaDataPanel method setDocumentManager.

/**
 * Sets the documentManager property (cbit.vcell.clientdb.DocumentManager) value.
 * @param documentManager The new value for the property.
 * @see #getDocumentManager
 */
public void setDocumentManager(DocumentManager documentManager) {
    DocumentManager oldValue = fieldDocumentManager;
    fieldDocumentManager = documentManager;
    firePropertyChange(CommonTask.DOCUMENT_MANAGER.name, oldValue, documentManager);
}
Also used : DocumentManager(cbit.vcell.clientdb.DocumentManager)

Example 30 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class ImageDbTreeModel method setDocumentManager.

/**
 * Sets the documentManager property (cbit.vcell.clientdb.DocumentManager) value.
 * @param documentManager The new value for the property.
 * @see #getDocumentManager
 */
public void setDocumentManager(DocumentManager documentManager) {
    DocumentManager oldValue = fieldDocumentManager;
    fieldDocumentManager = documentManager;
    if (oldValue != null) {
        oldValue.removeDatabaseListener(this);
    }
    if (documentManager != null) {
        documentManager.addDatabaseListener(this);
    }
    firePropertyChange(CommonTask.DOCUMENT_MANAGER.name, oldValue, documentManager);
    if (documentManager != oldValue) {
        refreshTree();
    }
}
Also used : DocumentManager(cbit.vcell.clientdb.DocumentManager)

Aggregations

DocumentManager (cbit.vcell.clientdb.DocumentManager)30 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)10 Hashtable (java.util.Hashtable)10 DocumentWindowManager (cbit.vcell.client.DocumentWindowManager)6 VCDocument (org.vcell.util.document.VCDocument)6 UserCancelException (org.vcell.util.UserCancelException)5 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)5 BioModel (cbit.vcell.biomodel.BioModel)4 Component (java.awt.Component)4 File (java.io.File)4 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)3 DatabaseWindowManager (cbit.vcell.client.DatabaseWindowManager)3 DocumentWindow (cbit.vcell.client.desktop.DocumentWindow)3 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)3 GeometryInfo (cbit.vcell.geometry.GeometryInfo)3 RegionImage (cbit.vcell.geometry.RegionImage)3 DataAccessException (org.vcell.util.DataAccessException)3 VCImageUncompressed (cbit.image.VCImageUncompressed)2 AnnotatedImageDataset (cbit.vcell.VirtualMicroscopy.importer.AnnotatedImageDataset)2 MicroscopyXmlReader (cbit.vcell.VirtualMicroscopy.importer.MicroscopyXmlReader)2