Ejemplo n.º 1
0
        private void NameChangedHandler(string prevName, IDataItem item)
        {
            if (prevName == item.Name) // ignore identical names
            {
                return;
            }
            if (mNameToItem.ContainsKey(item.Name)) // check duplicate names
            {
                item.CancelNameChange();
                throw new ChartDuplicateItemException(String.Format("A {0} by that name already exists in the data source", ItemTypeName));
            }

            if (prevName != null && mNameToItem.Remove(prevName) == false)
            {
                item.CancelNameChange();
                throw new ChartException(String.Format("Renaming {0} failed", ItemTypeName));
            }
            if (item.Name != null)
            {
                mNameToItem.Add(item.Name, (T)item);
            }
            if (NameChanged != null)
            {
                NameChanged(prevName, item);
            }
        }