Example #1
0
        public static PropertyChangeEvent CreateUpdateEvent(object source, string property, object newValue, object oldValue)
        {
            PropertyChangeEvent e = new PropertyChangeEvent(PROPERTY_CHANGE)
            {
                Kind     = PropertyChangeEventKind.UPDATE,
                OldValue = oldValue,
                NewValue = newValue,
                Source   = source,
                Property = property
            };

            return(e);
        }
		public static PropertyChangeEvent CreateUpdateEvent(object source, string property, object newValue, object oldValue)
		{
			PropertyChangeEvent e = new PropertyChangeEvent(PROPERTY_CHANGE)
										{
											Kind = PropertyChangeEventKind.UPDATE,
											OldValue = oldValue,
											NewValue = newValue,
											Source = source,
											Property = property
										};

			return e;
		}
Example #3
0
        /// <summary>
        /// Notify the view that an item has been updated
        /// </summary>
        /// <param name="item"></param>
        /// <param name="property"></param>
        /// <param name="oldValue"></param>
        /// <param name="newValue"></param>
        public void ItemUpdated(object item, object property = null, object oldValue = null, object newValue = null)
        {
            PropertyChangeEvent pce = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE)
                                            {
                                                Kind = PropertyChangeEventKind.UPDATE,
                                                Source = item,
                                                Property = property.ToString(),
                                                OldValue = oldValue,
                                                NewValue = newValue
                                            };

            ItemUpdateHandler(pce);        
        }  
Example #4
0
        /// <summary>
        /// Dispatches a collection event with the specified information.
        /// </summary>
        /// <param name="kind"></param>
        /// <param name="item"></param>
        /// <param name="location"></param>
        private void InternalDispatchEvent(CollectionEventKind kind, object item = null, int location= -1)
        {
            //Debug.Log(string.Format("InternalDispatchEvent: {0}, {1}, {2}", kind, item, location));
            if (_dispatchEvents == 0)
            {
                if (HasEventListener(CollectionEvent.COLLECTION_CHANGE))
                {
                    var ce = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE) { Kind = kind };
                    ce.Items.Add(item);
                    ce.Location = location;
                    DispatchEvent(ce);
                }

                // now dispatch a complementary PropertyChangeEvent
                if (HasEventListener(PropertyChangeEvent.PROPERTY_CHANGE) && 
                   (kind == CollectionEventKind.ADD || kind == CollectionEventKind.REMOVE))
                {
                    var objEvent = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE) {Property = location.ToString()};
                    if (kind == CollectionEventKind.ADD)
                        objEvent.NewValue = item;
                    else
                        objEvent.OldValue = item;
                    DispatchEvent(objEvent);
                }
            }
        }
Example #5
0
 /**
  *  Place the item at the specified index.  
  *  If an item was already at that index the new item will replace it and it 
  *  will be returned.
  *
  *  Param:  item the new value for the index
  *  Param:  index the index at which to place the item
  *  Returns: the item that was replaced, null if none
  *  @throws RangeError if index is less than 0 or greater than or equal to length
  */
 public virtual object SetItemAt(object item, int index)
 {
     if (index < 0 || index >= Length) 
     {
         throw new IndexOutOfRangeException("Range error");
     }
     
     object oldItem = Source[index];
     Source[index] = item;
     StopTrackUpdates(oldItem);
     StartTrackUpdates(item);
     
     //dispatch the appropriate events 
     if (_dispatchEvents == 0)
     {
         var hasCollectionListener = HasEventListener(CollectionEvent.COLLECTION_CHANGE);
         var hasPropertyListener = HasEventListener(PropertyChangeEvent.PROPERTY_CHANGE);
         PropertyChangeEvent updateInfo = null; 
         
         if (hasCollectionListener || hasPropertyListener)
         {
             updateInfo = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE)
                              {
                                  Kind = PropertyChangeEventKind.UPDATE,
                                  OldValue = oldItem,
                                  NewValue = item,
                                  Property = index.ToString()
                              };
         }
         
         if (hasCollectionListener)
         {
             CollectionEvent ce = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE)
                                      {
                                          Kind = CollectionEventKind.REPLACE,
                                          Location = index
                                      };
             ce.Items.Add(updateInfo);
             DispatchEvent(ce);
         }
         
         if (hasPropertyListener)
         {
             DispatchEvent(updateInfo);
         }
     }
     return oldItem;    
 }