private void AddNode(IFsSymFeatVal val, FeatureTreeNode parentNode) { FeatureTreeNode newNode = new FeatureTreeNode(val.Name.BestAnalysisAlternative.Text, (int)ImageKind.radio, (int)ImageKind.radio, val.Hvo, FeatureTreeNodeInfo.NodeKind.SymFeatValue); InsertNode(newNode, parentNode); }
private void AddNodeFromFS(IFsSymFeatVal val, FeatureTreeNode parentNode) { TreeNodeCollection col; if (parentNode == null) { col = Nodes; } else { col = parentNode.Nodes; } if (val == null) { return; // can't select it! } int hvoVal = val.Hvo; foreach (FeatureTreeNode node in col) { if (hvoVal == node.Hvo) { // already there (which is to be expected); mark it as selected node.ImageIndex = (int)ImageKind.radioSelected; node.SelectedImageIndex = (int)ImageKind.radioSelected; node.Chosen = true; return; } } // did not find the node, so add it (not to be expected, but we'd better deal with it) FeatureTreeNode newNode = new FeatureTreeNode(val.Name.AnalysisDefaultWritingSystem, (int)ImageKind.radio, (int)ImageKind.radio, val.Hvo, FeatureTreeNodeInfo.NodeKind.SymFeatValue); InsertNode(newNode, parentNode); newNode.Chosen = true; }
private void AddNode(IFsFeatStruc fs, FeatureTreeNode parentNode) { foreach (IFsFeatureSpecification spec in fs.FeatureSpecsOC) { AddNode(spec, parentNode); } }
private void AddNode(IFsFeatureSpecification spec, FeatureTreeNode parentNode) { IFsFeatDefn defn = spec.FeatureRA; TreeNodeCollection col; if (parentNode == null) { col = Nodes; } else { col = parentNode.Nodes; } IFsClosedValue closed = spec as IFsClosedValue; if (closed != null) { foreach (FeatureTreeNode node in col) { if (defn.Hvo == node.Hvo) { // already there (which is to be expected); see if its value is, too AddNodeFromFS(closed.ValueRA, node); return; } } // did not find the node, so add it and its value (not to be expected, but we'd better deal with it) FeatureTreeNode newNode = new FeatureTreeNode(defn.Name.AnalysisDefaultWritingSystem, (int)ImageKind.feature, (int)ImageKind.feature, defn.Hvo, FeatureTreeNodeInfo.NodeKind.Closed); InsertNode(newNode, parentNode); IFsSymFeatVal val = closed.ValueRA; if (val != null) { FeatureTreeNode newValueNode = new FeatureTreeNode(val.Name.AnalysisDefaultWritingSystem, (int)ImageKind.radioSelected, (int)ImageKind.radioSelected, val.Hvo, FeatureTreeNodeInfo.NodeKind.SymFeatValue); newValueNode.Chosen = true; InsertNode(newValueNode, newNode); } } IFsComplexValue complex = spec as IFsComplexValue; if (complex != null) { foreach (FeatureTreeNode node in col) { if (defn.Hvo == node.Hvo) { // already there (which is to be expected); see if its value is, too AddNode((IFsFeatStruc)complex.ValueOA, node); return; } } // did not find the node, so add it and its value (not to be expected, but we'd better deal with it) FeatureTreeNode newNode = new FeatureTreeNode(defn.Name.AnalysisDefaultWritingSystem, (int)ImageKind.complex, (int)ImageKind.complex, defn.Hvo, FeatureTreeNodeInfo.NodeKind.Complex); InsertNode(newNode, parentNode); AddNode((IFsFeatStruc)complex.ValueOA, newNode); } }
private void OnKeyUp(object obj, KeyEventArgs kea) { TreeView tv = (TreeView)obj; FeatureTreeNode tn = (FeatureTreeNode)tv.SelectedNode; if (kea.KeyCode == Keys.Space && tn != null) { HandleCheckBoxNodes(tv, tn); } }
private void InsertNode(FeatureTreeNode newNode, FeatureTreeNode parentNode) { if (parentNode == null) { Nodes.Add(newNode); } else { parentNode.Nodes.Add(newNode); } }
/// <summary> /// Recursively builds the feature structure based on contents of treeview node path. /// It recurses back up the treeview node path to the top and then builds the feature structure /// as it goes back down. /// </summary> /// <param name="node"></param> /// <param name="fs"></param> /// <param name="val"></param> /// <returns></returns> private void BuildFeatureStructure(FeatureTreeNode node, ref IFsFeatStruc fs, ref IFsFeatureSpecification val) { if (node.Parent != null) { BuildFeatureStructure((FeatureTreeNode)node.Parent, ref fs, ref val); } switch (node.Kind) { case FeatureTreeNodeInfo.NodeKind.Complex: var complexFeat = m_cache.ServiceLocator.GetInstance <IFsComplexFeatureRepository>().GetObject(node.Hvo); var complex = fs.GetOrCreateValue(complexFeat); val = complex; val.FeatureRA = complexFeat; if (fs.TypeRA == null) { fs.TypeRA = m_cache.LanguageProject.MsFeatureSystemOA.TypesOC.SingleOrDefault(type => type.FeaturesRS.Contains(complexFeat)); } fs = (IFsFeatStruc)complex.ValueOA; if (fs.TypeRA == null) { // this is the type of what's being embedded in the fs var cf = val.FeatureRA as IFsComplexFeature; if (cf != null) { fs.TypeRA = cf.TypeRA; } } break; case FeatureTreeNodeInfo.NodeKind.Closed: var closedFeat = m_cache.ServiceLocator.GetInstance <IFsClosedFeatureRepository>().GetObject(node.Hvo); val = fs.GetOrCreateValue(closedFeat); val.FeatureRA = closedFeat; if (fs.TypeRA == null) { // SingleOrDefault() gave an exception if 2 complex features used the same feature (LT-12780) fs.TypeRA = m_cache.LanguageProject.MsFeatureSystemOA.TypesOC.FirstOrDefault(type => type.FeaturesRS.Contains(closedFeat)); } break; case FeatureTreeNodeInfo.NodeKind.SymFeatValue: var closed = val as IFsClosedValue; if (closed != null) { closed.ValueRA = m_cache.ServiceLocator.GetInstance <IFsSymFeatValRepository>().GetObject(node.Hvo); } break; } }
/// <summary> /// Recursively builds the feature structure based on contents of treeview node path. /// It recurses back up the treeview node path to the top and then builds the feature structure /// as it goes back down. /// </summary> /// <param name="node"></param> /// <param name="fs"></param> /// <returns></returns> private void BuildFeatureStructure(FeatureTreeNode node, ref IFsFeatStruc fs, ref IFsFeatureSpecification val) { if (node.Parent != null) { BuildFeatureStructure((FeatureTreeNode)node.Parent, ref fs, ref val); } switch (node.Kind) { case FeatureTreeNodeInfo.NodeKind.Complex: IFsComplexValue complex = fs.FindOrCreateComplexValue(node.Hvo); val = complex as FsComplexValue; val.FeatureRAHvo = node.Hvo; if (fs.TypeRA == null) { // this is the type which contains the complex feature fs.TypeRAHvo = FsFeatureSystem.GetTypeFromFsComplexFeature(m_cache, node.Hvo); } fs = (IFsFeatStruc)complex.ValueOA; if (fs.TypeRA == null) { // this is the type of what's being embedded in the fs IFsComplexFeature cf = val.FeatureRA as IFsComplexFeature; if (cf != null) { fs.TypeRA = cf.TypeRA; } } break; case FeatureTreeNodeInfo.NodeKind.Closed: val = (IFsClosedValue)fs.FindOrCreateClosedValue(node.Hvo); val.FeatureRAHvo = node.Hvo; break; case FeatureTreeNodeInfo.NodeKind.SymFeatValue: IFsClosedValue closed = val as IFsClosedValue; if (closed != null) { closed.ValueRAHvo = node.Hvo; } break; default: break; // do nothing } }
private void OnMouseUp(object obj, MouseEventArgs mea) { if (mea.Button == MouseButtons.Left) { TreeView tv = (TreeView)obj; FeatureTreeNode tn = (FeatureTreeNode)tv.GetNodeAt(mea.X, mea.Y); if (tn != null) { Rectangle rec = tn.Bounds; rec.X += -18; // include the image bitmap (16 pixels plus 2 pixels between the image and the text) rec.Width += 18; if (rec.Contains(mea.X, mea.Y)) { HandleCheckBoxNodes(tv, tn); int i = tn.ImageIndex; } } } }
public void Sort(TreeNodeCollection col) { CheckDisposed(); if (col.Count == 0) { return; } List <FeatureTreeNode> list = new List <FeatureTreeNode>(col.Count); foreach (FeatureTreeNode childNode in col) { list.Add(childNode as FeatureTreeNode); } list.Sort(); BeginUpdate(); col.Clear(); foreach (FeatureTreeNode childNode in list) { col.Add(childNode); if (childNode.Nodes.Count > 0) { if (childNode.Nodes[0].Nodes.Count > 0) { Sort(childNode.Nodes); // sort all but terminal nodes } else { // append "none of the above" node to terminal nodes FeatureTreeNode noneOfTheAboveNode = new FeatureTreeNode( // REVIEW: SHOULD THIS STRING BE LOCALIZED? LexTextControls.ksNoneOfTheAbove, (int)ImageKind.radio, (int)ImageKind.radio, 0, FeatureTreeNodeInfo.NodeKind.Other); InsertNode(noneOfTheAboveNode, childNode); } } } EndUpdate(); }
private bool AlreadyInTree(int iTag, FeatureTreeNode node) { if (node == null) { // at the top level foreach (FeatureTreeNode treeNode in Nodes) { if (iTag == treeNode.Hvo) { return(true); } } } while (node != null) { if (iTag == node.Hvo) { return(true); } node = (FeatureTreeNode)node.Parent; } return(false); }
private void AddNode(IFsFeatDefn defn, FeatureTreeNode parentNode) { IFsClosedFeature closed = defn as IFsClosedFeature; if (closed != null) { if (!AlreadyInTree(closed.Hvo, parentNode)) { // avoid duplicates FeatureTreeNode newNode = new FeatureTreeNode(closed.Name.AnalysisDefaultWritingSystem, (int)ImageKind.feature, (int)ImageKind.feature, closed.Hvo, FeatureTreeNodeInfo.NodeKind.Closed); InsertNode(newNode, parentNode); foreach (IFsSymFeatVal val in closed.ValuesOC) { AddNode(val, newNode); } } } IFsComplexFeature complex = defn as IFsComplexFeature; if (complex != null) { if (!AlreadyInTree(complex.Hvo, parentNode)) { // avoid infinite loop if a complex feature's type is the same as other features. FeatureTreeNode newNode = new FeatureTreeNode(complex.Name.BestAnalysisAlternative.Text, (int)ImageKind.complex, (int)ImageKind.complex, complex.Hvo, FeatureTreeNodeInfo.NodeKind.Complex); InsertNode(newNode, parentNode); IFsFeatStrucType type = complex.TypeRA; foreach (IFsFeatDefn defn2 in type.FeaturesRS) { AddNode(defn2, newNode); } } } }
private void HandleCheckBoxNodes(TreeView tv, FeatureTreeNode tn) { //UndoLastSelectedNode(); if (IsTerminalNode(tn)) { tn.Chosen = true; tn.ImageIndex = tn.SelectedImageIndex = (int)ImageKind.radioSelected; if (tn.Parent != null) { FeatureTreeNode sibling = (FeatureTreeNode)tn.Parent.FirstNode; while (sibling != null) { if (IsTerminalNode(sibling) && sibling != tn) { sibling.Chosen = false; sibling.ImageIndex = sibling.SelectedImageIndex = (int)ImageKind.radio; } sibling = (FeatureTreeNode)sibling.NextNode; } } tv.Invalidate(); } m_lastSelectedTreeNode = tn; }
private void InsertNode(FeatureTreeNode newNode, FeatureTreeNode parentNode) { if (parentNode == null) Nodes.Add(newNode); else parentNode.Nodes.Add(newNode); }
private bool AlreadyInTree(int iTag, FeatureTreeNode node) { if (node == null) { // at the top level foreach (FeatureTreeNode treeNode in Nodes) { if (iTag == treeNode.Hvo) return true; } } while (node != null) { if (iTag == node.Hvo) return true; node = (FeatureTreeNode)node.Parent; } return false; }
private void AddNode(IFsFeatureSpecification spec, FeatureTreeNode parentNode) { var defn = spec.FeatureRA; TreeNodeCollection col; if (parentNode == null) col = Nodes; else col = parentNode.Nodes; var closed = spec as IFsClosedValue; if (closed != null) { foreach (FeatureTreeNode node in col) { if (defn.Hvo == node.Hvo) { // already there (which is to be expected); see if its value is, too AddNodeFromFS(closed.ValueRA, node); return; } } // did not find the node, so add it and its value (not to be expected, but we'd better deal with it) FeatureTreeNode newNode = new FeatureTreeNode(defn.Name.AnalysisDefaultWritingSystem.Text, (int)ImageKind.feature, (int)ImageKind.feature, defn.Hvo, FeatureTreeNodeInfo.NodeKind.Closed); InsertNode(newNode, parentNode); var val = closed.ValueRA; if (val != null) { FeatureTreeNode newValueNode = new FeatureTreeNode(val.Name.AnalysisDefaultWritingSystem.Text, (int)ImageKind.radioSelected, (int)ImageKind.radioSelected, val.Hvo, FeatureTreeNodeInfo.NodeKind.SymFeatValue); newValueNode.Chosen = true; InsertNode(newValueNode, newNode); } } var complex = spec as IFsComplexValue; if (complex != null) { foreach (FeatureTreeNode node in col) { if (defn.Hvo == node.Hvo) { // already there (which is to be expected); see if its value is, too AddNode((IFsFeatStruc)complex.ValueOA, node); return; } } // did not find the node, so add it and its value (not to be expected, but we'd better deal with it) FeatureTreeNode newNode = new FeatureTreeNode(defn.Name.AnalysisDefaultWritingSystem.Text, (int)ImageKind.complex, (int)ImageKind.complex, defn.Hvo, FeatureTreeNodeInfo.NodeKind.Complex); InsertNode(newNode, parentNode); AddNode((IFsFeatStruc)complex.ValueOA, newNode); } }
private void AddNodeFromFS(IFsSymFeatVal val, FeatureTreeNode parentNode) { TreeNodeCollection col; if (parentNode == null) col = Nodes; else col = parentNode.Nodes; if (val == null) return; // can't select it! int hvoVal = val.Hvo; foreach (FeatureTreeNode node in col) { if (hvoVal == node.Hvo) { // already there (which is to be expected); mark it as selected node.ImageIndex = (int)ImageKind.radioSelected; node.SelectedImageIndex = (int)ImageKind.radioSelected; node.Chosen = true; return; } } // did not find the node, so add it (not to be expected, but we'd better deal with it) FeatureTreeNode newNode = new FeatureTreeNode(val.Name.AnalysisDefaultWritingSystem.Text, (int)ImageKind.radio, (int)ImageKind.radio, val.Hvo, FeatureTreeNodeInfo.NodeKind.SymFeatValue); InsertNode(newNode, parentNode); newNode.Chosen = true; }
private void AddNode(IFsSymFeatVal val, FeatureTreeNode parentNode) { FeatureTreeNode newNode = new FeatureTreeNode(val.Name.BestAnalysisAlternative.Text, (int)ImageKind.radio, (int)ImageKind.radio, val.Hvo, FeatureTreeNodeInfo.NodeKind.SymFeatValue); InsertNode(newNode, parentNode); }
private void AddNode(IFsFeatDefn defn, FeatureTreeNode parentNode) { var closed = defn as IFsClosedFeature; if (closed != null) { if (!AlreadyInTree(closed.Hvo, parentNode)) { // avoid duplicates FeatureTreeNode newNode = new FeatureTreeNode(closed.Name.AnalysisDefaultWritingSystem.Text, (int)ImageKind.feature, (int)ImageKind.feature, closed.Hvo, FeatureTreeNodeInfo.NodeKind.Closed); InsertNode(newNode, parentNode); foreach (var val in closed.ValuesSorted) { AddNode(val, newNode); } } } var complex = defn as IFsComplexFeature; if (complex != null) { if (!AlreadyInTree(complex.Hvo, parentNode)) { // avoid infinite loop if a complex feature's type is the same as other features. FeatureTreeNode newNode = new FeatureTreeNode(complex.Name.BestAnalysisAlternative.Text, (int)ImageKind.complex, (int)ImageKind.complex, complex.Hvo, FeatureTreeNodeInfo.NodeKind.Complex); InsertNode(newNode, parentNode); var type = complex.TypeRA; foreach (var defn2 in type.FeaturesRS) AddNode(defn2, newNode); } } }
private void AddNode(IFsFeatStruc fs, FeatureTreeNode parentNode) { foreach (var spec in fs.FeatureSpecsOC) { AddNode(spec, parentNode); } }
/// <summary> /// Recursively builds the feature structure based on contents of treeview node path. /// It recurses back up the treeview node path to the top and then builds the feature structure /// as it goes back down. /// </summary> /// <param name="node"></param> /// <param name="fs"></param> /// <param name="val"></param> /// <returns></returns> private void BuildFeatureStructure(FeatureTreeNode node, ref IFsFeatStruc fs, ref IFsFeatureSpecification val) { if (node.Parent != null) BuildFeatureStructure((FeatureTreeNode)node.Parent, ref fs, ref val); switch (node.Kind) { case FeatureTreeNodeInfo.NodeKind.Complex: var complexFeat = m_cache.ServiceLocator.GetInstance<IFsComplexFeatureRepository>().GetObject(node.Hvo); var complex = fs.GetOrCreateValue(complexFeat); val = complex; val.FeatureRA = complexFeat; if (fs.TypeRA == null) fs.TypeRA = m_cache.LanguageProject.MsFeatureSystemOA.TypesOC.SingleOrDefault(type => type.FeaturesRS.Contains(complexFeat)); fs = (IFsFeatStruc)complex.ValueOA; if (fs.TypeRA == null) { // this is the type of what's being embedded in the fs var cf = val.FeatureRA as IFsComplexFeature; if (cf != null) { fs.TypeRA = cf.TypeRA; } } break; case FeatureTreeNodeInfo.NodeKind.Closed: var closedFeat = m_cache.ServiceLocator.GetInstance<IFsClosedFeatureRepository>().GetObject(node.Hvo); val = fs.GetOrCreateValue(closedFeat); val.FeatureRA = closedFeat; if (fs.TypeRA == null) { // SingleOrDefault() gave an exception if 2 complex features used the same feature (LT-12780) fs.TypeRA = m_cache.LanguageProject.MsFeatureSystemOA.TypesOC.FirstOrDefault(type => type.FeaturesRS.Contains(closedFeat)); } break; case FeatureTreeNodeInfo.NodeKind.SymFeatValue: var closed = val as IFsClosedValue; if (closed != null) closed.ValueRA = m_cache.ServiceLocator.GetInstance<IFsSymFeatValRepository>().GetObject(node.Hvo); break; } }
// private void UndoLastSelectedNode() // { // if (m_lastSelectedTreeNode != null) // { // if (IsTerminalNode(m_lastSelectedTreeNode)) // { // m_lastSelectedTreeNode.Chosen = false; // m_lastSelectedTreeNode.ImageIndex = m_lastSelectedTreeNode.SelectedImageIndex = (int)ImageKind.radio; // } // } // } private void HandleCheckBoxNodes(TreeView tv, FeatureTreeNode tn) { //UndoLastSelectedNode(); if (IsTerminalNode(tn)) { tn.Chosen = true; tn.ImageIndex = tn.SelectedImageIndex = (int)ImageKind.radioSelected; if (tn.Parent != null) { FeatureTreeNode sibling = (FeatureTreeNode)tn.Parent.FirstNode; while (sibling != null) { if (IsTerminalNode(sibling) && sibling != tn) { sibling.Chosen = false; sibling.ImageIndex = sibling.SelectedImageIndex = (int)ImageKind.radio; } sibling = (FeatureTreeNode)sibling.NextNode; } } tv.Invalidate(); } // m_lastSelectedTreeNode = tn; }
public void Sort(TreeNodeCollection col) { CheckDisposed(); if (col.Count == 0) return; List<FeatureTreeNode> list = new List<FeatureTreeNode>(col.Count); foreach (FeatureTreeNode childNode in col) { list.Add(childNode); } list.Sort(); BeginUpdate(); col.Clear(); foreach (FeatureTreeNode childNode in list) { col.Add(childNode); if (childNode.Nodes.Count > 0) { if (childNode.Nodes[0].Nodes.Count > 0) Sort(childNode.Nodes); // sort all but terminal nodes else { // append "none of the above" node to terminal nodes FeatureTreeNode noneOfTheAboveNode = new FeatureTreeNode( // REVIEW: SHOULD THIS STRING BE LOCALIZED? LexTextControls.ksNoneOfTheAbove, (int)ImageKind.radio, (int)ImageKind.radio, 0, FeatureTreeNodeInfo.NodeKind.Other); InsertNode(noneOfTheAboveNode, childNode); } } } EndUpdate(); }
/// <summary> /// Recursively builds the feature structure based on contents of treeview node path. /// It recurses back up the treeview node path to the top and then builds the feature structure /// as it goes back down. /// </summary> /// <param name="node"></param> /// <param name="fs"></param> /// <returns></returns> private void BuildFeatureStructure(FeatureTreeNode node, ref IFsFeatStruc fs, ref IFsFeatureSpecification val) { if (node.Parent != null) BuildFeatureStructure((FeatureTreeNode)node.Parent, ref fs, ref val); switch (node.Kind) { case FeatureTreeNodeInfo.NodeKind.Complex: IFsComplexValue complex = fs.FindOrCreateComplexValue(node.Hvo); val = complex as FsComplexValue; val.FeatureRAHvo = node.Hvo; if (fs.TypeRA == null) { // this is the type which contains the complex feature fs.TypeRAHvo = FsFeatureSystem.GetTypeFromFsComplexFeature(m_cache, node.Hvo); } fs = (IFsFeatStruc)complex.ValueOA; if (fs.TypeRA == null) { // this is the type of what's being embedded in the fs IFsComplexFeature cf = val.FeatureRA as IFsComplexFeature; if (cf != null) { fs.TypeRA = cf.TypeRA; } } break; case FeatureTreeNodeInfo.NodeKind.Closed: val = (IFsClosedValue)fs.FindOrCreateClosedValue(node.Hvo); val.FeatureRAHvo = node.Hvo; break; case FeatureTreeNodeInfo.NodeKind.SymFeatValue: IFsClosedValue closed = val as IFsClosedValue; if (closed != null) closed.ValueRAHvo = node.Hvo; break; default: break; // do nothing } }