예제 #1
0
        public CriteriaItemViewModel(ICrit crit, Action beforeInsert)
        {
            Contract.Requires(crit != null);

            this.beforeInsert = beforeInsert;
            this.crit         = crit;
            if (crit is Estimator)
            {
                var est = crit as Estimator;
                est.CriteriaGroups
                .Select(i => new CriteriaItemViewModel(i, beforeInsert))
                .ForEach(v => Children.Add(v));

                est.CriteriaGroupsChanged += nested_ICrit_Changed;
            }
            else if (crit is CriteriaGroup)
            {
                var cg = crit as CriteriaGroup;
                cg.Criteria
                .Select(i => new CriteriaItemViewModel(i, beforeInsert))
                .ForEach(v => Children.Add(v));

                cg.CriteriaChanged += nested_ICrit_Changed;
            }
            crit.PropertyChanged += crit_PropertyChanged;

            IsExpanded = true;
        }
예제 #2
0
        private void ShowEditor(ICrit crit)
        {
            if (CurrentEditor != null && (CurrentEditor as ICritKeeper).Crit == crit)
            {
                return; // уже открыт
            }
            naviagationExpected = crit != null;
            CloseEditor();
            naviagationExpected = false;

            if (crit is Estimator)
            {
                CurrentEditor = new EstimatorEditorViewModel(crit as Estimator);
            }
            else if (crit is CriteriaGroup)
            {
                CurrentEditor = new CriteriaGroupEditorViewModel(crit as CriteriaGroup);
            }
            else if (crit is Criterion)
            {
                CurrentEditor = new CriterionEditorViewModel(crit as Criterion);
            }

            if (CurrentEditor != null)
            {
                CurrentEditor.OnDialogResult((r) => CloseEditor());
            }
        }
예제 #3
0
        internal void Open(ICrit crit)
        {
            Contract.Requires(crit != null);
            logger.DebugFormat("open {0}", crit);

            Navigator.NavigateTo(crit);
        }
예제 #4
0
        private void OnCritDeleted(ICrit crit)
        {
            viewer.RemoveFromHistory(crit);

            if (crit is Estimator)
            {
                Navigator.RemoveRoot(crit as Estimator);
            }
        }
예제 #5
0
 private void DeleteCrit(ICrit crit)
 {
     if (crit is CriteriaGroup)
     {
         var crgr = crit as CriteriaGroup;
         crgr.Estimator.RemoveCriteriaGroup(crgr);
     }
     else if (crit is Criterion)
     {
         var cr = crit as Criterion;
         cr.Group.RemoveCriterion(cr);
         Session.DoSave(viewer.OpenedRoot);
     }
 }
예제 #6
0
        public static Estimator GetEstimator(this ICrit crit)
        {
            Contract.Requires(crit != null);

            if (crit is Estimator)
            {
                return(crit as Estimator);
            }
            if (crit is CriteriaGroup)
            {
                return((crit as CriteriaGroup).Estimator);
            }
            if (crit is Criterion)
            {
                return((crit as Criterion).Group == null ? null : (crit as Criterion).Group.Estimator);
            }

            throw new NotImplementedException();
        }
예제 #7
0
        public static T FindCritKeeperOf <T>(this IEnumerable <T> root, ICrit crit)
            where T : HierarchicalBase <T>, ICritKeeper
        {
            crit = crit.Actual as ICrit;
            T vm;

            foreach (var item in root)
            {
                if (item.Crit.Actual == crit)
                {
                    return(item);
                }
                vm = item.AllChildren.Where(x => x.Crit.Actual == crit).FirstOrDefault();
                if (vm != null)
                {
                    return(vm);
                }
            }
            return(null);
        }
예제 #8
0
 /// <summary>
 /// Создает и тут же вызывает Open(entity).
 /// </summary>
 public CriteriaViewModel(ICrit entity)
     : this()
 {
     Open(entity);
 }