public void TryItOut()
		{
			var filter = new WordsUsedOnlyElsewhereFilter();
			filter.Init(Cache, null);
			var sda = new FakeDecorator((ISilDataAccessManaged)Cache.DomainDataByFlid);
			filter.DataAccess = sda;
			UndoableUnitOfWorkHelper.Do("undo", "redo", m_actionHandler,
				() =>
					{
						var wfTry = MakeWordform("try");
						ISegment seg1;
						var text1 = MakeText("try it out", out seg1);
						seg1.AnalysesRS.Add(wfTry);
						Assert.That(wfTry.FullConcordanceCount, Is.EqualTo(1));
						ManyOnePathSortItem itemTry = new ManyOnePathSortItem(wfTry);
						// Here the global count is non-zero but the corpus count is zero.
						Assert.That(filter.Accept(itemTry), Is.False, "should not accept an item which occurs elsewhere but not in corpus");
						sda.HvoToOccurrenceCount[wfTry.Hvo] = 1;
						Assert.That(filter.Accept(itemTry), Is.True, "should accept an item in an included text");
						sda.HvoToOccurrenceCount[wfTry.Hvo] = 5;
						Assert.That(filter.Accept(itemTry), Is.True, "should accept an item in an included text, even if there are other occurrences");
						var wfNowhere = MakeWordform("nowhere");
						ManyOnePathSortItem itemNowhere = new ManyOnePathSortItem(wfNowhere);
						Assert.That(filter.Accept(itemNowhere), Is.True,"should accept an item that occurs nowhere at all.");
					});
		}
Ejemplo n.º 2
0
        ///// <summary>
        ///// Initialize the filter
        ///// </summary>
        ///// <param name="cache"></param>
        ///// <param name="configuration"></param>
