private void CreateVirtualProperties() { m_virtualName = m_fieldName + "_" + "TypeAhead"; IVwCacheDa cda = m_sda as IVwCacheDa; IVwVirtualHandler vh = cda.GetVirtualHandlerName(m_className, m_virtualName); if (vh == null) { // Need to create virtual property. switch (m_type) { case (int)CellarModuleDefns.kcptReferenceAtom: vh = new TypeAheadAtomVh(m_tag); vh.ClassName = m_className; vh.FieldName = m_virtualName; vh.Type = m_type; cda.InstallVirtual(vh); break; case (int)CellarModuleDefns.kcptReferenceSequence: case (int)CellarModuleDefns.kcptReferenceCollection: vh = new TypeAheadSeqVh(m_tag); vh.ClassName = m_className; vh.FieldName = m_virtualName; vh.Type = (int)CellarModuleDefns.kcptReferenceSequence; cda.InstallVirtual(vh); break; default: throw new Exception("unsupported property type for type-ahead chooser"); } } m_virtualTagObj = vh.Tag; // Make the virtual handler for type-ahead names if it doesn't already exist. vh = cda.GetVirtualHandlerName("CmObject", kstrTaName); if (vh == null) { vh = new TypeAheadShortNameStringVh(m_cache); vh.ClassName = m_className; vh.FieldName = kstrTaName; vh.Type = (int)CellarModuleDefns.kcptString; cda.InstallVirtual(vh); } m_taTagName = vh.Tag; // And the general-purpose Shortname one. vh = cda.GetVirtualHandlerName("CmObject", kstrSnName); if (vh == null) { vh = new TypeAheadShortNameStringVh(m_cache); vh.ClassName = m_className; vh.FieldName = kstrSnName; vh.Type = (int)CellarModuleDefns.kcptString; cda.InstallVirtual(vh); } m_snTagName = vh.Tag; }
/// <summary> /// Looks for a node called "virtuals" and under it collects nodes of type "virtual", /// each having at least "modelclass", "virtualfield", "assemblyPath", and "class". /// Here 'class' is the name of the C# class that implements the VH, while 'modelclass' /// is the name of the virtual property. The node is passed to the VH as a constructor /// argument, so other attributes may be required. /// </summary> /// <returns>the list of installed virtual handlers</returns> public static List <IVwVirtualHandler> InstallVirtuals(XmlNode virtualsNode, FdoCache cache, bool okToFail) { List <IVwVirtualHandler> installedHandlers = new List <IVwVirtualHandler>(); foreach (XmlNode virtualNode in virtualsNode.SelectNodes("virtual")) { IVwCacheDa cda = cache.MainCacheAccessor as IVwCacheDa; IVwVirtualHandler vh = cda.GetVirtualHandlerName( XmlUtils.GetManditoryAttributeValue(virtualNode, "modelclass"), XmlUtils.GetManditoryAttributeValue(virtualNode, "virtualfield")); if (vh != null && vh is BaseVirtualHandler) { // already exists, hope it's the same one. Make sure its cache is valid. (vh as BaseVirtualHandler).Reinitialize(virtualNode, cache); installedHandlers.Add(vh); continue; } try { vh = (IVwVirtualHandler)DynamicLoader.CreateObject( virtualNode.SelectSingleNode("dynamicloaderinfo"), new object[] { virtualNode, cache }); } catch (Exception err) { if (!okToFail) { throw err; } // Otherwise we're in some special test situation or really just want the IText ones // and we ignore the problem. continue; } try { cda.InstallVirtual(vh); } catch (Exception err) { Debug.WriteLine(err.Message); throw err; } installedHandlers.Add(vh); } return(installedHandlers); }
public void InstallVirtualHandler() { CheckDisposed(); StTextParaCountVh vh = new StTextParaCountVh(); ISilDataAccess sda = m_fdoCache.MainCacheAccessor; IVwCacheDa cda = sda as IVwCacheDa; vh.ClassName = "StText"; vh.FieldName = "ParagraphCount"; vh.Type = (int)CellarModuleDefns.kcptInteger; cda.InstallVirtual(vh); // Rather than try to find a real StText, simulate one. cda.CacheVecProp(khvoTest, (int)StText.StTextTags.kflidParagraphs, new int[] { 10, 20, 30, 40 }, 4); Assert.AreEqual(4, sda.get_IntProp(khvoTest, vh.Tag)); }
public override void MakeRoot() { CheckDisposed(); base.MakeRoot(); if (DesignMode) { return; } m_fdoCache.CreateDummyID(out m_hvoRoot); // Pretend it is of our expected destination class. Very few things should care about this, // but it allows IsValidObject to return true for it, which is important when reconstructing // the root box, as happens during Refresh. m_fdoCache.VwCacheDaAccessor.CacheIntProp(m_hvoRoot, (int)CmObjectFields.kflidCmObject_Class, (int)m_clidDst); // Review JohnT: why doesn't the base class do this?? m_rootb = VwRootBoxClass.Create(); m_rootb.SetSite(this); m_sda = m_fdoCache.MainCacheAccessor; IVwCacheDa cda = m_sda as IVwCacheDa; IVwVirtualHandler vh = cda.GetVirtualHandlerName(GhostStringVirtualHandler.GhostClassName, GhostStringVirtualHandler.FieldNameForWs(m_wsToCreate)); if (vh == null) { vh = new GhostStringVirtualHandler(m_wsToCreate); cda.InstallVirtual(vh); } m_flidGhost = vh.Tag; m_rootb.DataAccess = m_sda; m_vc = new GhostStringSliceVc(m_flidGhost); // arg3 is a meaningless initial fragment, since this VC only displays one thing. m_rootb.SetRootObject(m_hvoRoot, m_vc, 1, m_styleSheet); }
/// <summary> /// This will install a virtual handler for getting and setting temporary strings in each column. /// </summary> private void InstallVirtualHandlersForColumns() { // handle editableRow attributes Debug.Assert(m_xbv != null); FdoCache cache = m_xbv.Cache; Debug.Assert(cache != null); IVwCacheDa cda = cache.MainCacheAccessor as IVwCacheDa; // install a handler for each column for (int i = 1; i <= m_columns.Count; ++i) { string sField = ksEditColumnBaseName + i; IVwVirtualHandler vh = cda.GetVirtualHandlerName( EditRowModelClass, sField); if (vh == null) { MultiStringVirtualHandler msvh = new MultiStringVirtualHandler(EditRowModelClass, sField); cda.InstallVirtual(msvh); } } }
/// <summary> /// Return the VirtualHandler for the supplied cache, creating it if needed. /// </summary> /// <param name="cda"></param> /// <returns></returns> public static ObjectSelectedVirtualHandler InstallHandler(IVwCacheDa cda) { ObjectSelectedVirtualHandler vh = (ObjectSelectedVirtualHandler)cda.GetVirtualHandlerName(className, fieldName); if (vh == null) { vh = new ObjectSelectedVirtualHandler(); vh.Type = (int)CellarModuleDefns.kcptInteger; vh.ClassName = className; vh.FieldName = fieldName; cda.InstallVirtual(vh); } return vh; }
/// <summary> /// Return the MeVirtualHandler for the supplied cache, creating it if needed. /// </summary> /// <param name="cda"></param> /// <param name="className">name of class to define prop for</param> /// <param name="fieldName">field name for virtual prop</param> /// <param name="cpt">type of property, from CellarModuleDefns</param> /// <returns></returns> public static DummyVirtualHandler InstallDummyHandler(IVwCacheDa cda, string className, string fieldName, int cpt) { DummyVirtualHandler vh = (DummyVirtualHandler)cda.GetVirtualHandlerName(className, fieldName); if (vh == null) { vh = new DummyVirtualHandler(); vh.Type = cpt; vh.ClassName = className; vh.FieldName = fieldName; cda.InstallVirtual(vh); } return vh; }
/// <summary> /// Return the MeVirtualHandler for the supplied cache, creating it if needed. /// </summary> /// <param name="cda"></param> /// <returns></returns> public static MeVirtualHandler InstallMe(IVwCacheDa cda) { MeVirtualHandler vh = (MeVirtualHandler)cda.GetVirtualHandlerName("CmObject", "Me"); if (vh == null) { vh = new MeVirtualHandler(); cda.InstallVirtual(vh); } return vh; }