Topics: CAB & Smart Client Software Factory
Jul 6, 2006 at 5:41 AM
originally posted by: johanandries


the Presenter<TView> contains a method

protected virtual void CloseView()

that is called from the method OnCloseView() in the concreate presenter classes generated by the guidance package, but I don't see who is calling OnCloseView() on the presenter. What is the purpose of these methods?

Thank you.

Jul 6, 2006 at 6:02 PM
originally posted by: DapinderSingh

This method is called on the cancel event of a form.
if you have installed SCSF , open the code file
"\BankTellerWorkbench\Source\Src\BasicAccounts\Module\Views\PurchaseCDView.cs". In this on cancel button evnt, the function OnCloseView() is called which inturn calls CloseView(). The function "CloseView" checks if there is any child workspace present in this view and closes all the child views of this view before closing this view.
Jul 7, 2006 at 8:20 AM
originally posted by: marianoszklanny

Hi johanandries,
The CloseView() method of the Presenter base class actually searches for the Workspace that contains the View and then asks the Workspace to close it. The OnCloseView() method in concrete presenters calls CloseView(), thus it should be called when the View needs to be closed.

The method definition:

protected virtual void CloseView()
IWorkspaceLocatorService locator = WorkItem.Services.Get<IWorkspaceLocatorService>();
IWorkspace wks = locator.FindContainingWorkspace(WorkItem, View);
if (wks != null)

First, it retrieves an instance of the IWorkspaceLocatorService from the current WorkItem. During execution, this instance will be an instance of the WorkspaceLocatorService class defined in Infrastructure.Library.
This service contains only the following method:

IWorkspace FindContainingWorkspace(WorkItem workItem, object smartPart);

which finds the workspace in current WorkItem (or parents) that contains the smartPart.
So, going back to the method definition, CloseView() gets a reference to the Workspace that contains the view (wks), and finally closes the View by calling wks.Close(View).

Mariano Szklanny