Ejemplo n.º 1
0
        private void AddViewModelByPath(ObservableCollection <HierarchicalViewModelBase> collection, TaxonDistribution model)
        {
            String[] bits = model.DistRegionFullPath.Split('\\');
            var      pCol = collection;
            HierarchicalViewModelBase parent = null;

            for (int i = 0; i < bits.Length; ++i)
            {
                string bit     = bits[i];
                var    current = pCol.FirstOrDefault((candidate) => { return(candidate.DisplayLabel == bit); });
                if (current == null)
                {
                    if (i == bits.Length - 1)
                    {
                        current              = new DistributionViewModel(model, bit);
                        current.Parent       = parent;
                        current.DataChanged += new DataChangedHandler((d) => {
                            RegisterUniquePendingChange(new SaveDistributionRegionsCommand(Taxon.Taxon, _model));
                        });
                    }
                    else
                    {
                        current        = new DistributionPlaceholder(bit);
                        current.Parent = parent;
                        parent         = current;
                    }
                    pCol.Add(current);
                }
                else
                {
                    parent = current;
                    if (i == bits.Length - 1)
                    {
                        // This region exists already, but will be overridden by this one...
                        (current as DistributionViewModel).Model = model;
                    }
                }
                pCol = current.Children;
            }
            // return result;
        }
Ejemplo n.º 2
0
 private void AddViewModelByPath(ObservableCollection<HierarchicalViewModelBase> collection, TaxonDistribution model)
 {
     String[] bits = model.DistRegionFullPath.Split('\\');
     var pCol = collection;
     HierarchicalViewModelBase parent = null;
     for (int i = 0; i < bits.Length; ++i) {
         string bit = bits[i];
         var current = pCol.FirstOrDefault((candidate) => { return candidate.DisplayLabel == bit; });
         if (current == null) {
             if (i == bits.Length - 1) {
                 current = new DistributionViewModel(model, bit);
                 current.Parent = parent;
                 current.DataChanged += new DataChangedHandler((d) => {
                     RegisterUniquePendingChange(new SaveDistributionRegionsCommand(Taxon.Taxon, _model));
                 });
             } else {
                 current = new DistributionPlaceholder(bit);
                 current.Parent = parent;
                 parent = current;
             }
             pCol.Add(current);
         } else {
             parent = current;
             if (i == bits.Length - 1) {
                 // This region exists already, but will be overridden by this one...
                 (current as DistributionViewModel).Model = model;
             }
         }
         pCol = current.Children;
     }
     // return result;
 }