コード例 #1
0
        public void GenerateSeqItems()
        {
            ArrayList list   = new ArrayList();
            XmlNode   column = m_columnList[3];           // Glosses

            XmlViewsUtils.CollectBrowseItems(1, column, list, m_mdc, m_sda, m_layouts);
            Assert.AreEqual(1, list.Count, "got one items for glosses obj 1");
            list.Clear();
            XmlViewsUtils.CollectBrowseItems(4, column, list, m_mdc, m_sda, m_layouts);
            Assert.AreEqual(1, list.Count, "got one item for glosses obj 4");
            ManyOnePathSortItem bv = list[0] as ManyOnePathSortItem;

            Assert.AreEqual(5, bv.KeyObject);
            Assert.AreEqual(1, bv.PathLength);
            Assert.AreEqual(4, bv.PathObject(0));
            Assert.AreEqual(2010, bv.PathFlid(0));
            list.Clear();
            XmlViewsUtils.CollectBrowseItems(6, column, list, m_mdc, m_sda, m_layouts);
            Assert.AreEqual(3, list.Count, "got three items for glosses obj 6");
            int[] keys = new int[] { 7, 8, 9 };
            for (int i = 0; i < keys.Length; i++)
            {
                bv = list[i] as ManyOnePathSortItem;
                Assert.AreEqual(keys[i], bv.KeyObject);
                Assert.AreEqual(1, bv.PathLength);
                Assert.AreEqual(6, bv.PathObject(0));
                Assert.AreEqual(2010, bv.PathFlid(0));
            }
        }
コード例 #2
0
        public void GenerateAtomicItems()
        {
            ArrayList list   = new ArrayList();
            XmlNode   column = m_columnList[1];           // Etymology

            XmlViewsUtils.CollectBrowseItems(1, column, list, m_mdc, m_sda, m_layouts);
            Assert.AreEqual(1, list.Count, "got one item for etymology obj 1");
            ManyOnePathSortItem bv = list[0] as ManyOnePathSortItem;

            Assert.AreEqual(60, bv.KeyObject);
            Assert.AreEqual(1, bv.PathLength);
            Assert.AreEqual(1, bv.PathObject(0));
            Assert.AreEqual(2011, bv.PathFlid(0));
            list.Clear();
            XmlViewsUtils.CollectBrowseItems(4, column, list, m_mdc, m_sda, m_layouts);
            Assert.AreEqual(1, list.Count, "got one item for etymology obj 4");
            list.Clear();
            XmlViewsUtils.CollectBrowseItems(6, column, list, m_mdc, m_sda, m_layouts);
            Assert.AreEqual(1, list.Count, "got one item for etymology obj 6");
            bv = list[0] as ManyOnePathSortItem;
            Assert.AreEqual(61, bv.KeyObject);
            Assert.AreEqual(1, bv.PathLength);
            Assert.AreEqual(6, bv.PathObject(0));
            Assert.AreEqual(2011, bv.PathFlid(0));
        }
コード例 #3
0
ファイル: BulkPosEditor.cs プロジェクト: sillsdev/WorldPad
        /// <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());
        }
コード例 #4
0
ファイル: LayoutFinder.cs プロジェクト: sillsdev/WorldPad
        /// <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);
        }