This is the last post of a series that covers the basic ground of CAB QuickStarts from a simple point of view.
Other posts in this series
BankTeller QS
This is a list of the procedures in this post
- Startup
- BankTellerModuleInit
- BankTellerWorkItem Show
- Accept Customer
- Customer List SelectedIndexChanged
- Customer Map
- Customer Summary Controller
- CustomerWorkItem
- BankShellForm
- ShowCommentButton Click
- SaveButton Click
Startup
- The shell defines the root WorkItem as the default WorkItem provided by CAB, and the starting view as BankShellForm.
- The shell executes the Run() method. This method calls the LoadModules() method in the CabApplication class.
- The LoadModules() method obtains the modules (.dll) by using the FileCatalogModuleEnumerator.EnumerateModules() method. What it does is search for Assembly file names in the ProfileCatalog.xml.
- The shell then overrides the AfterShellCreated() method registering ExtensionSites by using the hardcoded strings in the UIExtensionConstants class.
- mainMenuStrip
- mainStatusStrip
- file menu item
- file menu drop-down section
UIExtensionSiteCollection Class
5. Then the LoadFromConfig() method from the UIElementBuilder class is called.
-
- Gets the “shellitems” section from App.config file.
- Exeutes a foreach (statement) MenuItemElement in the section, convert it to a ToolStripMenuItem (uiMenuItem).
- Adds the ToolStripMenuItem to the ExtensionSite collection in the WorkItem.
- If the menuItem has a CommandName, add a Command to the WorkItem registering the click event.
6. The BankTellerModuleInit (ModuleInitializer) is executed.
BankTellerModuleInit
- Uses the [Injection Constructor] which makes it the constructor to be used for Dependency Injection. It gets the WorkItem by using [Service Dependency].
- The Load() method adds the “Customer” ToolStripMenuItem by adding it to the UIExtensionSites Collection in the WorkItem.
- Then retrieves the Content and Sidebar WorkSpaces (with names harcoded in WorkSpacesConstants class).
- Adds a CHILD WorkItem named BankTellerWorkItem and calls its Show() method.
BankTellerWorkItem Show
- Creates a new object UserInfoView and adds it to the WorkItem.Items collection, giving it an ID (“UserInfo”) because it will be used in a place holder. (Remember that: The SmartPartPlaceHolder placeholder control has the SmartPartName property that automatically displays a SmartPart with that name if it is found within the current WorkItem.)
- The Constructor gets the CurrentPrincipal property of the current Thread and displays the name of the user.
- Creates a SideBarView and adds it to the WorkItem.Items collection. Then assigns it to a SideBarView instance named sideBarView.
- Then calls the AddMenuItems() method.
- Creates a new ToolStripMenuItem (“Queue”)==> queueItem
- Adds the queueItem to the WorkItem.ExtensionSites[“File”] collection.
- Then registers a new site [“Queue”] in the queueItem.DropDownItems collection.
- Creates a new ToolStripMenuItem (“AcceptCustomer”) ==> acceptCustomer.
- Sets shortcut keys for acceptCustomer.
- Adds the acceptCustomer ToolStripMenuItem to the [“Queue”] extension site.
- Adds a new CommandInvoker to the Command[“QueueAcceptCustomer”] using acceptCustomer as the Invoker and “Click” as the EventName. Father WorkItem
- Calls sideBar(IWorkSpace).Show method, passing sideBarView as a SmartPart parameter.
- Activates the WorkItem (this.Activate()).
- The BankTellerWorkItem overrides the OnActivated method, setting the bool ShowQueueMenu = true; which uses set{} to make the ToolStripMenuItem queueItem.Visible = true;
- The SideBarView DESIGNER has a design time (redundant) addition of the CustomerQueueView SmartPart.
- The CustomerQueueView uses dependency injection [CreateNew] to initialize the CustomerQueueController.
- Also registers the CommandHandler for the [“QueueAcceptCustomer”] command.
Accept Customer
(Event Handler)
- Registers the (“QueueAcceptCustomer”) [CommandHandler], which is referenced by acceptCustomer ToolStripMenuItem. The Event Handler is also subscribed to by the btnNextCustomer Click Event.
- Calls the GetNextCustomerInQueue() method from the CustomerQueueController.
- The GetNextCustomerInQueue() method calls the CustomerQueueService(which was initiated with [ServiceDependency] attribute) GetNext() method.
- The GetNext() method returns a new Customer.
- The view adds the Customer to the ListItem.Item Collection.
Customer List SelectedIndexChanged
- Retrieves the selected Customer from the list.
- Calls the CustomerQueueController.WorkWithCustomer(customer) method.
- This method calls the BankTellerWorkItem.WorkWithCustomer (customer) method.
- Creates a string keyè “Customer#” & {customer.ID}
- If the CustomerWorkItem for that customer has been created it gets it. Else it adds a new one.
- Assigns the CustomerWorkItem with the KEY to workItem object and adds it to father WorkItems collection.
- Sets the CustomerWorkItem ID, and .State[“Customer2”] = customer.
- If the BankTeller PersistanceService ! null & contains the WorkItem.ID, load() the workItem.
- This method uses the Services<Collection>.Get() method, to get the FileStatePersistance service, in order to be able to get a previously saved customer state.
- Calls the CustomerWorkItem.Show() method.
Customer WorkItem Show
- Assigns to CustomerSummaryView object the previously existing one if !null (?? operator), or adds a new view to the CustomerWorkItem.Items (Collection).
- The calls the WorkSpace(father).Show() method using CustomerSummaryView object as a parameter.
- Calls the AddMenuItems() method.
- Creates a new instance ToolStripMenuItem named editCustomerMenuItem.
- Adds the ToolStripMenuItem to the CustomerWorkItem UIExtenstionSites[“BankTellerModule.CustomerMenu”] Collection.
- In the WorkItem’s Commands[“EditCustomer”] adds an invoker from the editCustomerMenuItem Click Event handler.
- In the WorkItem’s Commands[“CustomerMouseOver”] adds an invoker from the customerSummaryView (CustomerSummaryView instance) MouseHover Event handler.
- Gets the customer from the WorkItem’s state.
- Calls OnStatusTextUpdate() method, passing as parameter the first and last name of the customer in a string.
- Calls the UpdateUserAddressLabel() method.
- Instances a new ToolStripStatusLabel named addressLabel.
- Adds to the UIExtensionSites (collection)[“MainStatus”] the addressLabel.
- Sets the text property of the label to the customer.Address1.
- Activates the WorkItem.
- Calls the SmartPart CustomerSummaryView.FocusFirstTab(), which sets the SelectedTab to [0].
- The CustomerSummaryView has a TabWorkSpace which inside has:
CustomerSummaryView.Designer.Cs
Customer Header View
- The CustomerHeaderView uses the [State] attribute to get the current customer from the Parent WorkItem.
- The load event binds the customer to the CustomerHeaderView.BindingSource.
CustomerDetailView
- The CustomerDetailView uses [ServiceDependency] to get a reference to the parent WorkItem.
- It also uses the [State] attribute to get the current customer from the Parent WorkItem.
- Then uses the [CreateNew] attribute to instantiate the CustomerDetailController.
- The overridden OnLoad() method sets the customer to the CustomerDetailView.BindingSource.
CustomerAccountsView
- The CustomerAccountsView uses the [State] attribute to get the current customer from the Parent WorkItem.
- Uses [ServiceDependency] to get a reference to CustomerAccountService.
- Overrides the OnLoad() method to call the accountService.GetByCustomerID (Customer.ID), which gets a ListDictionary<> of accounts and sets it as the datasource for the DataGrid.
Customer Map
- The Customer Map (third tab) is loaded from the CustomerMapExtensionModule.dll when the application starts because it is in the ProfileCatalog.xml. It contains a [SmartPart] (CustomerMap) and a CustomerWorkItemExtension.
- The CustomerWorkItemExtension overrides the OnActivated() method.
- Adds a CustomerMap smartpart to the WorkItemExtension.Items collection, and assigns the smartpart to mapView (CustomerMap instance).
- Creates a TabSmartPartInfo (A SmartPartInfo that shows how a specific SmartPart will be shown in a tab Workspace) named info.
- Assigns valus to title and description properties:
- Calls the WorkItem.WorkSpaces[“tabbedWorkSpace1”].Show() method, passing as parameters the CustomerMap Smartpart and the SmartPartInfo.
- The CustomerMap SmartPart gets a Customer instance using [State(“Customer 2”)]
Customer Summary Controller
The OnCustomerEdit event handler is declared as a [CommandHandler(“EditCustomer”)]
- Assigns to a tabWorkSpace tabWS the WorkItem.WorkSpaces[“tabbedWorkSpace1”] using as cast (if it is not able to do it return null)
- Sets the tabWorkSpace.SelectedIndex to 0, allowing customer Editing.
CustomerWorkItem
- The OnCustomerEdit event handler is declared as a [CommandHandler(“CustomerMouseOver”)] and executes when the user moves the mouse over the CustomerSummaryView SmartPart.
- If the WorkItem.Status is active, displays a ToolTipText indicating the ID of the customer being edited.
BankShellForm
- Registers the OnStatusUpdate event handler [EventSubscription] using the topic (“topic://BankShell/statusupdate”). This event is published in the CustomerWorkItem.
- Updates the toolStripStatusLabel1.Text with the data from the customer.
ShowCommentButton Click
- Calls the OnShowCustomers event handler.
- Calls the Controller.ShowCustomerComments() method.
- The Controller.ShowCustomerComments() method calls the WorkItem.ShowCustomerComments() method.
- Calls the CreateCommentsView() method.
- Assigns to commentsView (CustomerCommentsView instance) the previously existing one if !null (?? operator), or adds a new view to the CustomerWorkItem.Items collection.
- Declares info as a new tabSmartPartInfo. Assigns info.Title = “Comments”.
- Calls the WorkItem.RegisterSmartPartInfo() method passing as parameters (commentsView, info)
- Assigns to ws (which implements IWorkSpace Interface) WorkItem.WorkSpaces[“tabbedWorkSpace1”].
- ws.Show(commentsView);
SaveButton Click
- Calls the Controller.Save() method
- The Controller.Save() method calls WorkItem.Save() method.
- Declares an IStatePersistanceService service and gets the Services.Get <IStatePersistanceService>
- Saves the changes using the service and calls the state.AcceptChanges() method to reset the HasChanges “flag”.