Exemplo n.º 1
0
        public void RejectChanges()
        {
            if (_CollectedObject is IEditableObject)
            {
                ((IEditableObject)_CollectedObject).CancelEdit();
            }

            if (object.Equals(_Clone, default(T)))
            {
                if (Status == ObjectStatusType.Deleted)
                {
                    _Status = ObjectStatusType.Normal;
                    _PropertyChanged(this, new PropertyChangedEventArgs(""));
                }
                return;
            }
            _CollectedObject = _Clone;
            if (_CollectedObject is INotifyPropertyChanged)             // INotifyPropertyChanging
            {
                _Clone = default(T);
            }
            else
            {
                SaveClone(true);
            }
            _Status = ObjectStatusType.Normal;
            _PropertyChanged(this, new PropertyChangedEventArgs(""));
        }
Exemplo n.º 2
0
 private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (_PropertyChanged != null)
     {
         if (_Status == ObjectStatusType.Normal)
         {
             _Status = ObjectStatusType.Modified;
         }
         _PropertyChanged(this, e);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Change forcibly the state of an Item
 /// </summary>
 /// <param name="Item">Item to set</param>
 /// <param name="StatusType">State to force</param>
 protected void SetObjectStatus(Box <T> Item, ObjectStatusType StatusType)
 {
     if (!Item.Equals(this._CurrentStorageElement))
     {
         _CurrentStorageElement = Item;
     }
     _CurrentStorageElement.Storage.Status = StatusType;
     if (!IsVisible(_CurrentStorageElement))
     {
         _InvisibleCount++;
     }
 }
Exemplo n.º 4
0
 public void AcceptChanges()
 {
     _Status = ObjectStatusType.Normal;
     if (_CollectedObject is INotifyPropertyChanged)             // INotifyPropertyChanging
     {
         _Clone = default(T);
     }
     else
     {
         SaveClone(true);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Change forcibly the state of an Item
 /// </summary>
 /// <param name="Item">Item to set</param>
 /// <param name="StatusType">State to force</param>
 public void SetObjectStatus(T Item, ObjectStatusType StatusType)
 {
     if (!Item.Equals(this._CurrentStorageElement.Storage.CollectedObject))
     {
         _CurrentStorageElement = this.GetExternalStorage(Item);
     }
     _CurrentStorageElement.Storage.Status = StatusType;
     if (!IsVisible(_CurrentStorageElement))
     {
         _InvisibleCount++;
     }
 }
        /// <summary>
        /// Handler that receives Storage(T) notifications if a T property has changed
        /// </summary>
        /// <param name="sender">An object of type T</param>
        /// <param name="e">Name of the property that has changed</param>
        private void CollectedItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (!(sender is Storage <T>))
            {
                return;
            }
            Storage <T>      Item         = (Storage <T>)sender;
            string           PropertyName = e.PropertyName;
            ObjectStatusType StatusType   = Item.Status;
            // Its state has been modified in Storage(T) inside OnPropertyChanged method

            int index = this.IndexOf(Item.CollectedObject);

            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, index));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Return a symbol to represent the state of the object
        /// Used by the ToString() methods of this collection<para/>
        /// Normal       = <para/>
        /// Added        + <para/>
        /// Deleted      X <para/>
        /// Modified     U <para/>
        /// PendingAdded P <para/>
        /// </summary>
        /// <param name="StatusType">State to obtain the corresponding symbol</param>
        /// <returns>The symbol representing the given state</returns>
        private string MapStateSymbol(ObjectStatusType StatusType)
        {
            switch (StatusType)
            {
            case ObjectStatusType.Normal:
                return("=");

            case ObjectStatusType.Added:
                return("+");

            case ObjectStatusType.Deleted:
                return("X");

            case ObjectStatusType.Modified:
                return("U");

            case ObjectStatusType.PendingAdded:
                return("P");
            }
            return("?");
        }
Exemplo n.º 8
0
        /// <summary>
        /// TODO: verify a problem: Index is relative to the filter but GetNodeAt has pre-calculated this
        /// TODO: need unit testing
        ///
        /// Insert an Item at the specified index forcing its state
        /// </summary>
        /// <param name="index">Index to insert the item</param>
        /// <param name="value">Item to insert</param>
        /// <param name="StatusType">State to force for the item</param>
        public void Insert(int index, T value, ObjectStatusType StatusType)
        {
            Storage <T> Store = new Storage <T>(value, StatusType);

            OnBeforeAdd(Store);
            if (index > _ArrayCount - _InvisibleCount)
            {
                throw new ArgumentOutOfRangeException();
            }

            if (BaseArray.Length == _ArrayCount)
            {
                GrowArray();
            }
            // calcolo il vero index
            int RealIndex = CalculateRealIndex(index);

            if (RealIndex == -1)
            {
                RealIndex = Count;
            }
            if (RealIndex < _ArrayCount)
            {
                Array.Copy(BaseArray, RealIndex, BaseArray, RealIndex + 1, _ArrayCount - RealIndex);
            }
            Box <T> Element = new Box <T>(Store, true);

            _CurrentStorageElement = Element;

            BaseArray[RealIndex] = Element;
            _ArrayCount++;
            RecalcFilter(false);
            if (!IsVisible(Element))
            {
                _InvisibleCount++;
            }
            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index));

            OnAfterAdd(Store);
        }
Exemplo n.º 9
0
 public Storage(T Object)
 {
     _CollectedObject = Object;
     _Clone           = default(T);
     _Status          = ObjectStatusType.Normal;
 }
Exemplo n.º 10
0
 public Storage(T Object, ObjectStatusType StatusType)
     : this(Object)
 {
     Status = StatusType;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Add an element to the collection
        /// </summary>
        /// <param name="Item">Item to add</param>
        /// <param name="StatusType">Item state to force for this item</param>
        /// <returns>Index of the added item (Count-1)</returns>
        public int Add(T Item, ObjectStatusType StatusType)
        {
            Box <T> Elem = new Box <T>(new Storage <T>(Item, StatusType), true);

            return(Add(Elem));
        }