/// <summary> /// Adds an element to the tree but not to the head /// </summary> void AddElementNotToHead(Operator cursor, ITreeElement newElement, ref bool isElementAdded) { if (cursor == null) { throw new InvalidOperationException("Error"); } if (!isElementAdded) { if (cursor.Left == null) { cursor.Left = newElement; isElementAdded = true; return; } if (cursor.Left is Operator) { AddElementNotToHead(cursor.Left as Operator, newElement, ref isElementAdded); } } if (!isElementAdded) { if (cursor.Right == null) { cursor.Right = newElement; isElementAdded = true; return; } if (cursor.Right is Operator) { AddElementNotToHead(cursor.Right as Operator, newElement, ref isElementAdded); } } }
public Tree(ITreeElement root) { this.parameters = new Dictionary <IFilter, string>(); this.Root = root; this.Current = root; this.stack = new Stack <ITreeElement>(); }
private string ToString(ITreeElement element, int depth) { StringBuilder builder = new StringBuilder(); builder.Append(' ', depth).Append(element.Caption); foreach (IFilter f in element.AvailableFilters) { builder.Append(" ").Append(f.Name).Append(": "); foreach (string s in element.GetFilterValues(f)) { builder.Append(s).Append(" "); } } foreach (ITreeElement el in element.Children) { builder.Append("\n").Append(this.ToString(el, depth + 1)); } /*foreach(ITreeElement el in element.Children) * { * builder.Append(' ', depth).Append(el.Caption); * foreach(IFilter f in el.AvailableFilters) * { * builder.Append(" ").Append(f.Name).Append(": "); * foreach (string s in el.GetFilterValues(f)) * builder.Append(s).Append(" "); * } * * builder.Append("\n").Append(this.ToString(el, depth + 1)); * }*/ return(builder.ToString()); }
public Deserializer(string filepath, string localization) { this.localization = localization; //Parse JSON into our auxiliary system string data = System.IO.File.ReadAllText(filepath); this.dataStructure = new AuxiliaryDataStructure(); JToken token = (JToken)JsonConvert.DeserializeObject(data); this.dataStructure = token.ToObject <AuxiliaryDataStructure>(); JToken treeToken = token.Children <JProperty>().FirstOrDefault(x => x.Name == "tree"); AuxiliaryTreeNode tree = new AuxiliaryTreeNode(); FillAuxiliaryTree(treeToken, ref tree); this.dataStructure.Tree = tree; //Set available_filters category this.availableFilters = new HashSet <IFilter>(dataStructure.AvailableFilters.Items.Values .Select(x => new Filter.Filter(this.GetNameWithLocalization(x.Caption), x.Values.Values .Select(y => this.GetNameWithLocalization(y.Caption))))); this.defaultFilters = new HashSet <IFilter>(this.availableFilters .Where(x => this.dataStructure.AvailableFilters.Items .Where(y => this.dataStructure.AvailableFilters.DefaultList.Contains(y.Key)) .Select(z => this.GetNameWithLocalization(z.Value.Caption)) .Contains(x.Name))); //Set tree_elements category this.treeElements = new HashSet <ITreeElement>(); foreach (KeyValuePair <string, AuxiliaryItem> pair in this.dataStructure.TreeElements) { Dictionary <IFilter, IEnumerable <string> > filters = new Dictionary <IFilter, IEnumerable <string> >(); if (pair.Value.Filters != null) { foreach (KeyValuePair <string, List <string> > f in pair.Value.Filters) { filters.Add(this.GetFilter(f.Key), f.Value.Select(fil => this.GetNameWithLocalization(this.dataStructure.AvailableFilters.Items[f.Key].Values[fil].Caption))); } } this.treeElements.Add(new TreeElement.TreeElement( pair.Key, pair.Value.Caption == null ? pair.Key : this.GetNameWithLocalization(pair.Value.Caption), this.defaultFilters .Union(pair.Value.FilterList == null ? new List <IFilter>() : this.availableFilters .Where(x => this.dataStructure.AvailableFilters.Items .Where(y => pair.Value.FilterList.Contains(y.Key)) .Select(z => this.GetNameWithLocalization(z.Value.Caption)) .Contains(x.Name))), filters )); } //Generate Tree ITreeElement root = this.GetTreeElement(this.dataStructure.Tree.Children.First().Key); this.FillResultTree(root, this.dataStructure.Tree.Children.First().Value); this.Tree = new Tree.Tree(root); }
private void FillResultTree(ITreeElement treeElement, AuxiliaryTreeNode nodeInfo) { foreach (KeyValuePair <string, AuxiliaryTreeNode> pair in nodeInfo.Children) { ITreeElement child = this.GetTreeElement(pair.Key); FillResultTree(child, pair.Value); treeElement.AddChild(child); } }
private string Depth(ITreeElement element) { if (element.Parent != null) { return($"-{Depth(element.Parent)}"); } return(""); }
public void Update() { TreeView tree = View.docTreeViewControl; if (tree.SelectedItem != null) { ITreeElement selected_item = tree.SelectedItem as ITreeElement; this.Path.Text = Utils.getFullPath(selected_item.Node); } }
/// <summary> /// Adds an element to the tree /// </summary> void AddElementInTree(ITreeElement newElement) { if (head == null) { head = newElement; return; } bool addedElement = false; AddElementNotToHead(head as Operator, newElement, ref addedElement); }
public void Update() { TreeView tree = View.docTreeViewControl; if (tree.SelectedItem != null) { ITreeElement selected_item = tree.SelectedItem as ITreeElement; this.Path.Text = Utils.getFullPath(selected_item.Node); } NextValue.Text = ((SequenceTransformRule)Copy).NextValueItem; NextIndex.Text = ((SequenceTransformRule)Copy).NextValue.ToString(); }
private void TreeViewItem_MouseRightButton(object source, RoutedEventArgs e) { if (!e.Handled) { TreeViewItem el = source as TreeViewItem; ITreeElement tree_el = el?.DataContext as ITreeElement; if (tree_el != null) { tree_el.Expanded = true; tree_el.ChainExpand(); } e.Handled = true; } }
public void Update() { TreeView tree = View.docTreeViewControl; if (tree.SelectedItem != null) { ITreeElement selected_item = tree.SelectedItem as ITreeElement; this.Path.Text = Utils.getFullPath(selected_item.Node); if (this.CurVal.Text == string.Empty) { this.CurVal.Text = selected_item.Node.InnerText; } } }
private void NewIncrement_Clicked(object source, RoutedEventArgs e) { ITreeElement item = (ITreeElement)View.ruleTree.docTreeViewer.SelectedItem; string path = Utils.getFullPath(item?.Node as XmlNode); string current_value = ""; if (item != null) { current_value = ((XmlNode)item.Node).InnerText; } IncrementStringTransformRule rule = new IncrementStringTransformRule(current_value, path); RulePropsDrawer.DrawRule(View.ruleProps, rule, View); CollapseExpander(); }
/// <summary> /// Prints a tree element /// </summary> void PrintTreeElement(ITreeElement currentElement) { if (currentElement is Operator && (currentElement as Operator).Left != null) { Console.Write("( "); PrintTreeElement((currentElement as Operator).Left); } currentElement.Print(); Console.Write(" "); if (currentElement is Operator && (currentElement as Operator).Right != null) { PrintTreeElement((currentElement as Operator).Right); Console.Write(") "); } }
private void NewSequence_Clicked(object source, RoutedEventArgs e) { ITreeElement item = (ITreeElement)View.ruleTree.docTreeViewer.SelectedItem; string path = Utils.getFullPath(item?.Node as XmlNode); string current_value = "Value"; if (item != null) { current_value = item.Node.InnerText; } SequenceTransformRule rule = new SequenceTransformRule(new List <string>() { current_value }, path, 0); RulePropsDrawer.DrawRule(View.ruleProps, rule, View); CollapseExpander(); }
public ITreeElement GoToChild(ITreeElement child) { if (this.Current.Children.Contains(child)) { ITreeElement c = child; do { stack.Push(Current); Current = c; if (Current.Children.Count() == 0) { return(this.Current); } c = c.Children.First(); } while (Current.Children.Count() == 1); return(this.Current); } return(null); }
public void Save() { // Check if Node is Valid ITreeElement sel_element = View.ruleTree.docTreeViewer.SelectedItem as ITreeElement; XmlNode node = sel_element?.Node; // TODO change if (node != null) { if (!Copy.Validator.Validate(node)) { MessageBox.Show("This rule is not valid for the selected Node. Please select other node/rule.", "Invalid Node/Rule", MessageBoxButton.OK, MessageBoxImage.Exclamation); View.ViewModel.CloseProps(); return; } View.ViewModel.testCase.AddRule(Copy.Path, Copy); if (Rule.Parent == null) { View.ViewModel.Rules.Add(Copy); } else { if (MessageBox.Show("Are you sure to modify?", "Modify Rule", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { View.ViewModel.testCase.RemoveRule(Rule.Path, Rule); int obsIndex = View.ViewModel.Rules.IndexOf(Rule); View.ViewModel.Rules[obsIndex] = Copy; } else { View.ViewModel.testCase.RemoveRule(Copy.Path, Rule); } } } View.ViewModel.CloseProps(); View.testCase.Document.TestSuiteSaver.SaveSuite(); }
private void TreeViewItem_Loaded(object source, RoutedEventArgs e) { // tw is the TreeViewItem that gets loaded TreeViewItem tw = source as TreeViewItem; if (tw != null) { ITreeElement xNode = tw.DataContext as ITreeElement; if (xNode != null && (xNode.Node.NodeType == XmlNodeType.Element || xNode.Node.NodeType == XmlNodeType.Attribute)) { string path = Utils.getFullPath(xNode.Node); // add the current treeviewitem to the table NodeMap[path] = tw; // Try get the previous state of this node. Copy expanded attribute if found PreviousState.TryGetValue(path, out ITreeElement prev); if (prev != null && prev.Expanded) { tw.IsExpanded = true; } PreviousState[path] = xNode; Act(); } } }
public void SetLeft(ITreeElement left) { this.left = left; }
public Tree(string input) { int index = 0; this.root = CreateParserTree(input, ref index); }
/// <summary> /// Initializes a new instance of the <see cref="AdditionOperationTreeElement"/> class. /// </summary> /// <param name="leftTreeElement">Pointer to the left son.</param> /// <param name="rightTreeElement">Pointer to the right son.</param> public AdditionOperationTreeElement(ITreeElement leftTreeElement, ITreeElement rightTreeElement) : base(leftTreeElement, rightTreeElement) { }
/// <summary> /// Initializes a new instance of the <see cref="OperationTreeElement"/> class. /// </summary> /// <param name="leftTreeElement">Pointer to the left son.</param> /// <param name="rightTreeElement">Pointer to the right son.</param> protected OperationTreeElement(ITreeElement leftTreeElement, ITreeElement rightTreeElement) { this.LeftTreeElement = leftTreeElement ?? throw new ArgumentNullException(nameof(leftTreeElement)); this.RightTreeElement = rightTreeElement ?? throw new ArgumentNullException(nameof(rightTreeElement)); }
public void AddChild(ITreeElement child) { this.children.Add(child); }
public void SetRight(ITreeElement right) { this.right = right; }
/// <summary> /// Initializes a new instance of the <see cref="MultiplicationOperationTreeElement"/> class. /// </summary> /// <param name="leftTreeElement">Pointer to the left son.</param> /// <param name="rightTreeElement">Pointer to the right son.</param> public MultiplicationOperationTreeElement(ITreeElement leftTreeElement, ITreeElement rightTreeElement) : base(leftTreeElement, rightTreeElement) { }
private void VisitChildrens(ITreeElement element) { IEnumerable<ITreeElement> childrens = element.GetChilds(); foreach (var children in childrens) { children.Visit(this); } }
/// <summary> /// Initializes a new instance of the <see cref="SubtractionOperationTreeElement"/> class. /// </summary> /// <param name="leftTreeElement">Pointer to the left son.</param> /// <param name="rightTreeElement">Pointer to the right son.</param> public SubtractionOperationTreeElement(ITreeElement leftTreeElement, ITreeElement rightTreeElement) : base(leftTreeElement, rightTreeElement) { }