void CreateTreeForList(TreeViewItem root, IAutosarTreeList list) { /* */ bool needAdd = false; TreeViewItem newTreeItem; if (list.CreateRoot() || (root == null)) { newTreeItem = new TreeViewItem(); newTreeItem.Header = list.GetName(); newTreeItem.FontWeight = FontWeights.Normal; newTreeItem.Tag = list; needAdd = true; } else { needAdd = false; newTreeItem = root; } /* Create items for all properties */ List <IGUID> guids = list.GetItems(); if (guids != null) { foreach (IGUID guid in guids) { TreeViewItem item = CreateItemsForGuid(newTreeItem, guid); /* Create leafes for the lists*/ List <IAutosarTreeList> lists = guid.GetLists(); if (lists != null) { if (lists.Count > 0) { foreach (IAutosarTreeList treeList in lists) { CreateTreeForList(item, treeList); } } } } } if (needAdd) { if (root != null) { root.Items.Add(newTreeItem); } else { newTreeItem.FontWeight = FontWeights.Bold; this.Items.Add(newTreeItem); } } }
TreeViewItem CreateItemsForList(TreeViewItem root, IAutosarTreeList list) { TreeViewItem newTreeItem = new TreeViewItem(); newTreeItem.Header = list.GetName(); newTreeItem.FontWeight = FontWeights.Normal; newTreeItem.Tag = list; root.Items.Add(newTreeItem); return(newTreeItem); }
public void UpdateAutosarTreeView() { /* Find all properties in Autosar Application */ /* Find all IGuidObjects */ String res = ""; PropertyInfo[] allProperties = AutosarApplication.GetInstance().GetType().GetProperties(); List <PropertyInfo> properties = new List <PropertyInfo>(); foreach (PropertyInfo property in allProperties) { if (property.GetValue(AutosarApplication.GetInstance()) as IAutosarTreeList != null) { properties.Add(property); } } properties.Sort(delegate(PropertyInfo x, PropertyInfo y) { IAutosarTreeList list1 = x.GetValue(AutosarApplication.GetInstance()) as IAutosarTreeList; IAutosarTreeList list2 = y.GetValue(AutosarApplication.GetInstance()) as IAutosarTreeList; String name1 = list1.GetName(); String name2 = list2.GetName(); if ((name1 != null) && (name2 != null)) { string xName = name1.ToString(); string yName = name2.ToString(); if (xName == null && yName == null) { return(0); } else if (xName == null) { return(-1); } else if (yName == null) { return(1); } else { return(xName.CompareTo(yName)); } } throw new Exception("Sort exception! Properties not exists!"); }); /* Delete unexist */ //DeleteUnexists(properties); /* Add new */ TreeViewItem root = new TreeViewItem(); foreach (PropertyInfo property in properties) { res += property.Name + " " + Environment.NewLine; IAutosarTreeList treeList = property.GetValue(AutosarApplication.GetInstance()) as IAutosarTreeList; if (treeList != null) { /* Create root for the list */ CreateTreeForList(root, treeList); } } /* Sort */ for (int i = 0; i < root.Items.Count; i++) { SortChilds(root.Items[i] as TreeViewItem); } /* syncronize root and items */ SyncronizeRoot(root.Items.Count); for (int i = 0; i < root.Items.Count; i++) { Syncronize(root.Items[i] as TreeViewItem, Items[i] as TreeViewItem); } /* Sort */ for (int i = 0; i < root.Items.Count; i++) { SortChilds(root.Items[i] as TreeViewItem); } }