/// <summary>
 /// Look for a shown child and replace it with a new one
 /// <para>This comes as we have set it up for items to be replaced in the hierarchy</para>
 /// </summary>
 /// <param name="shown">Shown item to replace</param>
 /// <param name="newItem">New item to replace the shown with</param>
 private void ReplaceShownChild(ListItemVM shown, ListItemVM newItem)
 {
     if (ParentItemVM == null)
     {
         if (ParentVM != null)
         {
             ParentVM.ReplaceSelectedItem(newItem);
         }
     }
     else
     {
         if (String.Equals(Model.Code.ChildType, IcdCodeStrings.ChildType_Direct))
         {
             ParentItemVM.ReplaceShownChild(shown, newItem);
         }
         else
         {
             var newParentChildren = ParentItemVM.Children.ToList();
             for (int childOn = 0; childOn < newParentChildren.Count; ++childOn)
             {
                 if (Object.ReferenceEquals(newParentChildren[childOn], shown) ||
                     Object.ReferenceEquals(newParentChildren[childOn], this))
                 {
                     newParentChildren[childOn] = newItem;
                 }
             }
             ParentItemVM.Children = newParentChildren;
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Clear the list so only one item is displayed
        /// </summary>
        /// <param name="item">The single item to display</param>
        public void ClearToItem(ListItemVM item)
        {
            if (item == null)
            {
                return;
            }

            Items.InterruptCollectionChanged();
            Items.Items.Clear();
            Items.Items.Add(item);
            Items.AllowCollectionChanged();
            Items.ForceCollectionChanged();
            UpdateChecks();
        }
        /// <summary>
        /// Replace a single, selected item
        /// <para>Attempts to propagate to the ListVM of ParentVM or calls ReplaceShownChild when appropriate</para>
        /// </summary>
        /// <param name="newItem">New item to replace the single selected item with</param>
        public void ReplaceSelectedChild(ListItemVM newItem)
        {
            if (newItem == null)
            {
                return;
            }

            if (ParentItemVM == null)
            {
                if (ParentVM != null)
                {
                    ParentVM.ReplaceSelectedItem(newItem);
                }
            }
            else
            {
                ReplaceShownChild(this, newItem);
            }
        }
Beispiel #4
0
        /// <summary>
        /// If only one, selected item is chosen by the user, replace it with a new item
        /// </summary>
        /// <param name="newItem">The new item to replace the old with</param>
        /// <param name="selected">If false, will search for only 1 non-selected item; otherwise will search for 1 selected item only</param>
        public void ReplaceSelectedItem(ListItemVM newItem, bool selected = true)
        {
            if (newItem == null)
            {
                return;
            }

            if (Items.Items.Count == 1)
            {
                if (Items.Items[0].IsChosen == selected)
                {
                    Items.InterruptCollectionChanged();
                    Items.Items.Clear();
                    Items.Items.Add(newItem);
                    Items.AllowCollectionChanged();
                    Items.ForceCollectionChanged();
                    UpdateChecks();
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Convert Child items into new ViewModel Items
        /// </summary>
        /// <param name="inItems">Children items to convert</param>
        /// <param name="parentVM">ListVM object that is the highest parent</param>
        /// <param name="itemParentVM">The parent Item's ViewModel</param>
        /// <returns>New range of ListItemVM objects for the children</returns>
        public static IEnumerable <ListItemVM> GetChildItems(IEnumerable <IcdCodeItem> inItems, SearchVM parentVM, ListItemVM itemParentVM)
        {
            var useParentTitle = new List <string>();

            if (itemParentVM != null)
            {
                useParentTitle.AddRange(itemParentVM.ParentTitle);
                useParentTitle.Add(itemParentVM.Title.Title);
            }

            var resultGroups = from child in inItems
                               group child by child.Code.ChildType;


            var directChildren = (from result in resultGroups
                                  where result.Key == IcdCodeStrings.ChildType_Direct
                                  from ret in result
                                  select ret).ToList();

            if (directChildren.Count > 0)
            {
                yield return(new ListItemVM(0, IcdCodeItemMethods.NewDividerItem(SpecificityString), Enumerable.Empty <string>())
                {
                    ParentVM = parentVM,
                    ParentItemVM = itemParentVM
                });

                foreach (var child in directChildren)
                {
                    yield return(new ListItemVM(0, child, useParentTitle)
                    {
                        ParentVM = parentVM,
                        ParentItemVM = itemParentVM
                    });
                }
                yield break;
            }

            foreach (var type in ChildTypes)
            {
                var currChildren = (from result in resultGroups
                                    where result.Key == type.Key
                                    from ret in result
                                    select ret).ToList();
                if (currChildren.Count > 0)
                {
                    yield return(new ListItemVM(0, IcdCodeItemMethods.NewDividerItem(type.Value), Enumerable.Empty <string>())
                    {
                        ParentVM = parentVM,
                        ParentItemVM = itemParentVM
                    });

                    foreach (var child in currChildren)
                    {
                        yield return(new ListItemVM(0, child, Enumerable.Empty <string>())
                        {
                            ParentVM = parentVM,
                            ParentItemVM = itemParentVM
                        });
                    }
                }
            }
        }