protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            base.OnCollectionChanged(e);

            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (_I item in e.NewItems)
                {
                    var parentName = CremaDataTable.GetParentName(item.Name);
                    if (parentName != string.Empty)
                    {
                        item.Parent = this[parentName];
                    }
                    item.TableInfoChanging += Item_TableInfoChanging;
                    item.TableInfoChanged  += Item_TableInfoChanged;
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (_I item in e.OldItems)
                {
                    item.TableInfoChanging -= Item_TableInfoChanging;
                    item.TableInfoChanged  -= Item_TableInfoChanged;
                    item.TemplatedParent    = null;
                }
            }
        }
Example #2
0
        private void UpdateItemsSource()
        {
            var viewModels         = new Dictionary <string, TreeViewItemViewModel>();
            var dataSet            = this.shell.DataSet;
            var categories         = dataSet.ExtendedProperties[CremaSchema.TableDirectory] as string[];
            var compositionService = this.ServiceProvider.GetService(typeof(ICompositionService)) as ICompositionService;

            foreach (var item in categories)
            {
                if (item == PathUtility.Separator)
                {
                    viewModels.Add(item, new DataBaseTreeViewItemViewModel(dataSet, this));
                }
                else
                {
                    viewModels.Add(item, new CategoryTreeViewItemViewModel(dataSet, item, this));
                }
            }
            foreach (var item in dataSet.Tables)
            {
                viewModels.Add(item.CategoryPath + item.Name, new TableTreeViewItemViewModel(item, this));
            }

            foreach (var item in viewModels)
            {
                compositionService.SatisfyImportsOnce(item.Value);
                if (item.Key == PathUtility.Separator)
                {
                }
                else
                {
                    if (NameValidator.VerifyCategoryPath(item.Key) == true)
                    {
                        var categoryName = new CategoryName(item.Key);
                        item.Value.Parent = viewModels[categoryName.ParentPath];
                    }
                    else
                    {
                        var itemName = new ItemName(item.Key);

                        if (itemName.Name.IndexOf('.') > 0)
                        {
                            var parentName = CremaDataTable.GetParentName(itemName.Name);
                            item.Value.Parent = viewModels[itemName.CategoryPath + parentName];
                        }
                        else
                        {
                            item.Value.Parent = viewModels[itemName.CategoryPath];
                        }
                    }
                }
            }

            this.Items.Clear();
            this.Items.Add(viewModels[PathUtility.Separator]);
        }