Search in sources :

Example 6 with FieldDataFileOperationResults

use of cbit.vcell.field.io.FieldDataFileOperationResults in project vcell by virtualcell.

the class FieldDataWindowManager method findReferencingModels.

public boolean findReferencingModels(final ExternalDataIdentifier targetExtDataID, boolean bShowReferencingModelsList) throws DataAccessException, UserCancelException {
    ReferenceQuerySpec rqs = new ReferenceQuerySpec(targetExtDataID);
    ReferenceQueryResult rqr = getRequestManager().getDocumentManager().findReferences(rqs);
    VersionableTypeVersion[] dependants = null;
    Hashtable<VersionableTypeVersion, String[]> choices = new Hashtable<VersionableTypeVersion, String[]>();
    boolean bDanglingReferences = false;
    VersionableType bioModelType = VersionableType.BioModelMetaData;
    VersionableType mathModelType = VersionableType.MathModelMetaData;
    if (rqr != null) {
        dependants = (rqr.getVersionableFamily().bDependants() ? rqr.getVersionableFamily().getUniqueDependants() : null);
        if (dependants != null) {
            for (int i = 0; i < dependants.length; i += 1) {
                boolean isBioModel = dependants[i].getVType().equals(bioModelType);
                boolean isTop = isBioModel || dependants[i].getVType().equals(mathModelType);
                if (isTop) {
                    VersionableRelationship[] vrArr2 = rqr.getVersionableFamily().getDependantRelationships();
                    for (int j = 0; j < vrArr2.length; j += 1) {
                        if ((vrArr2[j].from() == dependants[i]) && vrArr2[j].to().getVType().equals((isBioModel ? VersionableType.SimulationContext : VersionableType.MathDescription))) {
                            for (int k = 0; k < vrArr2.length; k += 1) {
                                boolean bAdd = false;
                                if (k == j && vrArr2[k].from().getVType().equals(mathModelType)) {
                                    bAdd = true;
                                }
                                if ((vrArr2[k].from() == vrArr2[j].to()) && vrArr2[k].to().getVType().equals(VersionableType.MathDescription)) {
                                    bAdd = true;
                                }
                                if (bAdd) {
                                    choices.put(dependants[i], new String[] { dependants[i].getVersion().getName(), (isBioModel ? bioModelType.getTypeName() : mathModelType.getTypeName()), (isBioModel ? vrArr2[k].from().getVersion().getName() : ""), dependants[i].getVersion().getVersionKey().toString() });
                                }
                            }
                        }
                    }
                }
            }
            bDanglingReferences = (choices.size() == 0);
        } else {
            bDanglingReferences = true;
        }
    }
    // FieldDataFileOperationResults fdfor = getRequestManager().getDocumentManager().fieldDataFileOperation(
    // FieldDataFileOperationSpec.createDependantFuncsFieldDataFileOperationSpec(targetExtDataID));
    FieldDataFileOperationResults fdfor = null;
    boolean bHasReferences = false;
    if (choices.size() > 0 || fdfor != null) {
        bHasReferences = true;
        if (bShowReferencingModelsList) {
            String[] columnNames = new String[] { "Model", "Type", "Description" };
            Vector<VersionableType> varTypeV = new Vector<VersionableType>();
            Vector<KeyValue> keyValV = new Vector<KeyValue>();
            Vector<String[]> choicesV = new Vector<String[]>();
            String[][] modelListData = choices.values().toArray(new String[0][0]);
            for (int i = 0; i < modelListData.length; i++) {
                choicesV.add(new String[] { modelListData[i][0], modelListData[i][1], "Model Variable - " + (modelListData[i][2].length() == 0 ? "" : "App='" + modelListData[i][2] + "'") + " version[" + modelListData[i][3] + "]" });
                varTypeV.add((modelListData[i][1].equals(bioModelType.getTypeName()) ? bioModelType : mathModelType));
                keyValV.add(new KeyValue(modelListData[i][3]));
            }
            for (int i = 0; fdfor != null && i < fdfor.dependantFunctionInfo.length; i++) {
                String functionNames = "";
                for (int j = 0; j < fdfor.dependantFunctionInfo[i].funcNames.length; j++) {
                    functionNames += (j > 0 ? "," : "") + fdfor.dependantFunctionInfo[i].funcNames[j];
                }
                choicesV.add(new String[] { fdfor.dependantFunctionInfo[i].referenceSourceName, fdfor.dependantFunctionInfo[i].referenceSourceType, "Data Viewer Function(s) '" + functionNames + "' - " + (fdfor.dependantFunctionInfo[i].applicationName == null ? "" : "App='" + fdfor.dependantFunctionInfo[i].applicationName + "' ") + (fdfor.dependantFunctionInfo[i].simulationName == null ? "" : "Sim='" + fdfor.dependantFunctionInfo[i].simulationName + "' ") + "version[" + fdfor.dependantFunctionInfo[i].refSourceVersionDate + "]" });
                if (fdfor.dependantFunctionInfo[i].referenceSourceType.equals(FieldDataFileOperationResults.FieldDataReferenceInfo.FIELDDATATYPENAME)) {
                    varTypeV.add(null);
                } else if (fdfor.dependantFunctionInfo[i].referenceSourceType.equals(bioModelType.getTypeName())) {
                    varTypeV.add(bioModelType);
                } else if (fdfor.dependantFunctionInfo[i].referenceSourceType.equals(mathModelType.getTypeName())) {
                    varTypeV.add(mathModelType);
                } else {
                    throw new IllegalArgumentException("Unknown reference source type " + fdfor.dependantFunctionInfo[i].referenceSourceType);
                }
                keyValV.add(fdfor.dependantFunctionInfo[i].refSourceVersionKey);
            }
            int[] selectionArr = PopupGenerator.showComponentOKCancelTableList(getComponent(), "References to Field Data (Select To Open) " + targetExtDataID.getName(), columnNames, choicesV.toArray(new String[0][0]), ListSelectionModel.SINGLE_SELECTION);
            if (selectionArr != null && selectionArr.length > 0) {
                if (varTypeV.elementAt(selectionArr[0]) != null) {
                    if (varTypeV.elementAt(selectionArr[0]).equals(bioModelType)) {
                        BioModelInfo bmi = getRequestManager().getDocumentManager().getBioModelInfo(keyValV.elementAt(selectionArr[0]));
                        getRequestManager().openDocument(bmi, FieldDataWindowManager.this, true);
                    } else if (varTypeV.elementAt(selectionArr[0]).equals(mathModelType)) {
                        MathModelInfo mmi = getRequestManager().getDocumentManager().getMathModelInfo(keyValV.elementAt(selectionArr[0]));
                        getRequestManager().openDocument(mmi, FieldDataWindowManager.this, true);
                    } else {
                        throw new IllegalArgumentException("Not expecting varType " + varTypeV.elementAt(selectionArr[0]));
                    }
                } else {
                    PopupGenerator.showInfoDialog(this, "use FiledDataManager to view FieldData '" + choicesV.elementAt(selectionArr[0])[0] + "'");
                }
            }
        }
    } else {
        if (!bDanglingReferences) {
            bHasReferences = false;
            if (bShowReferencingModelsList) {
                PopupGenerator.showInfoDialog(this, "No Model references found for Field Data " + targetExtDataID.getName());
            }
        } else {
            bHasReferences = true;
            if (bShowReferencingModelsList) {
                PopupGenerator.showInfoDialog(this, "No current Model references found.\n" + "Field Data has internal database references from\n" + "previously linked Model(s) that have been deleted.\n" + "Note: Field Data '" + targetExtDataID.getName() + "' is not deletable\n" + "until database is culled (daily).");
            }
        }
    }
    return bHasReferences;
}
Also used : FieldDataFileOperationResults(cbit.vcell.field.io.FieldDataFileOperationResults) KeyValue(org.vcell.util.document.KeyValue) VersionableTypeVersion(org.vcell.util.document.VersionableTypeVersion) ReferenceQueryResult(org.vcell.util.document.ReferenceQueryResult) Hashtable(java.util.Hashtable) BioModelInfo(org.vcell.util.document.BioModelInfo) MathModelInfo(org.vcell.util.document.MathModelInfo) VersionableType(org.vcell.util.document.VersionableType) VersionableRelationship(org.vcell.util.document.VersionableRelationship) ReferenceQuerySpec(org.vcell.util.document.ReferenceQuerySpec) Vector(java.util.Vector)

Aggregations

FieldDataFileOperationResults (cbit.vcell.field.io.FieldDataFileOperationResults)6 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 Hashtable (java.util.Hashtable)3 ClientRequestManager (cbit.vcell.client.ClientRequestManager)2 RequestManager (cbit.vcell.client.RequestManager)2 FieldDataDBOperationResults (cbit.vcell.field.FieldDataDBOperationResults)2 FieldDataDBOperationSpec (cbit.vcell.field.FieldDataDBOperationSpec)2 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)2 MathException (cbit.vcell.math.MathException)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 CartesianMesh (cbit.vcell.solvers.CartesianMesh)2 XmlParseException (cbit.vcell.xml.XmlParseException)2 Vector (java.util.Vector)2 DataAccessException (org.vcell.util.DataAccessException)2 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)2 ImageException (cbit.image.ImageException)1 VCImageUncompressed (cbit.image.VCImageUncompressed)1 FieldDataWindowManager (cbit.vcell.client.FieldDataWindowManager)1 RegionImage (cbit.vcell.geometry.RegionImage)1