Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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]);
            }
        }
Exemple #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();
 }
Exemple #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);
        }
Exemple #9
0
 private void ClearAsyncErrors(RowPresenter rowPresenter)
 {
     Debug.Assert(rowPresenter != null);
     if (_asyncErrorsByRow != null && _asyncErrorsByRow.ContainsKey(rowPresenter))
     {
         _asyncErrorsByRow.Remove(rowPresenter);
     }
 }
Exemple #10
0
 internal void Refresh(T element, RowPresenter rowPresenter)
 {
     if (!IsFlushing && !IsLockedByFlushingError(element))
     {
         RowBinding.Refresh(element, rowPresenter);
     }
     element.RefreshValidation(GetValidationInfo(rowPresenter));
 }
Exemple #11
0
 private void UpdateAsyncErrors(RowPresenter rowPresenter, IDataValidationErrors errors)
 {
     ClearAsyncErrors(rowPresenter);
     if (errors.Count > 0)
     {
         AsyncErrorsByRow.Add(rowPresenter, errors);
     }
 }
Exemple #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);
     }
 }
Exemple #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);
 }
Exemple #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();
        }
Exemple #15
0
 internal sealed override void PerformSetup(RowPresenter rowPresenter)
 {
     Setup(SettingUpElement, rowPresenter);
     Refresh(SettingUpElement, rowPresenter);
     if (Input != null)
     {
         Input.Attach(SettingUpElement);
     }
 }
Exemple #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);
 }
Exemple #17
0
 private static void SetRowPresenter(this UIElement element, RowPresenter value)
 {
     if (value == null)
     {
         element.ClearValue(RowPresenterProperty);
     }
     else
     {
         element.SetValue(RowPresenterProperty, value);
     }
 }
Exemple #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));
            }
        }
Exemple #19
0
        internal void ShowAll(RowPresenter rowPresenter)
        {
            if (_progress == null)
            {
                return;
            }

            if (_valueChanged.ContainsKey(rowPresenter))
            {
                _valueChanged.Remove(rowPresenter);
            }
            _progress[rowPresenter] = null;
        }
Exemple #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));
         }
     }
 }
Exemple #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);
        }
Exemple #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();
     }
 }
Exemple #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());
 }
Exemple #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);
        }
Exemple #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();
            }
        }
Exemple #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);
        }
Exemple #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));
        }
Exemple #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);
            }
        }
Exemple #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);
 }
Exemple #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);
        }