Cancel Terminating WorkItem

Topics: CAB & Smart Client Software Factory
Feb 28, 2007 at 5:16 AM
Edited Feb 28, 2007 at 5:16 AM
I'm sure this is something that many of you have dealt with; I have a simple situation where a list of customers is on the left and the details of the selected customer are on the right. When a customer is 2x clicked in the list, I create and run a WorkItem to show the view(s) to work with the customer. Because I am not using a modal WindowWorkspace, it's possible to 2x click another customer and create an additional WI. What I would like to do is Terminate() the active WI when a user 2x clicks a different customer, then have my active smart part's presenter for the WI that is being terminated ask the user for confirmation to cancel the current WorkItem.

Here is the workflow I imagine:
1) 2x click Customer "A"
2) Create and run WorkItem passing Customer "A"'s model to the WorkItem
3) WorkItem shows view with Customer "A"'s details
4) 2x click Customer "B"
5) Get the active WorkItem and call Terminate()
6) Customer "A"'s Presenter catches an event like "OnTerminating" and if the model is dirty, asks the user if they are sure they want to cancel
7) If user says "no" the Terminate() call is cancelled, otherwise it's Terminated and the new WorkItem is started with Customer "B"

I hope that makes sense...

The WorkItem class has some interesting methods such as: OnTerminating which sounds like it might be just what I need.

The only way I can think to use this is to fire an event from OnTerminating that my Presenter would subscribe to, check the state of the model and if it's dirty, display a confirmation.

As I type this I'm realizing that it sounds more and more like a hack. So my question is, how do you all handle a situation where you only want the user to work with a single instance of a Use Case at a time and don't want to use a Modal WindowWorkspace?

Thank you for any suggestions or pointers to existing threads on the subject (I couldn't find any by searching...)

-Steve
Feb 28, 2007 at 4:11 PM
OK, so I found out how to subscribe to the terminating event, but I'm not seeing any wall to cancel a termination request. Anyone have a trick?
Feb 28, 2007 at 6:14 PM
Hi Steve,

Unfortunatelly there no way to cancel a “Terminating” event (as it is) since it lacks the CancelEventArgs that “Activating” and “Deactivating” have. The only way to add this capability would be to modify the OnTerminating, Dispose and ChangeStatus methods in the Workitem class inside CAB, but beware that code making use of OnTerminating will not be ready for the change so you might run into compatibility issues.

You have the option to extend Workitem with your own implementation of “Terminate” giving you the chance to cancel the call to Dispose (that will call “OnTerminating” in turn). This solution would be a last resort if you cannot produce the desired functionality at a higher level using events to control when a view should be closed.

Let me know if this helps,

Federico Delgado
http://staff.southworks.net/blogs/fdelgado