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"); IManyOnePathSortItem bv = list[0] as IManyOnePathSortItem; 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 IManyOnePathSortItem; Assert.AreEqual(61, bv.KeyObject); Assert.AreEqual(1, bv.PathLength); Assert.AreEqual(6, bv.PathObject(0)); Assert.AreEqual(2011, bv.PathFlid(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"); IManyOnePathSortItem bv = list[0] as IManyOnePathSortItem; 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 IManyOnePathSortItem; Assert.AreEqual(keys[i], bv.KeyObject); Assert.AreEqual(1, bv.PathLength); Assert.AreEqual(6, bv.PathObject(0)); Assert.AreEqual(2010, bv.PathFlid(0)); } }
public override bool Accept(IManyOnePathSortItem item) { int OccurrenceCount = m_sda.get_IntProp(item.RootObjectHvo, m_flid); if (OccurrenceCount != 0) return true; // occurs in our corpus, we want to show it. IWfiWordform wf = (IWfiWordform)item.RootObjectUsing(m_cache); // Otherwise we want it only if it does NOT occur somewhere else. return wf.FullConcordanceCount == 0; }
private string[] GetChildObjKey(XmlNode layout, int hvo, IManyOnePathSortItem item, int pathIndex, bool sortedFromEnd) { ICmObject childObj = m_cache.ServiceLocator.ObjectRepository.GetObject(hvo); string layoutName = XmlUtils.GetOptionalAttributeValue(layout, "layout"); XmlNode part = XmlVc.GetNodeForPart(hvo, layoutName, true, m_sda, m_layouts); var key = GetKey(part, childObj, item, pathIndex, sortedFromEnd); if (key != null) { return(key); } return(CallSortMethod(childObj, sortedFromEnd)); }
public override bool Accept(IManyOnePathSortItem item) { int OccurrenceCount = m_sda.get_IntProp(item.RootObjectHvo, m_flid); if (OccurrenceCount != 0) { return(true); // occurs in our corpus, we want to show it. } IWfiWordform wf = (IWfiWordform)item.RootObjectUsing(m_cache); // Otherwise we want it only if it does NOT occur somewhere else. return(wf.FullConcordanceCount == 0); }
public void DisplayAtomicPathObject() { ArrayList list = new ArrayList(); XmlNode column = m_columnList[1]; XmlViewsUtils.CollectBrowseItems(1, column, list, m_mdc, m_sda, m_layouts); IManyOnePathSortItem bvi = list[0] as IManyOnePathSortItem; // Try on first column. Nothing in the path matches, but we still dig inside // the span. int useHvo; List <XmlNode> collectStructNodes = new List <XmlNode>(); XmlNode useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[0], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(1, useHvo); CheckDebugId(useNode, "LexemeCf"); Assert.AreEqual(1, collectStructNodes.Count); CheckDebugId(collectStructNodes[0], "LexemeSpan"); // Try on matching column. collectStructNodes.Clear(); useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[1], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(bvi.KeyObject, useHvo); CheckDebugId(useNode, "EtymologyComment"); Assert.AreEqual(1, collectStructNodes.Count); XmlNode structNode1 = collectStructNodes[0]; CheckDebugId(structNode1, "EtymologySpan"); // Try on a column involving a lookup. This affects the node output. collectStructNodes.Clear(); useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[2], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(1, useHvo); CheckDebugId(useNode, "EntryMsaSeq"); Assert.AreEqual(1, collectStructNodes.Count); structNode1 = collectStructNodes[0]; CheckDebugId(structNode1, "EntryMsasDiv"); // On a different view of the Etymology, we should still get the Etymology object. collectStructNodes.Clear(); useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[6], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(bvi.KeyObject, useHvo); CheckDebugId(useNode, "EtymologyComment2"); // But this column has no structural nodes. Assert.AreEqual(0, collectStructNodes.Count); }
///// <summary> ///// Initialize the filter ///// </summary> ///// <param name="cache"></param> ///// <param name="configuration"></param> // public override void Init(LcmCache cache,XmlNode filterNode) // { //// m_cache = cache; //// int hvo = m_cache.LangProject.MorphologicalDataOA.TestSetsOC.HvoArray[0]; //// m_wordSet= IWfiWordSet.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(IManyOnePathSortItem item) { int hvo = item.KeyObject; for (int i = m_hvos.Length - 1; i >= 0; i--) { if (m_hvos[i] == hvo) { return(true); } } return(false); }
/// ------------------------------------------------------------------------------------ /// <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(IManyOnePathSortItem item, bool fForSorting) { 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.RootObjectHvo; TsStringCollectorEnv collector; if (fForSorting) { collector = new SortCollectorEnv(null, m_sda, hvo); } else { collector = new TsStringCollectorEnv(null, m_sda, 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 = new XmlBrowseViewBaseVc(m_cache, m_stringTbl); m_vc.SuppressPictures = true; // we won't dispose of it, so it mustn't make pictures (which we don't need) m_vc.DataAccess = m_sda; } 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); }
/// <summary> /// Get the items to be compared against the filter. /// </summary> /// <param name="item"></param> /// <returns></returns> protected override int[] GetItems(IManyOnePathSortItem item) { ISilDataAccess sda = m_cache.DomainDataByFlid; 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, LexSenseTags.kflidMorphoSyntaxAnalysis); GetItemsForMsaType(sda, ref results, hvoMsa); } else { int hvoEntry = item.RootObjectHvo; 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()); }
/// ------------------------------------------------------------------------------------ /// <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(IManyOnePathSortItem item, bool sortedFromEnd) { string result = Key(item, true).Text; if (result == null) { return(new string[0]); } else { if (sortedFromEnd) { result = TsStringUtils.ReverseString(result); } return(new string[] { result }); } }
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. /// /// Collator sorting generally ignores the minus sign as being a hyphen. So we have /// to be tricky handling negative numbers. Nine's complement with an inverted sign /// digit should do the trick... /// </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(IManyOnePathSortItem item, bool sortedFromEnd) { 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[] { "9" + new String('0', maxDigits) } } ; string prefix; char chFiller; if (sVal[0] == '-') { sVal = NinesComplement(sVal.Substring(1)); prefix = "0"; // negative numbers come first. chFiller = '9'; } else { prefix = "9"; // positive numbers come later. chFiller = '0'; } if (sVal.Length == maxDigits) { return new string[] { prefix + sVal } } ; else { return new string[] { prefix + new String(chFiller, maxDigits - sVal.Length) + sVal } }; }
public void DisplayPathlessObject() { ArrayList list = new ArrayList(); XmlNode column = m_columnList[0]; XmlViewsUtils.CollectBrowseItems(1, column, list, m_mdc, m_sda, m_layouts); IManyOnePathSortItem bvi = list[0] as IManyOnePathSortItem; // Try on original column. We get original object since there's no path, // but we still dig inside the span int useHvo; List <XmlNode> collectStructNodes = new List <XmlNode>(); XmlNode useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[0], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(1, useHvo); CheckDebugId(useNode, "LexemeCf"); Assert.AreEqual(1, collectStructNodes.Count); CheckDebugId(collectStructNodes[0], "LexemeSpan"); // Try on another column. Again we get original object, and dig inside span collectStructNodes.Clear(); useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[1], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(1, useHvo); CheckDebugId(useNode, "EtymologyObj"); Assert.AreEqual(1, collectStructNodes.Count); XmlNode structNode1 = collectStructNodes[0]; CheckDebugId(structNode1, "EtymologySpan"); // Try on a column involving a lookup. This affects the node output. collectStructNodes.Clear(); useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[2], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(1, useHvo); CheckDebugId(useNode, "EntryMsaSeq"); Assert.AreEqual(1, collectStructNodes.Count); structNode1 = collectStructNodes[0]; CheckDebugId(structNode1, "EntryMsasDiv"); }
public void GeneratePathlessItems() { ArrayList list = new ArrayList(); XmlNode column = m_columnList[0]; XmlViewsUtils.CollectBrowseItems(1, column, list, m_mdc, m_sda, m_layouts); Assert.AreEqual(1, list.Count, "got one item for lexeme obj 1"); IManyOnePathSortItem bv = list[0] as IManyOnePathSortItem; Assert.AreEqual(1, bv.KeyObject); Assert.AreEqual(0, bv.PathLength); list.Clear(); XmlViewsUtils.CollectBrowseItems(4, column, list, m_mdc, m_sda, m_layouts); Assert.AreEqual(1, list.Count, "got one item for lexeme obj 4"); list.Clear(); XmlViewsUtils.CollectBrowseItems(6, column, list, m_mdc, m_sda, m_layouts); Assert.AreEqual(1, list.Count, "got one item for lexeme obj 6"); bv = list[0] as IManyOnePathSortItem; Assert.AreEqual(6, bv.KeyObject); Assert.AreEqual(0, bv.PathLength); }
/// <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(IManyOnePathSortItem item, bool sortedFromEnd) { if (item.KeyObject == 0) { 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.RootObjectHvo, m_layoutName, true, m_sda, m_layouts); var rootObject = item.RootObjectUsing(m_cache); var key = GetKey(layout, rootObject, item, 0, sortedFromEnd); if (key == null) { // the root object sort method is not tried in GetKey key = CallSortMethod(rootObject, sortedFromEnd); if (key == null) { // try calling the sort method on the key object var keyCmObjectUsing = item.KeyObjectUsing(m_cache); key = CallSortMethod(keyCmObjectUsing, sortedFromEnd); if (key == null) { // Try the default fallback if we can't find the method. var firstKey = keyCmObjectUsing.SortKey ?? ""; if (sortedFromEnd) { firstKey = TsStringUtils.ReverseString(firstKey); } return(new [] { firstKey, keyCmObjectUsing.SortKey2Alpha }); } } } return(key); }
/// <summary> /// Default is to return the strings for the key object. /// </summary> /// <param name="item"></param> /// <returns></returns> public string[] Strings(IManyOnePathSortItem item, bool sortedFromEnd) { string[] result = Strings(item.KeyObject); if (sortedFromEnd) for(int i = 0; i < result.Length; i++) result[i] = TsStringUtils.ReverseString(result[i]); return result; }
/// ------------------------------------------------------------------------------------ /// <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(IManyOnePathSortItem item, bool fForSorting) { 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.RootObjectHvo; TsStringCollectorEnv collector; if (fForSorting) { collector = new SortCollectorEnv(null, m_sda, hvo); } else { collector = new TsStringCollectorEnv(null, m_sda, 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 = new XmlBrowseViewBaseVc(m_cache, m_stringTbl); m_vc.SuppressPictures = true; // we won't dispose of it, so it mustn't make pictures (which we don't need) m_vc.DataAccess = m_sda; } 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; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Keys the specified item. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public ITsString Key(IManyOnePathSortItem item) { return Key(item, false); }
/// ------------------------------------------------------------------------------------------ /// <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(IManyOnePathSortItem item) { return true; }
/// <summary> /// Get the items to be compared against the filter. /// </summary> /// <param name="item"></param> /// <returns></returns> protected override int[] GetItems(IManyOnePathSortItem item) { ISilDataAccess sda = m_cache.DomainDataByFlid; 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, LexSenseTags.kflidMorphoSyntaxAnalysis); GetItemsForMsaType(sda, ref results, hvoMsa); } else { int hvoEntry = item.RootObjectHvo; 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(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Keys the specified item. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public override ITsString Key(IManyOnePathSortItem item) { return m_sda.get_MultiStringAlt(item.KeyObject, m_flid, m_ws); }
/// ------------------------------------------------------------------------------------------ /// <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(IManyOnePathSortItem item) { return Matcher.Accept(m_finder.Key(item)); }
/// ------------------------------------------------------------------------------------ /// <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(IManyOnePathSortItem 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; }
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. /// /// Collator sorting generally ignores the minus sign as being a hyphen. So we have /// to be tricky handling negative numbers. Nine's complement with an inverted sign /// digit should do the trick... /// </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(IManyOnePathSortItem item, bool sortedFromEnd) { 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[] { "9" + new String('0', maxDigits) }; string prefix; char chFiller; if (sVal[0] == '-') { sVal = NinesComplement(sVal.Substring(1)); prefix = "0"; // negative numbers come first. chFiller = '9'; } else { prefix = "9"; // positive numbers come later. chFiller = '0'; } if (sVal.Length == maxDigits) return new string[] { prefix + sVal }; else return new string[] { prefix + new String(chFiller, maxDigits - sVal.Length) + sVal }; }
/// <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(IManyOnePathSortItem 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); }
/// ------------------------------------------------------------------------------------ /// <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(IManyOnePathSortItem item, bool sortedFromEnd) { string result = Key(item, true).Text; if (result == null) return new string[0]; else { if (sortedFromEnd) result = TsStringUtils.ReverseString(result); return new string[] { result }; } }
/// <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(IManyOnePathSortItem 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), CmObjectTags.kflidClass); int flid = mdc.GetFieldId2(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, CmObjectTags.kflidClass) == 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); } }
/// <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, IManyOnePathSortItem 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.MainCacheAccessor.get_ObjectProp(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.MainCacheAccessor.get_VecSize(cmo.Hvo, flid); StringBuilder sb = null; for (int i = 0; i < size; i++) { int objHvo = m_cache.MainCacheAccessor.get_VecItem(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 var childObjKey = GetChildObjKey(layout, objHvo, item, -1, sortedFromEnd); if (childObjKey != null) { if (sb == null) { sb = new StringBuilder(); } foreach (var subKey in childObjKey) { sb.Append(subKey); } } } if (sb != null) { return new [] { 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; } var key = GetKey(child, cmo, item, pathIndex, sortedFromEnd); if (key != null) { return(key); } } } break; } return(null); }
/// ------------------------------------------------------------------------------------ /// <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(IManyOnePathSortItem item, bool sortedFromEnd) { return(Strings(item, sortedFromEnd)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// For most of these we want to return the same thing. /// </summary> /// <param name="item"></param> /// <returns></returns> public string[] SortStrings(IManyOnePathSortItem item, bool sortedFromEnd) { return Strings(item, sortedFromEnd); }
/// <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(IManyOnePathSortItem item, bool sortedFromEnd) { if (item.KeyObject == 0) 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.RootObjectHvo, m_layoutName, true, m_sda, m_layouts); var rootObject = item.RootObjectUsing(m_cache); var key = GetKey(layout, rootObject, item, 0, sortedFromEnd); if (key == null) { // the root object sort method is not tried in GetKey key = CallSortMethod(rootObject, sortedFromEnd); if (key == null) { // try calling the sort method on the key object var keyCmObjectUsing = item.KeyObjectUsing(m_cache); key = CallSortMethod(keyCmObjectUsing, sortedFromEnd); if (key == null) { // Try the default fallback if we can't find the method. var firstKey = keyCmObjectUsing.SortKey ?? ""; if (sortedFromEnd) firstKey = TsStringUtils.ReverseString(firstKey); return new [] {firstKey, keyCmObjectUsing.SortKey2Alpha}; } } } return key; }
public virtual ITsString Key(IManyOnePathSortItem item) { throw new NotImplementedException("Don't have new Key function implemented on class " + this.GetType()); }
private string[] GetChildObjKey(XmlNode layout, int hvo, IManyOnePathSortItem item, int pathIndex, bool sortedFromEnd) { ICmObject childObj = m_cache.ServiceLocator.ObjectRepository.GetObject(hvo); string layoutName = XmlUtils.GetOptionalAttributeValue(layout, "layout"); XmlNode part = XmlVc.GetNodeForPart(hvo, layoutName, true, m_sda, m_layouts); var key = GetKey(part, childObj, item, pathIndex, sortedFromEnd); if (key != null) return key; return CallSortMethod(childObj, sortedFromEnd); }
/// ------------------------------------------------------------------------------------ /// <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(IManyOnePathSortItem item);
/// <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, IManyOnePathSortItem 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.MainCacheAccessor.get_ObjectProp(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.MainCacheAccessor.get_VecSize(cmo.Hvo, flid); StringBuilder sb = null; for (int i = 0; i < size; i++) { int objHvo = m_cache.MainCacheAccessor.get_VecItem(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 var childObjKey = GetChildObjKey(layout, objHvo, item, -1, sortedFromEnd); if (childObjKey != null) { if (sb == null) sb = new StringBuilder(); foreach (var subKey in childObjKey) sb.Append(subKey); } } if (sb != null) return new [] {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; var key = GetKey(child, cmo, item, pathIndex, sortedFromEnd); if (key != null) return key; } } break; } return null; }
/// ------------------------------------------------------------------------------------------ /// <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(IManyOnePathSortItem item) { foreach (RecordFilter f in m_filters) if (!f.Accept(item)) return false; return true; }
public void DisplayDoubleSeqPathObject() { ArrayList list = new ArrayList(); XmlNode column = m_columnList[5]; XmlViewsUtils.CollectBrowseItems(6, column, list, m_mdc, m_sda, m_layouts); IManyOnePathSortItem bvi = list[0] as IManyOnePathSortItem; // Try on first column. Nothing in the path matches, but we still dig inside // the span. int useHvo; List <XmlNode> collectStructNodes = new List <XmlNode>(); XmlNode useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[0], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(6, useHvo); CheckDebugId(useNode, "LexemeCf"); Assert.AreEqual(1, collectStructNodes.Count); CheckDebugId(collectStructNodes[0], "LexemeSpan"); // Try on etymology column. Has an <obj>, but doens't match collectStructNodes.Clear(); useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[1], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(6, useHvo); CheckDebugId(useNode, "EtymologyObj"); Assert.AreEqual(1, collectStructNodes.Count); XmlNode structNode1 = collectStructNodes[0]; CheckDebugId(structNode1, "EtymologySpan"); // Try on a column involving a lookup. This affects the node output. collectStructNodes.Clear(); useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[2], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(6, useHvo); CheckDebugId(useNode, "EntryMsaSeq"); Assert.AreEqual(1, collectStructNodes.Count); structNode1 = collectStructNodes[0]; CheckDebugId(structNode1, "EntryMsasDiv"); // On the matching column, we should get the leaf object collectStructNodes.Clear(); useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[5], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(bvi.KeyObject, useHvo); CheckDebugId(useNode, "PACN_Para"); Assert.AreEqual(1, collectStructNodes.Count); structNode1 = collectStructNodes[0]; CheckDebugId(structNode1, "DosDiv"); // On the gloss column, we get the sense. collectStructNodes.Clear(); useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[3], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(7, useHvo); // the first sense CheckDebugId(useNode, "SenseGloss"); Assert.AreEqual(1, collectStructNodes.Count); structNode1 = collectStructNodes[0]; CheckDebugId(structNode1, "SenseGlossPara"); // Make sure that for later Bvis, we get later senses collectStructNodes.Clear(); bvi = list[3] as IManyOnePathSortItem; useNode = XmlViewsUtils.GetNodeToUseForColumn(bvi, m_columnList[3], m_mdc, m_sda, m_layouts, out useHvo, collectStructNodes); Assert.AreEqual(9, useHvo); // the third sense, in which context we display the 4th SD }
/// ------------------------------------------------------------------------------------ /// <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 (IManyOnePathSortItem item) { var obj = item.KeyObjectUsing(m_cache); if (!(obj is ICmBaseAnnotation)) return false; // It's not a base annotation var annotation = (ICmBaseAnnotation)obj; if (annotation.BeginObjectRA == null) return false; int cls = annotation.BeginObjectRA.ClassID; foreach(uint i in m_classIds) { if ( i == cls) return true; } return false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Keys the specified item. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public ITsString Key(IManyOnePathSortItem item) { return(Key(item, false)); }
///// <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= IWfiWordSet.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 (IManyOnePathSortItem item) { int hvo = item.KeyObject; for(int i = m_hvos.Length-1; i>=0; i--) { if(m_hvos[i] == hvo) return true; } return false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Given a IManyOnePathSortItem 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(IManyOnePathSortItem item, XmlNode node, int hvo, IVwEnv vwenv) { List<XmlNode> outerParts = new List<XmlNode>(); int hvoToDisplay; NodeDisplayCommand dispCommand = XmlViewsUtils.GetDisplayCommandForColumn(item, node, m_mdc, m_sda, 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, hvo); 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; } }