//		public override void Init(FdoCache cache,XmlNode filterNode)
//		{
////			m_cache = cache;
////			int hvo = m_cache.LangProject.MorphologicalDataOA.TestSetsOC.HvoArray[0];
////			m_wordSet= WfiWordSet.CreateFromDBObject(m_cache, hvo);
//		}

        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// decide whether this object should be included
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>true if the object should be included</returns>
        /// ------------------------------------------------------------------------------------
        public override bool Accept(ManyOnePathSortItem item)
        {
            int hvo = item.KeyObject;

            for (int i = m_hvos.Length - 1; i >= 0; i--)
            {
                if (m_hvos[i] == hvo)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        public override void TestSetup()
        {
            base.TestSetup();


            IManyOnePathSortItem mopsi = new ManyOnePathSortItem(Cache.LangProject);

            m_list = new ArrayList();
            m_list.Add(mopsi);
            var leFactory = Cache.ServiceLocator.GetInstance <ILexEntryFactory>();

            UndoableUnitOfWorkHelper.Do("undoit", "redoit", Cache.ActionHandlerAccessor, () =>
            {
                m_le1 = leFactory.Create();
                m_le2 = leFactory.Create();
            });
            mopsi = new ManyOnePathSortItem(Cache.LangProject.LexDbOA.Hvo, new int[] { m_le1.Hvo, m_le2.Hvo }, new int[] { 2, 3 });
            m_list.Add(mopsi);
        }
Ejemplo n.º 4
0
        public void PersistMopsiList()
        {
            var mopsi = (IManyOnePathSortItem)m_list[m_list.Count - 1];

            using (var stream = new MemoryStream())
            {
                var objRepo             = Cache.ServiceLocator.ObjectRepository;
                var originalPersistData = mopsi.PersistData(objRepo);
                using (var writer = new StreamWriter(stream))
                {
                    ManyOnePathSortItem.WriteItems(m_list, writer, objRepo, null);
                    stream.Seek(0, SeekOrigin.Begin);
                    using (var reader = new StreamReader(stream))
                    {
                        string versionStamp;
                        var    items = ManyOnePathSortItem.ReadItems(reader, objRepo, out versionStamp);
                        Assert.That(items.Count, Is.EqualTo(m_list.Count));
                        Assert.That(versionStamp, Is.Null);
                        mopsi = (IManyOnePathSortItem)items[0];
                        Assert.That(mopsi.KeyObject, Is.EqualTo(Cache.LangProject.Hvo));
                        Assert.That(mopsi.PathLength, Is.EqualTo(0));
                        // Root object is key object, if no path.
                        Assert.That(mopsi.RootObjectHvo, Is.EqualTo(Cache.LangProject.Hvo));
                        Assert.That(mopsi.RootObjectUsing(Cache), Is.EqualTo(Cache.LangProject));
                        // PathObject(0) is also the key, if no path.
                        Assert.That(mopsi.PathObject(0), Is.EqualTo(Cache.LangProject.Hvo));
                        mopsi = (IManyOnePathSortItem)items[1];
                        Assert.That(mopsi.KeyObject, Is.EqualTo(Cache.LangProject.LexDbOA.Hvo));
                        Assert.That(mopsi.PathLength, Is.EqualTo(2));
                        Assert.That(mopsi.PathFlid(0), Is.EqualTo(2));
                        Assert.That(mopsi.PathFlid(1), Is.EqualTo(3));
                        Assert.That(mopsi.PathObject(0), Is.EqualTo(m_le1.Hvo));
                        Assert.That(mopsi.PathObject(1), Is.EqualTo(m_le2.Hvo));
                        Assert.That(mopsi.PathObject(2), Is.EqualTo(Cache.LangProject.LexDbOA.Hvo), "Index one too large yields key object.");
                        Assert.That(mopsi.RootObjectHvo, Is.EqualTo(m_le1.Hvo));
                        Assert.That(mopsi.RootObjectUsing(Cache), Is.EqualTo(m_le1));
                        Assert.That(mopsi.KeyObjectUsing(Cache), Is.EqualTo(Cache.LangProject.LexDbOA));
                        Assert.That(mopsi.PersistData(objRepo), Is.EqualTo(originalPersistData));
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public void PersistMopsiList_BadGUID()
 {
     // Now make one containing a bad GUID.
     using (var stream = new MemoryStream())
     {
         var objRepo = Cache.ServiceLocator.ObjectRepository;
         using (var writer = new StreamWriter(stream))
         {
             ManyOnePathSortItem.WriteItems(m_list, writer, objRepo);
             writer.WriteLine(Convert.ToBase64String(Guid.NewGuid().ToByteArray()));
             // fake item, bad guid
             writer.Flush();
             stream.Seek(0, SeekOrigin.Begin);
             using (var reader = new StreamReader(stream))
             {
                 var items = ManyOnePathSortItem.ReadItems(reader, objRepo);
                 Assert.That(items, Is.Null);
             }
         }
     }
 }
Ejemplo n.º 6
0
		/// <summary>
		/// Gets the sort key by traversing the part tree, calling the sort method at the leaves.
		/// </summary>
		/// <param name="layout">The layout.</param>
		/// <param name="cmo">The object.</param>
		/// <param name="item">The item.</param>
		/// <param name="pathIndex">Index of the path.</param>
		/// <param name="sortedFromEnd">if set to <c>true</c> [sorted from end].</param>
		/// <returns></returns>
		private string GetKey(XmlNode layout, ICmObject cmo, ManyOnePathSortItem item, int pathIndex, bool sortedFromEnd)
		{
			if (layout == null)
				return null;

			switch (layout.Name)
			{
				case "obj":
					{
						int flid = GetFlid(layout, cmo.Hvo);
						if (pathIndex != -1 && (pathIndex == item.PathLength || flid != item.PathFlid(pathIndex)))
							// we are now off of the path
							pathIndex = -1;

						int objHvo = m_cache.GetObjProperty(cmo.Hvo, flid);
						if (objHvo != 0)
						{
							if (pathIndex != -1
								&& (pathIndex < item.PathLength - 1 && objHvo == item.PathObject(pathIndex + 1))
								 || (pathIndex == item.PathLength - 1 && objHvo == item.KeyObject))
							{
								return GetChildObjKey(layout, objHvo, item, pathIndex + 1, sortedFromEnd);
							}

							// we are off of the path
							return GetChildObjKey(layout, objHvo, item, -1, sortedFromEnd);
						}
					}
					break;

				case "seq":
					{
						int flid = GetFlid(layout, cmo.Hvo);
						if (pathIndex != -1 && (pathIndex == item.PathLength || flid != item.PathFlid(pathIndex)))
							// we are now off of the path
							pathIndex = -1;

						int size = m_cache.GetVectorSize(cmo.Hvo, flid);
						StringBuilder sb = null;
						for (int i = 0; i < size; i++)
						{
							int objHvo = m_cache.GetVectorItem(cmo.Hvo, flid, i);
							if (pathIndex != -1
								&& (pathIndex < item.PathLength - 1 && objHvo == item.PathObject(pathIndex + 1))
								|| (pathIndex == item.PathLength - 1 && objHvo == item.KeyObject))
							{
								return GetChildObjKey(layout, objHvo, item, pathIndex + 1, sortedFromEnd);
							}

							// if we are off of the path, we concatenate all vector keys to create an
							// aggregate key
							string childObjKey = GetChildObjKey(layout, objHvo, item, -1, sortedFromEnd);
							if (childObjKey != null)
							{
								if (sb == null)
									sb = new StringBuilder();
								sb.Append(childObjKey);
							}
						}
						if (sb != null)
							return sb.ToString();
					}
					break;

				case "layout":
				case "part":
					{
						string partref = XmlUtils.GetOptionalAttributeValue(layout, "ref");
						if (partref != null)
						{
							XmlNode part = XmlVc.GetNodeForPart(cmo.Hvo, partref, true, m_sda, m_layouts);
							return GetKey(part, cmo, item, pathIndex, sortedFromEnd);
						}

						foreach (XmlNode child in layout.ChildNodes)
						{
							if (child is XmlComment)
								continue;

							string key = GetKey(child, cmo, item, pathIndex, sortedFromEnd);
							if (key != null)
								return key;
						}
					}
					break;
			}
			return null;
		}
Ejemplo n.º 7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// For most of these we want to return the same thing.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="sortedFromEnd">if set to <c>true</c> [sorted from end].</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public virtual string[] SortStrings(ManyOnePathSortItem item, bool sortedFromEnd)
		{
			CheckDisposed();

			return Strings(item, sortedFromEnd);
		}
Ejemplo n.º 8
0
		private Set<int> GetDescendents(int hvoCommonAncestor, int relativesFlid)
		{
			string listPropertyName = Cache.MetaDataCacheAccessor.GetFieldName(relativesFlid);
			string parentObjName = Cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(hvoCommonAncestor).ClassName;
			string xpathToPart = "./part[@id='" + parentObjName + "-Jt-" + listPropertyName + "']";
			XmlNode pathSpec = m_parentToChildrenSpecs.SelectSingleNode(xpathToPart);
			Debug.Assert(pathSpec != null,
				String.Format("You are experiencing a rare and difficult-to-reproduce error (LT- 11443 and linked issues). If you can add any information to the issue or fix it please do. If JohnT is available please call him over. Expected to find part ({0}) in ParentClassPathsToChildren", xpathToPart));
			if (pathSpec == null)
				return new Set<int>(); // This just means we don't find a related object. Better than crashing, but not what we intend.
			// get the part spec that gives us the path from obsolete current (parent) list item object
			// to the new one.
			var vc = new XmlBrowseViewBaseVc(m_cache, null);
			var parentItem = new ManyOnePathSortItem(hvoCommonAncestor, null, null);
			var collector = new XmlBrowseViewBaseVc.ItemsCollectorEnv(null, m_cache, hvoCommonAncestor);
			vc.DisplayCell(parentItem, pathSpec, hvoCommonAncestor, collector);
			if (collector.HvosCollectedInCell != null && collector.HvosCollectedInCell.Count > 0)
			{
				return collector.HvosCollectedInCell;
			}
			return new Set<int>();
		}
Ejemplo n.º 9
0
		public override void TestSetup()
		{
			base.TestSetup();


			IManyOnePathSortItem mopsi = new ManyOnePathSortItem(Cache.LangProject);
			m_list = new ArrayList();
			m_list.Add(mopsi);
			var leFactory = Cache.ServiceLocator.GetInstance<ILexEntryFactory>();
			UndoableUnitOfWorkHelper.Do("undoit", "redoit", Cache.ActionHandlerAccessor, () =>
			{
				m_le1 = leFactory.Create();
				m_le2 = leFactory.Create();
			});
			mopsi = new ManyOnePathSortItem(Cache.LangProject.LexDbOA.Hvo, new int[] { m_le1.Hvo, m_le2.Hvo }, new int[] { 2, 3 });
			m_list.Add(mopsi);
		}
Ejemplo n.º 10
0
		///// <summary>
		///// Initialize the filter
		///// </summary>
		///// <param name="cache"></param>
		///// <param name="configuration"></param>
//		public override void Init(FdoCache cache,XmlNode filterNode)
//		{
////			m_cache = cache;
////			int hvo = m_cache.LangProject.MorphologicalDataOA.TestSetsOC.HvoArray[0];
////			m_wordSet= WfiWordSet.CreateFromDBObject(m_cache, hvo);
//		}

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// decide whether this object should be included
		/// </summary>
		/// <param name="item">The item.</param>
		/// <returns>true if the object should be included</returns>
		/// ------------------------------------------------------------------------------------
		public override bool Accept (ManyOnePathSortItem item)
		{
			int hvo = item.KeyObject;

			for(int i = m_hvos.Length-1; i>=0; i--)
			{
				if(m_hvos[i] == hvo)
					return true;
			}

			return false;
		}
Ejemplo n.º 11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// For most of these we want to return the same thing.
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		public string[] SortStrings(ManyOnePathSortItem item, bool sortedFromEnd)
		{
			return Strings(item, sortedFromEnd);
		}
Ejemplo n.º 12
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Checks if we are sorted by column of the given flid, and if so returns the hvo for that item.
		/// </summary>
		/// <param name="flid">The flid.</param>
		/// <param name="iPathFlid">The i path flid.</param>
		/// <param name="item">The item.</param>
		/// <param name="hvo">The hvo.</param>
		/// <returns>
		/// 	<c>true</c> if [is sorted by field] [the specified flid]; otherwise, <c>false</c>.
		/// </returns>
		/// ------------------------------------------------------------------------------------
		static internal bool IsSortedByField(int flid, int iPathFlid, ManyOnePathSortItem item, out int hvo)
		{
			hvo = 0;
			if (item.PathLength > iPathFlid && item.PathFlid(iPathFlid) == flid)
			{
				if ((item.PathLength > 1) && (item.PathLength != (iPathFlid + 1)))
					hvo = item.PathObject(1);
				else
					hvo = item.KeyObject;
				return true;
			}
			return false;
		}
Ejemplo n.º 13
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// We want to display the object bvi.KeyObject, or one of its pathobjects, in a
		/// column specified by colSpec.
		/// Determine the hvo and XmlNode that we should use as the root for the cell.
		/// By default, we display the first object in the path, using the base node
		/// derived from the colSpec.
		/// However, if the colSpec begins with a path compatible with bvi.PathFlid(0),
		/// we can use bvi.PathObject(1) and the appropriate derived node.
		/// If all flids match we can use bvi.KeyObject itself.
		/// If collectOuterStructParts is non-null, it accumulates containing parts
		/// that are structural, like para, span, div.
		/// </summary>
		/// <param name="bvi">The bvi.</param>
		/// <param name="colSpec">The col spec.</param>
		/// <param name="mdc">The MDC.</param>
		/// <param name="sda">The sda.</param>
		/// <param name="layouts">The layouts.</param>
		/// <param name="hvo">The hvo.</param>
		/// <param name="collectOuterStructParts">The collect outer struct parts.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public static XmlNode GetNodeToUseForColumn(ManyOnePathSortItem bvi, XmlNode colSpec,
			IFwMetaDataCache mdc, ISilDataAccess sda, LayoutCache layouts, out int hvo, List<XmlNode> collectOuterStructParts)
		{
			return GetDisplayCommandForColumn(bvi, colSpec, mdc, sda, layouts, out hvo, collectOuterStructParts).Node;
		}
Ejemplo n.º 14
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the items.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		protected abstract int[] GetItems(ManyOnePathSortItem item);
Ejemplo n.º 15
0
		/// <summary>
		/// return all the hvos for this column in the row identified by the sort item.
		/// </summary>
		/// <param name="rowItem"></param>
		/// <returns></returns>
		protected override int[] GetItems(ManyOnePathSortItem rowItem)
		{
			int hvoRootObj = rowItem.RootObject.Hvo;
			XmlBrowseViewBaseVc.ItemsCollectorEnv collector =
				new XmlBrowseViewBaseVc.ItemsCollectorEnv(null, m_cache, hvoRootObj);
			if (Vc != null && m_colSpec != null)
				this.Vc.DisplayCell(rowItem, m_colSpec, hvoRootObj, collector);
			return collector.HvosCollectedInCell.ToArray();
		}
Ejemplo n.º 16
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// decide whether this object should be included
		/// </summary>
		/// <param name="item">The item.</param>
		/// <returns>true if the object should be included</returns>
		/// ------------------------------------------------------------------------------------
		public override bool Accept(ManyOnePathSortItem item)
		{
			int[] values = GetItems(item);
			if (m_mode == ListMatchOptions.All || m_mode == ListMatchOptions.Exact)
			{
				Set<int> matches = new Set<int>(m_targets.Count);
				foreach (int hvo in values)
				{
					if (m_targets.Contains(hvo))
					{
						matches.Add(hvo);
						if (m_mode == ListMatchOptions.All && matches.Count == m_targets.Count)
							return true;
					}
					else if (m_mode == ListMatchOptions.Exact)
						return false; // found one that isn't present.
				}
				return matches.Count == m_targets.Count; // success if we found them all.
			}
			else
			{
				// any or none: look for first match
				foreach (int hvo in values)
				{
					if (m_targets.Contains(hvo))
					{
						// If we wanted any, finding one is a success; if we wanted none, finding any is a failure.
						return m_mode == ListMatchOptions.Any;
					}
				}
				// If we wanted any, not finding any is failure; if we wanted none, not finding any is success.
				return m_mode != ListMatchOptions.Any;
			}
		}
Ejemplo n.º 17
0
		/// <summary>
		/// This returns a NodeDisplayCommand containing thd node for GetNodeToUseForColumn. However, it distinguishes whether to
		/// display the children of this node or the node itself by returning the appropriate kind of NodeDisplayCommand.
		/// </summary>
		/// <param name="bvi"></param>
		/// <param name="colSpec"></param>
		/// <param name="mdc"></param>
		/// <param name="sda"></param>
		/// <param name="layouts"></param>
		/// <param name="hvo"></param>
		/// <param name="collectOuterStructParts"></param>
		/// <returns></returns>
		public static NodeDisplayCommand GetDisplayCommandForColumn(ManyOnePathSortItem bvi, XmlNode colSpec,
			IFwMetaDataCache mdc, ISilDataAccess sda, LayoutCache layouts, out int hvo, List<XmlNode> collectOuterStructParts)
		{
			XmlNode topNode = XmlBrowseViewBaseVc.GetColumnNode(colSpec, bvi.PathObject(0), sda, layouts);
			return GetDisplayCommandForColumn1(bvi, topNode, mdc, sda, layouts, 0, out hvo, collectOuterStructParts);
		}
Ejemplo n.º 18
0
		private Set<int> GetDescendents(int hvoCommonAncestor, int relativesFlid)
		{
			string listPropertyName = Cache.MetaDataCacheAccessor.GetFieldName((uint)relativesFlid);
			string parentObjName = Cache.MetaDataCacheAccessor.GetClassName((uint)m_cache.GetClassOfObject(hvoCommonAncestor));
			string xpathToPart = "./part[@id='" + parentObjName + "-Jt-" + listPropertyName + "']";
			XmlNode pathSpec = m_parentToChildrenSpecs.SelectSingleNode(xpathToPart);
			if (pathSpec == null)
				throw new ArgumentException("Expected to find part ({0}) in ParentClassPathsToChildren", xpathToPart);
			// get the part spec that gives us the path from obsolete current (parent) list item object
			// to the new one.
			using (XmlBrowseViewBaseVc vc = new XmlBrowseViewBaseVc(m_cache, null))
			{
				ManyOnePathSortItem parentItem = new ManyOnePathSortItem(hvoCommonAncestor, null, null);
				XmlBrowseViewBaseVc.ItemsCollectorEnv collector =
					new XmlBrowseViewBaseVc.ItemsCollectorEnv(null, m_cache, hvoCommonAncestor);
				vc.DisplayCell(parentItem, pathSpec, hvoCommonAncestor, collector);
				if (collector.HvosCollectedInCell != null && collector.HvosCollectedInCell.Count > 0)
				{
				   return collector.HvosCollectedInCell;
				}
			}
			return new Set<int>();
		}
Ejemplo n.º 19
0
		private string GetChildObjKey(XmlNode layout, int hvo, ManyOnePathSortItem item, int pathIndex, bool sortedFromEnd)
		{
			ICmObject childObj = CmObject.CreateFromDBObject(m_cache, hvo);
			string layoutName = XmlUtils.GetManditoryAttributeValue(layout, "layout");
			XmlNode part = XmlVc.GetNodeForPart(hvo, layoutName, true, m_sda, m_layouts);
			string key = GetKey(part, childObj, item, pathIndex, sortedFromEnd);
			if (key != null)
				return key;
			return CallSortMethod(childObj, sortedFromEnd);
		}
Ejemplo n.º 20
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// decide whether this object should be included
		/// </summary>
		/// <param name="item">The item.</param>
		/// <returns>true if the object should be included</returns>
		/// ------------------------------------------------------------------------------------
		public abstract bool Accept(ManyOnePathSortItem item);
Ejemplo n.º 21
0
		/// <summary>
		/// Get a key from the item.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="sortedFromEnd">if set to <c>true</c> [sorted from end].</param>
		/// <returns></returns>
		public override string[] SortStrings(ManyOnePathSortItem item, bool sortedFromEnd)
		{
			CheckDisposed();

			if (item.KeyCmObject == null)
				return new string[0];

			// traverse the part tree from the root, the root object and the root layout node should
			// be compatible
			XmlNode layout = XmlVc.GetNodeForPart(item.RootObject.Hvo, m_layoutName, true, m_sda, m_layouts);
			string key = GetKey(layout, item.RootObject, item, 0, sortedFromEnd);
			if (key == null)
			{
				// the root object sort method is not tried in GetKey
				key = CallSortMethod(item.RootObject, sortedFromEnd);

				if (key == null)
				{
					// try calling the sort method on the key object
					key = CallSortMethod(item.KeyCmObject, sortedFromEnd);

					if (key == null)
					{
						// Try the default fallback if we can't find the method.
						key = item.KeyCmObject.SortKey ?? "";
						if (sortedFromEnd)
							key = StringUtils.ReverseString(key);

						key = key + " " + item.KeyCmObject.SortKey2Alpha;
					}
				}
			}

			return new string[] {key};
		}
Ejemplo n.º 22
0
		/// ------------------------------------------------------------------------------------------
		/// <summary>
		/// decide whether this object should be included
		/// </summary>
		/// <param name="item">The item.</param>
		/// <returns>true if the object should be included</returns>
		/// ------------------------------------------------------------------------------------------
		public override bool Accept(ManyOnePathSortItem item)
		{
			foreach (RecordFilter f in m_filters)
				if (!f.Accept(item))
					return false;
			return true;
		}
Ejemplo n.º 23
0
		/// <summary>
		/// Default is to return the strings for the key object.
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		public string[] Strings(ManyOnePathSortItem item, bool sortedFromEnd)
		{
			string[] result = Strings(item.KeyObject);
			if (sortedFromEnd)
				for(int i = 0; i < result.Length; i++)
					result[i] = StringUtils.ReverseString(result[i]);

			return result;
		}
Ejemplo n.º 24
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// decide whether this object should be included
		/// </summary>
		/// <param name="item"></param>
		/// <returns>true if the object should be included</returns>
		/// ------------------------------------------------------------------------------------
		public override bool Accept (ManyOnePathSortItem item)
		{
			ICmObject obj = item.KeyCmObject;
			if (!(obj is ICmBaseAnnotation))
				return false;//it's not a base annotation

			ICmBaseAnnotation annotation = (ICmBaseAnnotation)obj;
			if (annotation.BeginObjectRAHvo <= 0)
				return false;
			int cls = obj.Cache.GetClassOfObject(annotation.BeginObjectRAHvo);
			bool x = m_classIds.Contains(cls);
			foreach(uint i in m_classIds)
			{
				if ( i == cls)
					return true;
			}
			return false;
		}
Ejemplo n.º 25
0
		public ITsString Key(ManyOnePathSortItem item)
		{
			throw new NotImplementedException("Don't have new Key function implemented on class " + this.GetType());
		}
Ejemplo n.º 26
0
		/// <summary>
		/// Recursive implementation method for GetDisplayCommandForColumn.
		/// </summary>
		/// <param name="bvi"></param>
		/// <param name="node"></param>
		/// <param name="mdc"></param>
		/// <param name="sda"></param>
		/// <param name="layouts"></param>
		/// <param name="depth"></param>
		/// <param name="hvo"></param>
		/// <param name="collectOuterStructParts"></param>
		/// <returns></returns>
		static NodeDisplayCommand GetDisplayCommandForColumn1(ManyOnePathSortItem bvi, XmlNode node,
			IFwMetaDataCache mdc, ISilDataAccess sda, LayoutCache layouts, int depth,
			out int hvo, List<XmlNode> collectOuterStructParts)
		{
			hvo = bvi.PathObject(depth); // default
			switch(node.Name)
			{
			case "obj":
			case "seq":
			{
				// These two cases are the same here, because if the field matches, the object
				// that determines the next step comes from the bvi, not from one or many items
				// in the property.

				if (bvi.PathLength == depth)
				{
					// No more path, we display the final object using the node we've deduced is
					// appropriate for it.
					// (We could put this test outside the switch. But then we don't dig into
					// layout, para, span, etc elements at the end of the chain. It's more
					// consistent if we always dig as deep as we can.
					hvo = bvi.KeyObject;
					return new NodeDisplayCommand(node);
				}

				int clsid = sda.get_IntProp(bvi.PathObject(depth), (int)CmObjectFields.kflidCmObject_Class);
				int flid = (int)mdc.GetFieldId2((uint)clsid, XmlUtils.GetManditoryAttributeValue(node, "field"), true);
				if (flid != bvi.PathFlid(depth))
					return new NodeDisplayCommand(node); // different field, can't dig deeper.
				int hvoDst = bvi.PathObject(depth + 1);
				// If the path object has been deleted, fall back to displaying whatever the property currently holds.
				if (sda.get_IntProp(hvoDst, (int)CmObjectFields.kflidCmObject_Class) == 0)
					return new NodeDisplayCommand(node); // different field, can't dig deeper.
				// At this point we have to mimic the process that XmlVc uses to come up with the
				// node that will be used to process the destination item.
				XmlNode dstNode = GetNodeForRelatedObject(hvoDst, null, node, layouts, sda);
				return GetDisplayCommandForColumn1(bvi, dstNode, mdc, sda, layouts, depth + 1, out hvo, collectOuterStructParts);
			}
			case "para":
			case "span":
			case "div":
			case "concpara":
			case "innerpile":
			{
				XmlNode mainChild = FindMainChild(node);
				if (mainChild == null)
					return new NodeDisplayCommand(node); // can't usefully go further.
				if (collectOuterStructParts != null)
					collectOuterStructParts.Add(node);
				return GetDisplayCommandForColumn1(bvi, mainChild, mdc, sda, layouts, depth, out hvo, collectOuterStructParts);
			}
				// Review JohnT: In XmlVc, "part" is the one thing that calls ProcessChildren with non-null caller.
				// this should make some difference here, but I can't figure what yet, or come up with a test that fails.
				// We may need a "caller" argument to pass this down so it can be used in GetNodeForRelatedObject.
			case "part":
			{
				string layoutName = XmlUtils.GetOptionalAttributeValue(node, "ref");
				if (layoutName != null)
				{
					// It's actually a part ref, in a layout, not a part looked up by one!
					// Get the node it refers to, and make a command to process its children.
					XmlNode part = XmlVc.GetNodeForPart(hvo, layoutName, false, sda, layouts);
					if (part != null)
						return new NodeChildrenDisplayCommand(part); // display this object using the children of the part referenced.
					else
						return new NodeDisplayCommand(node); // no matching part, do default.
				}

				// These are almost the same, but are never added to collectOuterStructParts.
				// Also, expecially in the case of 'layout', they may result from unification, and be meaningless
				// except for their children; in any case, the children are all we want to process.
				// This is the main reason we return a command, not just a node: this case has to return the subclass.
				XmlNode mainChild = FindMainChild(node);
				if (mainChild == null)
					return new NodeChildrenDisplayCommand(node); // can't usefully go further.
				return GetDisplayCommandForColumn1(bvi, mainChild, mdc, sda, layouts, depth, out hvo, collectOuterStructParts);
			}
			case "column":
			case "layout":
			{

				// These are almost the same as para, span, etc, but are never added to collectOuterStructParts.
				// Also, expecially in the case of 'layout', they may result from unification, and be meaningless
				// except for their children; in any case, the children are all we want to process.
				// This is the main reason we return a command, not just a node: this case has to return the subclass.
				XmlNode mainChild = FindMainChild(node);
				if (mainChild == null)
					return new NodeChildrenDisplayCommand(node); // can't usefully go further.
				return GetDisplayCommandForColumn1(bvi, mainChild, mdc, sda, layouts, depth, out hvo, collectOuterStructParts);
			}
			default:
				// If we can't find anything clever to do, we display the object at the
				// current level using the current node.
				return new NodeDisplayCommand(node);
			}
		}
Ejemplo n.º 27
0
		/// ------------------------------------------------------------------------------------------
		/// <summary>
		/// decide whether this object should be included
		/// </summary>
		/// <param name="item">The item.</param>
		/// <returns>true if the object should be included</returns>
		/// ------------------------------------------------------------------------------------------
		public override bool Accept(ManyOnePathSortItem item)
		{
			return Matcher.Accept(m_finder.Key(item));
		}
Ejemplo n.º 28
0
		const int maxDigits = 10; // Int32.MaxValue.ToString().Length;, but that is not 'const'!

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get a key from the item for sorting. Add enough leading zeros so string comparison works.
		/// Note: negative number case not tested, for lack of a current example where it is possible.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="sortedFromEnd">if set to <c>true</c> [sorted from end].</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public override string[] SortStrings(ManyOnePathSortItem item, bool sortedFromEnd)
		{
			CheckDisposed();

			string[] baseResult = base.SortStrings(item, sortedFromEnd);
			if (sortedFromEnd)
				return baseResult; // what on earth would it mean??
			if (baseResult.Length != 1)
				return baseResult;
			string sVal = baseResult[0];
			if (sVal.Length == 0)
				return new string[] { new String('0', maxDigits) };
			string prefix = sVal.Substring(0,1);
			if (prefix == "-")
				sVal = sVal.Substring(1); // strip off the minus
			else
				prefix = ""; // not negated, no prefix needed.
			if (sVal.Length == maxDigits)
				return new string[] { prefix + sVal };
			else
				return new string[] { prefix + new String('0', maxDigits - sVal.Length) + sVal };
		}
Ejemplo n.º 29
0
		/// ------------------------------------------------------------------------------------------
		/// <summary>
		/// decide whether this object should be included
		/// </summary>
		/// <param name="item">The item.</param>
		/// <returns>true if the object should be included</returns>
		/// ------------------------------------------------------------------------------------------
		public override bool Accept(ManyOnePathSortItem item)
		{
			return true;
		}
Ejemplo n.º 30
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Figure the node and hvo that correspond to the particular sort item,
		/// and generate its key. This figures out the XML needed for the particular
		/// key object, and interprets it to make a key.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="sortedFromEnd"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public string[] Strings(ManyOnePathSortItem item, bool sortedFromEnd)
		{
			CheckDisposed();

			string result = Key(item, true).Text;
			if (result == null)
				return new string[0];
			else
			{
				if (sortedFromEnd)
					result = StringUtils.ReverseString(result);

				return new string[] { result };
			}
		}
Ejemplo n.º 31
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Keys the specified item.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public ITsString Key(ManyOnePathSortItem item)
		{
			CheckDisposed();

			return Key(item, false);
		}
Ejemplo n.º 32
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Keys the specified item.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="fForSorting">if set to <c>true</c> [f for sorting].</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public ITsString Key(ManyOnePathSortItem item, bool fForSorting)
		{
			CheckDisposed();

			if (m_cache == null)
				throw new ApplicationException("There's no way the browse VC (m_vc) can get a string in its current state.");
			int hvo = item.RootObject.Hvo;
			TsStringCollectorEnv collector;
			if (fForSorting)
			{
				collector = new SortCollectorEnv(null, m_cache.MainCacheAccessor, hvo);
			}
			else
			{
				collector = new TsStringCollectorEnv(null, m_cache.MainCacheAccessor, hvo);
			}

			// This will check to see if the VC is either null or disposed.  The disposed check is neccesary because
			// there are several instances where we can have a reference to an instance that was disposed, which will
			// cause problems later on.
			// Enhance CurtisH/EricP: If this VC gets used in other places, rather than adding more checks like this one,
			// it may be better to refactor XWorksViewBase to cause it to reload the sorter and filter from persistence
			// every time the tool is changed
			if (m_vc == null || m_vc.IsDisposed)
			{
				m_vc = new XmlBrowseViewBaseVc(m_cache, m_stringTbl);
			}
			else
			{
				if (m_vc.Cache == null)
					m_vc.Cache = m_cache;
				if (m_vc.Cache == null)
					throw new ApplicationException("There's no way the browse VC (m_vc) can get a string in its current state.");
				if (m_vc.StringTbl == null)
					m_vc.StringTbl = m_stringTbl;
			}
			m_vc.DisplayCell(item, m_colSpec, hvo, collector);
			return collector.Result;
		}
Ejemplo n.º 33
0
		/// <summary>
		/// Get the items to be compared against the filter.
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		protected override int[] GetItems(ManyOnePathSortItem item)
		{
			ISilDataAccess sda = m_cache.MainCacheAccessor;
			List<int> results = new List<int>();
			if (item.PathLength > 0 && item.PathFlid(0) == kflidMsas)
			{
				// sorted by MSA, match just the one MSA.
				// I don't think this path can occur with the current XML spec where this is used.
				int hvoMsa;
				if (item.PathLength > 1)
					hvoMsa = item.PathObject(1);
				else
					hvoMsa = item.KeyObject;
				GetItemsForMsaType(sda, ref results, hvoMsa);
			}
			else if (item.PathLength >= 1 && item.PathFlid(0) == kflidEntrySenses)
			{
				// sorted in a way that shows one sense per row, test that sense's MSA.
				int hvoSense;
				if (item.PathLength > 1)
					hvoSense = item.PathObject(1);
				else
					hvoSense = item.KeyObject;
				int hvoMsa = sda.get_ObjectProp(hvoSense, (int)LexSense.LexSenseTags.kflidMorphoSyntaxAnalysis);
				GetItemsForMsaType(sda, ref results, hvoMsa);
			}
			else
			{
				int hvoEntry = item.RootObject.Hvo;
				int cmsa = sda.get_VecSize(hvoEntry, kflidMsas);
				for (int imsa = 0; imsa < cmsa; imsa++)
				{
					int hvoMsa = sda.get_VecItem(hvoEntry, kflidMsas, imsa);
					GetItemsForMsaType(sda, ref results, hvoMsa);
				}
			}
			return results.ToArray();
		}
Ejemplo n.º 34
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Given a ManyOnePathSortItem that describes one of the rows in the view, and a node
		/// that configures one of the columns, make the required calls to the VwEnv to display the cell
		/// contents. This is also used by the LayoutFinder.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="node">The node.</param>
		/// <param name="hvo">The hvo.</param>
		/// <param name="vwenv">The vwenv.</param>
		/// ------------------------------------------------------------------------------------
		public void DisplayCell(ManyOnePathSortItem item, XmlNode node, int hvo, IVwEnv vwenv)
		{
			CheckDisposed();

			List<XmlNode> outerParts = new List<XmlNode>();
			int hvoToDisplay;
			NodeDisplayCommand dispCommand = XmlViewsUtils.GetDisplayCommandForColumn(item, node, m_cache.MetaDataCacheAccessor,
				m_cache.MainCacheAccessor, m_layouts, out hvoToDisplay, outerParts);
			// See if the column has a writing system established for it.
			try
			{
				if (node.Name == "column")
				{
					SetForcedWs(node);
				}
				OpenOuterParts(outerParts, vwenv, hvoToDisplay);
				if (hvoToDisplay == hvo)
					dispCommand.PerformDisplay(this, 0, hvo, vwenv);
				else
				{
					int fragId = GetId(dispCommand, m_idToDisplayCommand, m_displayCommandToId);
					vwenv.AddObj(hvoToDisplay, this, fragId);
				}
				//ProcessChildren(nodeToProcess, vwenv, hvoToDisplay, null);
				CloseOuterParts(outerParts, vwenv);
			}
			finally
			{
				// reset the ws for next column in the row.
				WsForce = 0;
			}
		}