DeckWorksoace and views from multiple modules.

Topics: CAB & Smart Client Software Factory
Oct 22, 2005 at 8:07 AM
originally posted by: jnicholsonfl1

I have a CAB app that uses a Deck Worlspace on the main form. I load and run a view from a module at app startup. When the use case is complete, I want to switch that view for another from a different module. I've examined the Quickstarts and don't quite see how to do this.
Oct 22, 2005 at 8:15 AM
originally posted by: jolu1977

Since the DeckWorkspace is a well known workspace published by the shell in your ModuleInit you can retrieve the workspace using the workspaces collections on the workitem (use dependency injection to get the workitem). Once you have the workspace create an instance of you workitem that will show the view and call Show on the workitem.

i.e.
//In ModuleInit
//Retrieve well known workspaces
IWorkspace contentWorkspace = workItem.WorkspacesWorkspacesConstants.SHELL_CONTENT;

BankTellerWorkItem bankTellerWorkItem = workItem.WorkItems.AddNew<BankTellerWorkItem>();
bankTellerWorkItem.Show(contentWorkspace);
Oct 22, 2005 at 8:30 AM
originally posted by: jnicholsonfl1

OK, I understand that code snippet. However, If I want to be able to have the modules not know about each other, where would I actually create and run the new WorkItem. I want to be able to signal the Main form when one module's work has finished and then have the main form decide, based on the modules currently loaded, which to activate and show in the Workspace next.
Oct 22, 2005 at 9:07 AM
originally posted by: jnicholsonfl1

OK, after looking at the DeckWorkspace definition, I see that it declares an event for a SmartPartClosing. I suppose I can handle this event for closing my first SmaartPart in the first module and in the handler Show the SmartPart from the second module. Sound reasonable?
Oct 22, 2005 at 9:29 AM
originally posted by: jolu1977

I was going to say look at the WorkItemTypeCatalog if you want to create WorkItems very late.
Oct 22, 2005 at 9:52 AM
originally posted by: jnicholsonfl1

Well, it looks like this idea won't work the way I suspected it would either. I don't have a way to actually "Close" a SmartPart based on a UserControl. is the first problem. Secondly, how would I call the SmartPartClosing from the SmartPArt?
Oct 22, 2005 at 10:03 AM
originally posted by: jolu1977

Call SmartPartClosing? That is an event that is fired by the workspace. If you need to Close the smartpart in the workspace call Close pasing the SmartPart.

I think I may be missing something. When a UseCase is done (meaning the workitem not longer needed and could be terminated) you can create a new workitem using the workitemtypecatalog and show it in the DeckedWorkspace.
Oct 22, 2005 at 10:06 AM
originally posted by: jnicholsonfl1

If I have the following:

class MyWorkItem : WorkItem
{
public void Run(IWorkspace mainWorkSpace)
{
IMyView view = this.Items.AddNew<MyView>();
MyPresenter presenter = new MyPresenter(view);
this.Items.Add(presenter);
mainWorkSpace.Show(view);
}
}

How do I get back to the WorkItem from MyView??? If I can do this, say by clicking a Cancel button on my SmartPart (MyView), I should then be able to Close the SmartPart via mainWorkSpace.Close(view) which in turn I can handle in the SmartPartClosing handler in the main form and then Run a different WorlkItem.
Oct 22, 2005 at 10:07 AM
originally posted by: jnicholsonfl1

Yes, but the question here is how to actually signal that the UseCase is complete?
Oct 22, 2005 at 10:12 AM
originally posted by: jolu1977

Use your presenter. The presenter should derive from Controller (yes I know it is not a controller) but I have done MVP with CAB this way. Then you have a reference to the workitem. You should know the endpoints of the usecase and code them accordingly.
Oct 25, 2005 at 7:31 PM
originally posted by: PProvost

I'm not sure that I understand your situation. But let me see if I can help.

If you want your view to talk to your work item, your view can take a ServiceDependency on WorkItem and get a reference to it. You can use either property-setter or constructor based dependency injection for this (although we prefer constructor injection.)

If you need to have the view communicate back to your WorkItem in a generic way, without knowing the WorkItem type, you can have it publish a WorkItem scoped event-broker event using the EventPublication attribute.

If you want to have your view, controller or presenter let the main root work item know that your use case is complete, you could use a global event broker event.

Does this help?