EditLevel mismatch with multiple undo for hierarchical object model

EditLevel mismatch with multiple undo for hierarchical object model

Old forum URL: forums.lhotka.net/forums/t/3304.aspx


sai posted on Tuesday, July 31, 2007

I have few queries with multiple undo with hierarchical object model. The object model is something like this

BusinessBase<A> has "Bs" as data member

BusinessListBase<Bs,B>

BusinessBase<B> has "Cs" as data member

BusinessListBase<Cs,C>

BusinessBase<C>

I use instances of B and C for data binding.

With this object model if I want to implement multiple undo what is the best practice?

1. copy the state of root object i.e. A, for all scenarios 

2. copy the state of A, B or C whichever is applicable for that scenario. Can I keep a mix of such scenarios and work without getting any "EditLevel mismatch" errors?

    Copy the state of A if a data member "Bs" is modified i.e. a new member added or existing deleted

    Copy the state of B where it is bound to control and details for this object are modified

    Copy the state of C where it is bound to control and details for this object are modified

Thanks

RockfordLhotka replied on Tuesday, July 31, 2007

First, be aware that a bug was recently reported for this scenario, and CSLA 3.0.2 (in test) has a bug fix to address the problem.

Second, when you say "multiple undo" what do you mean?

The 3.0.2 fix means that you get one level of undo for the specific object(s) being edited by your grid controls. This makes data binding and the grid controls work properly.

If you also want a form-level Cancel button that complicates matters. To make that work, you need to do a manual BeginEdit() on your root object before binding to the form. Then in your Cancel button's click event, you must unbind all objects from the form and then manually call CancelEdit().

The 3.0 PTWin forms demonstrate how to unbind the objects from the form, so you can adapt that code to your needs.

sai replied on Tuesday, July 31, 2007

Thanks for the reply.

My code calls BeginEdit() and CancelEdit() manually. The operations with my object model are

- adding/removing members of Bs (which is a menber data of A),

- adding/removing members of Cs(which is a member data of B),

- modifying details of B

- modifying details of C

There is no particular order user may follow while performing above operations and these operations may get performed numerous times before actual save.

I would like to know if I want to implement multiple undo what should be best practice, always copy state of root parent object (A) or copy state of particular object (A or B or C) based on which operation is carried out.

Thanks

 

 

RockfordLhotka replied on Tuesday, July 31, 2007

There is no one best practice. It depends on what you are trying to accomplish in your UI.

 

If you are using data binding there are very specific best practices that you must follow or you’ll get sync exceptions.

 

But if you are calling n-level undo manually at all times, the only rule is that there must be symmetry. A BeginEdit() call must be paired with a corresponding CancelEdit() or ApplyEdit() call.

 

If you want a form-level Cancel button, then you’ll almost certainly start with a BeginEdit() call to your root object. If you want incremental undo on child objects, you’ll need to call BeginEdit() (and cancel/apply) on those child objects as appropriate. That’s what data binding does as the user starts/leaves editing of each child object.

 

Rocky

 

From: sai [mailto:cslanet@lhotka.net]
Sent: Tuesday, July 31, 2007 2:48 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] EditLevel mismatch with multiple undo for hierarchical object model

 

Thanks for the reply.

My code calls BeginEdit() and CancelEdit() manually. The operations with my object model are

- adding/removing members of Bs (which is a menber data of A),

- adding/removing members of Cs(which is a member data of B),

- modifying details of B

- modifying details of C

There is no particular order user may follow while performing above operations and these operations may get performed numerous times before actual save.

I would like to know if I want to implement multiple undo what should be best practice, always copy state of root parent object (A) or copy state of particular object (A or B or C) based on which operation is carried out.

Thanks

 

 



Copyright (c) Marimer LLC