New Posts New Posts RSS Feed: RelatedEntityList events
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

RelatedEntityList events

 Post Reply Post Reply
Author
Sinnema View Drop Down
Groupie
Groupie
Avatar

Joined: 23-Mar-2009
Location: Muri AG, EU, CH
Posts: 54
Post Options Post Options   Quote Sinnema Quote  Post ReplyReply Direct Link To This Post Topic: RelatedEntityList events
    Posted: 15-Jan-2010 at 11:55pm
Hi,
 
We've constructed a pretty nifty bunch of classes that we call ObservableLists. These lists can do the following:
  • One can add new items to the lists.
  • The list than observes changes to the items in the list and tells all subscribed clients (using several mechanisms like INotifyProperyChanged, OnValueChanged, OnItemChanged, OnListChanged, etc.).
  • The different flavors are needed because there are incompatibilities between the different assemblies we use (like DevForce, WPF and .NET Collections).

The Classes we've written so far are:

  • ObservableList
  • FilteredObservableList
  • RelatedList
  • RelatedEntityList
  • AbstractSequenceHistoryList
  • AbstractIntersectingHistoryList

And there ViewModel counterparts. The list is still growing.

Now we have a problem with the RelatedEntityList of DevForce. It does a fine job of maintaining items correctly in the list but it does not tell our lists when changes in items of the list take place, other than CollectionChanged (items added, moved, deleted, etc) and PropertyChanged (a property of the list was changed).
 
We could add [AfterSet] interceptors for all properties of the items in the list but that would be like shooting a fly with a canon. Our ObservableLists depend on getting ValueChanged, ItemChanged, ListChanged and PropertyChanged events (overrides). Is there a way to get these kinds of events from the RelatedEntityList?
 
Regards,
Paul Sinnema
Diartis AG
 
Senior Developer at Diartis AG in Switzerland.
Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post Posted: 19-Jan-2010 at 1:36pm
I'm not quite understanding what your specific issue is with the RelatedEntityList. How do you provide the functionality you desire (specifically, notice about internal changes to the contained items) when you get your data from other sources?

Back to Top
Sinnema View Drop Down
Groupie
Groupie
Avatar

Joined: 23-Mar-2009
Location: Muri AG, EU, CH
Posts: 54
Post Options Post Options   Quote Sinnema Quote  Post ReplyReply Direct Link To This Post Posted: 20-Jan-2010 at 10:54pm
In our Entities (the partial class) we use an ObservableProperty. This class notifies other of changes to its value. Our classes register with these properties and act accordingly. We use the AfterSet interceptor of DevForce to set the values in our properties. All this code for propagating etc. is generated using T4. At the moment we don't use any other sources than the entities of DevForce and I don't think that is going to change soon.

Edited by Sinnema - 20-Jan-2010 at 10:55pm
Senior Developer at Diartis AG in Switzerland.
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 21-Jan-2010 at 9:29am
It is the entity itself that must provide the initial notification that it has been changed; so it seems to me that any wrapper list class you create that is supposed to forward this notification must set up handlers for the individual entities' PropertyChanged events so that it (the wrapper list) can know this has occurred and so forward this information to its own event subscribers. This would be true no matter how you get the entities with which your wrapper list will be populated.
Back to Top
Sinnema View Drop Down
Groupie
Groupie
Avatar

Joined: 23-Mar-2009
Location: Muri AG, EU, CH
Posts: 54
Post Options Post Options   Quote Sinnema Quote  Post ReplyReply Direct Link To This Post Posted: 23-Jan-2010 at 3:27am
Hi Greg,
 
Your right. In the mean time we've cooked up a solution. Below's (part of) our code. We attach to the ListChanged event and act accordingly. This class is base on a class we call the ObservableList<T> which already has an implementation of the OnListChanged event (override). The class uses the RelatedEntityList<T> of DevForce and maintains its own list (that's why there is a RefillList()). The class is build using the principal: 'First make it work, than make it better and than make it fast'. We've proved it works.
 
Regards,
Paul Sinnema
Diartis AG
 
   public override void OnListChanged(object sender, ObservableListChangedEventArgs e)
  {
   if (m_SuspendItemChangedEvents == 0)
   {
    switch (e.Action)
    {
     case ObservableListChangedAction.Add:
      base.OnListChanged(sender, e);
      AttachPropertyChangedEvents(e.NewItems);
      break;
     case ObservableListChangedAction.Remove:
      DetachPropertyChangedEvents(e.OldItems);
      base.OnListChanged(sender, e);
      break;
     case ObservableListChangedAction.Replace:
     case ObservableListChangedAction.Move:
      DetachPropertyChangedEvents(e.OldItems);
      base.OnListChanged(sender, e);
      AttachPropertyChangedEvents(e.NewItems);
      break;
     case ObservableListChangedAction.None:
     case ObservableListChangedAction.Reset:
     case ObservableListChangedAction.Resync:
      base.OnListChanged(sender, e);
      break;
     default:
      throw new InvalidArgumentException("e.Action", e.Action);
    }
   }
  }
private void AttachChangedEvents()
  {
   if (m_RelatedEntityList != null)
   {
    m_RelatedEntityList.CollectionChanged += RelatedEntityListCollectionChanged;
    AttachPropertyChangedEvents(m_RelatedEntityList);
   }
  }
  private void AttachPropertyChangedEvents(IList list)
  {
   foreach (T item in list)
   {
    item.PropertyChanged += ItemPropertyChanged;
   }
  }
  private void DetachChangedEvents()
  {
   if (m_RelatedEntityList != null)
   {
    m_RelatedEntityList.CollectionChanged -= RelatedEntityListCollectionChanged;
    DetachPropertyChangedEvents(m_RelatedEntityList);
   }
  }
  private void DetachPropertyChangedEvents(IList list)
  {
   foreach (T item in list)
   {
    item.PropertyChanged -= ItemPropertyChanged;
   }
  }
 
   private void ItemPropertyChanged(object sender, PropertyChangedEventArgs e)
  {
   if (sender is T)
   {
    int index = IndexOf((T)sender);
    if (index >= 0)
    {
     this.OnItemChanged(sender, new ItemPropertyChangedEventArgs(this, sender, index, e.PropertyName));
    }
    RefillList();
   }
  }


Edited by Sinnema - 23-Jan-2010 at 3:28am
Senior Developer at Diartis AG in Switzerland.
Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post Posted: 25-Jan-2010 at 11:22am
Thanks for sharing this, Paul.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down