Пример #1
0
        private IValidationErrors GetErrors(IValidationErrors result, RowPresenter rowPresenter, IColumns source, bool isAsync)
        {
            IReadOnlyDictionary <RowPresenter, IDataValidationErrors> dictionary = isAsync ? _asyncErrorsByRow : _errorsByRow;

            if (dictionary != null)
            {
                IDataValidationErrors errors;
                if (dictionary.TryGetValue(rowPresenter, out errors))
                {
                    if (errors != null && errors.Count > 0)
                    {
                        result = GetErrors(result, rowPresenter, errors, source, !isAsync);
                    }
                }
            }

            if (isAsync && rowPresenter == CurrentRow)
            {
                foreach (var asyncValidator in AsyncValidators)
                {
                    var fault = asyncValidator.GetFault(source);
                    if (fault != null)
                    {
                        result = result.Add(fault);
                    }
                }
            }

            return(result);
        }
Пример #2
0
        internal bool HasError(RowPresenter rowPresenter, IColumns source, bool isAsync)
        {
            IReadOnlyDictionary <RowPresenter, IDataValidationErrors> dictionary = isAsync ? _asyncErrorsByRow : _errorsByRow;

            if (dictionary != null)
            {
                IDataValidationErrors errors;
                if (dictionary.TryGetValue(rowPresenter, out errors))
                {
                    if (errors != null && errors.Count > 0 && HasError(rowPresenter, errors, source, !isAsync))
                    {
                        return(true);
                    }
                }
            }

            if (isAsync && rowPresenter == CurrentRow)
            {
                foreach (var asyncValidator in AsyncValidators)
                {
                    if (asyncValidator.GetFault(source) != null)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #3
0
        private bool HasError(RowPresenter rowPresenter, IColumns columns)
        {
            if (ErrorsByRow.Count == 0)
            {
                return(false);
            }

            IDataValidationErrors errors;

            if (!ErrorsByRow.TryGetValue(rowPresenter, out errors))
            {
                return(false);
            }

            for (int i = 0; i < errors.Count; i++)
            {
                var message = errors[i];
                if (message.Source.SetEquals(columns))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #4
0
        private bool HasVisibleError(RowPresenter rowPresenter, bool isAsync)
        {
            IReadOnlyDictionary <RowPresenter, IDataValidationErrors> dictionary = isAsync ? _asyncErrorsByRow : _errorsByRow;

            if (dictionary != null)
            {
                IDataValidationErrors errors;
                if (dictionary.TryGetValue(rowPresenter, out errors))
                {
                    if (errors != null && errors.Count > 0 && errors.Any(x => IsVisible(rowPresenter, x.Source)))
                    {
                        return(true);
                    }
                }
            }

            if (isAsync && rowPresenter == CurrentRow)
            {
                if (AsyncValidators.Any(x => x.Status == AsyncValidatorStatus.Faulted))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #5
0
        /// <summary>
        /// Gets the flushing error.
        /// </summary>
        /// <param name="rowPresenter">The row presenter.</param>
        /// <returns>The flushing error.</returns>
        public FlushingError GetFlushingError(RowPresenter rowPresenter)
        {
            RowBinding rowBinding = RowBinding;
            var        element    = rowBinding[rowPresenter];

            return(element != null?GetFlushingError(element) : null);
        }
Пример #6
0
        /// <summary>
        /// Gets the view element for specified <see cref="RowPresenter"/>.
        /// </summary>
        /// <param name="rowPresenter">The specified <see cref="RowPresenter"/>.</param>
        /// <returns>The view element.</returns>
        public UIElement this[RowPresenter rowPresenter]
        {
            get
            {
                if (Ordinal == -1)
                {
                    return(null);
                }

                if (Parent != null)
                {
                    return(Parent.GetChild(Parent[rowPresenter], Ordinal));
                }

                if (rowPresenter == null || rowPresenter.Template != Template)
                {
                    return(null);
                }

                var rowView = rowPresenter.View;
                if (rowView == null)
                {
                    return(null);
                }
                var elements = rowView.Elements;
                return(elements == null ? null : elements[Ordinal]);
            }
        }
Пример #7
0
 /// <summary>
 /// Begins inserting new row after specified row.
 /// </summary>
 /// <param name="row">The specified row. If <see langword="null"/>, insert at the end.</param>
 public void BeginInsertAfter(RowPresenter row = null)
 {
     VerifyInsert(row);
     SuspendInvalidateView();
     RequireLayoutManager().BeginInsertAfter(null, row);
     ResumeInvalidateView();
 }
Пример #8
0
        internal bool HasError(RowPresenter rowPresenter, Input <RowBinding, IColumns> input, bool?blockingPrecedence)
        {
            if (rowPresenter == CurrentRow)
            {
                var flushingError = GetFlushingError(input.Binding[rowPresenter]);
                if (flushingError != null)
                {
                    return(true);
                }
            }

            if (blockingPrecedence.HasValue)
            {
                if (AnyBlockingErrorInput(rowPresenter, input, blockingPrecedence.Value))
                {
                    return(false);
                }
            }

            if (HasError(rowPresenter, input.Target, false))
            {
                return(true);
            }
            if (HasError(rowPresenter, input.Target, true))
            {
                return(true);
            }
            return(false);
        }
Пример #9
0
 private void ClearAsyncErrors(RowPresenter rowPresenter)
 {
     Debug.Assert(rowPresenter != null);
     if (_asyncErrorsByRow != null && _asyncErrorsByRow.ContainsKey(rowPresenter))
     {
         _asyncErrorsByRow.Remove(rowPresenter);
     }
 }
Пример #10
0
 internal void Refresh(T element, RowPresenter rowPresenter)
 {
     if (!IsFlushing && !IsLockedByFlushingError(element))
     {
         RowBinding.Refresh(element, rowPresenter);
     }
     element.RefreshValidation(GetValidationInfo(rowPresenter));
 }
Пример #11
0
 private void UpdateAsyncErrors(RowPresenter rowPresenter, IDataValidationErrors errors)
 {
     ClearAsyncErrors(rowPresenter);
     if (errors.Count > 0)
     {
         AsyncErrorsByRow.Add(rowPresenter, errors);
     }
 }
Пример #12
0
 private static void Refresh(Placeholder element, RowPresenter rowPresenter, double desiredWidth, double desiredHeight, Action <Placeholder, RowPresenter> onRefresh)
 {
     element.DesiredWidth  = desiredWidth;
     element.DesiredHeight = desiredHeight;
     if (onRefresh != null)
     {
         onRefresh(element, rowPresenter);
     }
 }
Пример #13
0
 internal void InsertChild(int index, RowPresenter child)
 {
     Debug.Assert(index >= 0 && index <= Children.Count);
     if (_children == null)
     {
         _children = new List <RowPresenter>();
     }
     _children.Insert(index, child);
 }
Пример #14
0
        /// <summary>
        /// Begins inserting child row after specified child row.
        /// </summary>
        /// <param name="child">The specified child row, <see langword="null"/> if insert as last child row.</param>
        public void BeginInsertAfter(RowPresenter child = null)
        {
            VerifyInsert(child);
            var elementManager = ElementManager;

            elementManager?.SuspendInvalidateView();
            RowManager.BeginInsertAfter(this, child);
            elementManager?.ResumeInvalidateView();
        }
Пример #15
0
 internal sealed override void PerformSetup(RowPresenter rowPresenter)
 {
     Setup(SettingUpElement, rowPresenter);
     Refresh(SettingUpElement, rowPresenter);
     if (Input != null)
     {
         Input.Attach(SettingUpElement);
     }
 }
Пример #16
0
 private bool Validate(RowPresenter rowPresenter, ref int errors, int errorLimit)
 {
     Debug.Assert(rowPresenter != null);
     rowPresenter.Validate(false);
     if (Errors.ContainsKey(rowPresenter))
     {
         errors++;
     }
     return(errors < errorLimit);
 }
Пример #17
0
 private static void SetRowPresenter(this UIElement element, RowPresenter value)
 {
     if (value == null)
     {
         element.ClearValue(RowPresenterProperty);
     }
     else
     {
         element.SetValue(RowPresenterProperty, value);
     }
 }
Пример #18
0
        private void VerifyRowPresenter(RowPresenter value, string paramName, int index = -1)
        {
            if (value == null)
            {
                throw new ArgumentNullException(GetParamName(paramName, index));
            }

            if (value.DataPresenter != this || value.Index < 0)
            {
                throw new ArgumentException(DiagnosticMessages.DataPresenter_InvalidRowPresenter, GetParamName(paramName, index));
            }
        }
Пример #19
0
        internal void ShowAll(RowPresenter rowPresenter)
        {
            if (_progress == null)
            {
                return;
            }

            if (_valueChanged.ContainsKey(rowPresenter))
            {
                _valueChanged.Remove(rowPresenter);
            }
            _progress[rowPresenter] = null;
        }
Пример #20
0
 private void VerifyInsert(RowPresenter row)
 {
     if (!CanInsert)
     {
         throw new InvalidOperationException(DiagnosticMessages.DataPresenter_VerifyCanInsert);
     }
     if (row != null)
     {
         if (row.DataPresenter != this || row.Parent != null)
         {
             throw new ArgumentException(DiagnosticMessages.DataPresenter_InvalidRowPresenter, nameof(row));
         }
     }
 }
Пример #21
0
        private bool DoFlush(RowPresenter rowPresenter, T element)
        {
            bool result = false;

            for (int i = 0; i < _flushFuncs.Count; i++)
            {
                var flush   = _flushFuncs[i];
                var flushed = flush(rowPresenter, element);
                if (flushed)
                {
                    result = true;
                }
            }
            return(result);
        }
Пример #22
0
 private void VerifyInsert(RowPresenter child)
 {
     if (child == null)
     {
         VerifyNoPendingEdit();
     }
     else
     {
         if (child.Parent != this)
         {
             throw new ArgumentException(DiagnosticMessages.RowPresenter_InvalidChildRow, nameof(child));
         }
         child.VerifyNoPendingEdit();
     }
 }
Пример #23
0
 internal void ExitEdit(RowPresenter rowAfterEditing)
 {
     Debug.Assert(!CurrentRow.IsEditing);
     if (_progress != null && rowAfterEditing != null)
     {
         Validate(rowAfterEditing, false);
     }
     _snapshot       = null;
     _flushingErrors = null;
     if (rowAfterEditing != null)
     {
         ClearAsyncErrors(rowAfterEditing);
     }
     Template.RowAsyncValidators.ForEach(x => x.Reset());
 }
Пример #24
0
        internal sealed override void PerformSetup(RowPresenter rowPresenter)
        {
            for (int i = 0; i < _childBindings.Count; i++)
            {
                var childBinding = _childBindings[i];
                if (childBinding.GetSettingUpElement() != null)
                {
                    childBinding.Setup(rowPresenter);
                }
            }
            _onRefresh?.Invoke(SettingUpElement, rowPresenter);

            var rowElement = SettingUpElement as IRowElement;

            rowElement?.Setup(rowPresenter);
        }
Пример #25
0
        /// <summary>
        /// Selects specified <see cref="RowPresenter"/>.
        /// </summary>
        /// <param name="rowPresenter">The specified <see cref="RowPresenter"/>.</param>
        /// <param name="selectionMode">The selection mode.</param>
        /// <param name="ensureVisible">Indicates whether selected row must be visible.</param>
        /// <param name="beforeSelecting">A delegate will be invoked before selectinng.</param>
        public void Select(RowPresenter rowPresenter, SelectionMode selectionMode, bool ensureVisible = true, Action beforeSelecting = null)
        {
            VerifyRowPresenter(rowPresenter, nameof(rowPresenter));

            var oldCurrentRow = CurrentRow;

            beforeSelecting?.Invoke();
            SuspendInvalidateView();
            CurrentRow = rowPresenter;
            RequireLayoutManager().Select(rowPresenter, selectionMode, oldCurrentRow);
            ResumeInvalidateView();
            if (ensureVisible && Scrollable != null)
            {
                Scrollable.EnsureCurrentRowVisible();
            }
        }
Пример #26
0
        internal bool IsDescendantOf(RowPresenter rowPresenter)
        {
            if (rowPresenter == null)
            {
                return(false);
            }

            for (var parent = Parent; parent != null; parent = parent.Parent)
            {
                if (parent == rowPresenter)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #27
0
        /// <summary>
        /// Determines whether validation error is visible.
        /// </summary>
        /// <param name="rowPresenter">The <see cref="RowPresenter"/>.</param>
        /// <param name="columns">The columns.</param>
        /// <returns><see langword="true"/> if validation error is visible, otherwise <see langword="false"/>.</returns>
        public bool IsVisible(RowPresenter rowPresenter, IColumns columns)
        {
            rowPresenter.VerifyNotNull(nameof(rowPresenter));

            if (columns == null || columns.Count == 0)
            {
                return(false);
            }

            if (_progress == null)
            {
                return(true);
            }

            return(Exists(_progress, rowPresenter, columns));
        }
Пример #28
0
        internal void Validate(RowPresenter rowPresenter, bool showAll)
        {
            Debug.Assert(rowPresenter != null);
            if (showAll)
            {
                ShowAll(rowPresenter);
            }
            ClearErrors(rowPresenter);
            var dataRow = rowPresenter.DataRow;
            var errors  = Validate(dataRow);

            if (errors != null && errors.Count > 0)
            {
                ErrorsByRow.Add(rowPresenter, errors);
            }
        }
Пример #29
0
 private bool AnyBlockingValidatingInput(RowPresenter rowPresenter, Input <RowBinding, IColumns> input, bool isPreceding)
 {
     for (int i = 0; i < Inputs.Count; i++)
     {
         if (input.Index == i)
         {
             continue;
         }
         var canBlock = isPreceding ? Inputs[i].IsPrecedingOf(input) : input.IsPrecedingOf(Inputs[i]);
         if (canBlock && IsValidatingStatus(rowPresenter, Inputs[i], null))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #30
0
        internal void OnRowDisposed(RowPresenter rowPresenter)
        {
            if (_progress != null)
            {
                if (_progress.ContainsKey(rowPresenter))
                {
                    _progress.Remove(rowPresenter);
                }
                if (_valueChanged.ContainsKey(rowPresenter))
                {
                    _valueChanged.Remove(rowPresenter);
                }
            }

            ClearErrors(rowPresenter);
            ClearAsyncErrors(rowPresenter);
        }