/// <summary> /// Check if the field can be inserted into the given object. /// </summary> /// <param name="fdoCache"></param> /// <param name="fieldName">name of the field to be inserted</param> /// <param name="parentObj">The object where the item would be inserted, if possible.</param> /// <param name="index">index (0-based) where it will be inserted. -1 if atomic or returns false</param> /// <returns>true if we can insert into the given object</returns> protected bool CanInsertFieldIntoObj(FdoCache fdoCache, string fieldName, ICmObject parentObj, out int index) { index = -1; // atomic or not possible if (fdoCache == null || parentObj == null || (!parentObj.IsValidObject) || String.IsNullOrEmpty(fieldName)) return false; var mdc = fdoCache.ServiceLocator.GetInstance<IFwMetaDataCacheManaged>(); // class not specified, depends on the object we're testing. int flid = GetFlidIfPossible(parentObj.ClassID, fieldName, mdc); if (flid == 0) return false; // Some kind of fake field, or wrong type of object, so bail out. var type = (CellarPropertyType) mdc.GetFieldType(flid); // we can only insert new objects into virtual reference properties if (fdoCache.IsReferenceProperty(flid) && !mdc.get_IsVirtual(flid)) return false; if (type == CellarPropertyType.OwningSequence || type == CellarPropertyType.OwningCollection || type == CellarPropertyType.ReferenceCollection || type == CellarPropertyType.ReferenceSequence) { index = fdoCache.DomainDataByFlid.get_VecSize(parentObj.Hvo, flid); return true; } // if its an atomic field, see if it's already been filled. if (type == CellarPropertyType.OwningAtomic || type == CellarPropertyType.ReferenceAtomic) { return fdoCache.DomainDataByFlid.get_ObjectProp(parentObj.Hvo, flid) == 0; } return false; }
public ReferenceBaseUi(FdoCache cache, ICmObject rootObj, int referenceFlid, int targetHvo) { // determine whether this is an atomic or vector relationship. Debug.Assert(cache.IsReferenceProperty(referenceFlid)); Debug.Assert(rootObj != null); m_cache = cache; m_hvo = rootObj.Hvo; m_obj = rootObj; m_flid = referenceFlid; m_hvoTarget = targetHvo; m_targetUi = MakeUi(m_cache, m_hvoTarget); }