TabbedWorkspace Issue

Topics: CAB & Smart Client Software Factory
Feb 20, 2007 at 3:19 PM
Hi. I am having an issue working with the TabbedWorkspace that I am hoping to get some help with. Here is the scenario: I have a smartpart that contains a treeview that I display in a workspace on the left side of the form. On the right side, I have a TabbedWorkspace. From the treeview, the user can right-click on various nodes to perform different actions. For example, they can right click on the "Security" node and select "Add User" from the context menu. This will cause an AddNewUser workitem to display the AddUserView in a new tab in the tabbed workspace. So there could be several tabs containing various views. I also have a Save button in the shell's toolbar. When the user clicks that, a command gets fired, and I would like for the current tab to handle that save.

Well, the problem that I am having is, I trap the save command in the presenters, check to see if the View is the ActiveSmartPart, and if so, then I do the save and then close the view. Here is the code that is in the presenters:

EventSubscription(EventTopicNames.Save, ThreadOption.UserInterface)
public void OnSave(object sender, EventArgs eventArgs)
{
if (WorkItem.WorkspacesConstants.WorkspaceNames.TabbedWorkspace.ActiveSmartPart == View)
{
Save();
}
}

private void Save()
{
// Save the new user
adminService.SaveUser(user);

WorkItem.RootWorkItem.WorkspacesConstants.WorkspaceNames.TabbedWorkspace.Close(View);
WorkItem.SmartParts.Remove(View);
CloseView();
if (View is IDisposable)
{
((IDisposable)View).Dispose();
}
}

The problem I am experiencing is after I do the save and then close the view, the next tab becomes immediately becomes the active tab, and its smartpart becomes the ActiveSmartPart, so when it handles that same Save command that got fired, it ends up saving and closing itself as well. This continues for all of the tabs and then end up all getting saved and then closed.

If I comment out the CloseView() code after the save, then only the ActiveSmartPart will do the save, as expected. However, I do need to have the view closed after the save is performed. Any suggestions would be greatly appreciated. Thanks!

Paul
Feb 21, 2007 at 1:15 PM
What I recommend you to do in this is case is to send the ActiveSmartPart as a parameter when you fire the “EventTopicNames.Save” event as follows:

WorkItem.EventTopicsEventTopicNames.Save].Fire(this, new EventArgs<object>(WorkItem.WorkspacesInfrastructure.Interface.Constants.WorkspaceNames.TabbedWorkspace.ActiveSmartPart), this.WorkItem, PublicationScope.WorkItem);

Change the public void OnSave of your presenter to receive the ActiveSmartPart as a parameter and to ask if the View is equal to the mentioned ActiveSmartPart as follows:

EventSubscription(EventTopicNames.Save, ThreadOption.UserInterface)
public void OnSave(object sender, EventArgs<object> eventArgs)
{
if (eventArgs.Data == View)
{
Save();
}
}

I hope this helps you.

Jonathan Menasches.
http://staff.southworks.net/jony