private DistributionViewModel FindDistributionByPath(string path) { foreach (HierarchicalViewModelBase model in _model) { DistributionViewModel found = null; model.Traverse((item) => { var dvm = item as DistributionViewModel; if (dvm != null && dvm.DistRegionFullPath == path) { found = dvm; } }); if (found != null) { return(found as DistributionViewModel); } } return(null); }
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; }
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; }