/// <summary>
        /// Sets the specified array as the items of the collection.
        /// </summary>
        /// <param name="editValue">The collection to edit.</param>
        /// <param name="value">An array of objects to set as the collection items.</param>
        /// <returns>
        /// The newly created collection object or, otherwise, the collection indicated by the <paramref name="editValue"/> parameter.
        /// </returns>
        protected override object SetItems(object editValue, object[] value)
        {
            object result = base.SetItems(editValue, value);

            IComponentChangeService svc        = _context.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
            INameController         controller = editValue as INameController;

            if (controller != null && svc != null && (editValue is ChartAreaCollection || editValue is LegendCollection))
            {
                IList newList         = (IList)result;
                bool  elementsRemoved = false;
                foreach (ChartNamedElement element in controller.Snapshot)
                {
                    if (newList.IndexOf(element) < 0)
                    {
                        elementsRemoved = true;
                    }
                }
                if (elementsRemoved)
                {
                    svc.OnComponentChanging(this._chart, null);
                    ChartNamedElement defaultElement = (ChartNamedElement)(newList.Count > 0 ? newList[0] : null);
                    foreach (ChartNamedElement element in controller.Snapshot)
                    {
                        if (newList.IndexOf(element) < 0)
                        {
                            controller.OnNameReferenceChanged(new NameReferenceChangedEventArgs(element, defaultElement));
                        }
                    }
                    svc.OnComponentChanged(this._chart, null, null, null);
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Removes the element at the specified index of the collection.
        /// </summary>
        /// <param name="index">The zero-based index of the element to remove.</param>
        protected override void RemoveItem(int index)
        {
            // Remember the removedElement
            ChartNamedElement removedElement = index < Count ? this[index] : null;

            if (_disableDeleteCount == 0)
            {
                ((INameController)this).OnNameReferenceChanged(new NameReferenceChangedEventArgs(removedElement, null));
            }
            base.RemoveItem(index);
            if (_disableDeleteCount == 0)
            {
                // All elements referencing the removed element will be redirected to the first element in collection
                // Fire the NameReferenceChanged event to update all the dependent elements
                ChartNamedElement defaultElement = this.Count > 0 ? this[0] : null;
                ((INameController)this).OnNameReferenceChanged(new NameReferenceChangedEventArgs(removedElement, defaultElement));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Replaces the element at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the element to replace.</param>
        /// <param name="item">The new value for the element at the specified index.</param>
        protected override void SetItem(int index, T item)
        {
            if (String.IsNullOrEmpty(item.Name))
            {
                item.Name = this.NextUniqueName();
            }
            else if (!IsUniqueName(item.Name) && IndexOf(item.Name) != index)
            {
                throw new ArgumentException(SR.ExceptionNameAlreadyExistsInCollection(item.Name, this.GetType().Name));
            }

            //If the item references other named references we might need to fix the references
            FixNameReferences(item);

            // Remember the removedElement
            ChartNamedElement removedElement = index < Count ? this[index] : null;

            ((INameController)this).OnNameReferenceChanging(new NameReferenceChangedEventArgs(removedElement, item));
            base.SetItem(index, item);
            // Fire the NameReferenceChanged event to update all the dependent elements
            ((INameController)this).OnNameReferenceChanged(new NameReferenceChangedEventArgs(removedElement, item));
        }
Esempio n. 4
0
 public NameReferenceChangedEventArgs(ChartNamedElement oldElement, string oldName, string newName)
 {
     _oldElement = oldElement;
     _oldName    = oldName;
     _newName    = newName;
 }
Esempio n. 5
0
 public NameReferenceChangedEventArgs(ChartNamedElement oldElement, ChartNamedElement newElement)
 {
     _oldElement = oldElement;
     _oldName    = oldElement != null ? oldElement.Name : string.Empty;
     _newName    = newElement != null ? newElement.Name : string.Empty;
 }