Managing CAB/SCSF/MVP/MVC, the break up and rejoining.

So once again I’m back at putting together management methodology for MVP designs.  It seems also pertinent that sometimes, against what would seem logical, it’s also a good idea ot mix MVP and MVC design.  With the possiblities for using controllers for business flow when writing the business flow in presenters breaks apart the logic into too many seperate and sometimes disparate locations.

The idea here is a wizard with multiple screens, each being a SmartPart, that is then fed into a TabWorkspace or other multiple smart part container, should utilize a singe controller for the basic business logic flow, while the presenters can or should hold individual screen business logic.  Also of course linked up to any pertinent business rules validation and other such infrastructure.  Often times one or the other is used (I say often times, MVP and MVC aren’t exactly regularly used design patterns) and mixing seems like it might be “against the rules”.

Contrary to that one should utilize such break downs with prudent and thought out design of the controlers and presenters.  With careful design developers can then develop within their particular business or infrastructure scope without infringing upon each other’s efforts.

CAB & SCSF [SmartParts] Pt. 2

Actually Writing some Code!

  • So now that there is the basic structure of the application setup I started delving into the code.  The first thing I glanced and decided to straighten out was the fact that left and right workspace along with some other Constants where still declared in the Infrastructure.Interface Project under the Constants folder in the WorkspaceNames.cs file.  I removed everything and just left the following:

    public class WorkspaceNames

    {

        public const string LayoutWorkspace = “LayoutWorkspace”;

    }

  • Some other code I went ahead and removed was located in the ModuleController.cs file.  Any code that is related to the tool strip I removed from the Run() Method and deleted the method dedicated to adding items to the tool strip.

    • The first files to dig into are the ModuleController.cs and WorkspaceNames.cs file located in the Constants application directory.  I opened those up for the following code surgery.

      • In addition to those two files I also created another file to store the constants that will be used for the various Views.  I placed this file in the Constants directory and names it simply Views.cs.

        • To the Views.cs file I added the following constant declarations:

    public class Views

    {

        public const string TripDestinations = “TripDestinations”;

        public const string TripManagement = “TripManagement”;

        public const string TripPurpose = “TripPurpose”;

        public const string TripTypes = “TripTypes”;

    }

  • To the WorkspaceNames.cs file I added the single constant:

    /// <summary>

    /// Constants for workspace names.

    /// </summary>

    public class WorkspaceNames : TravelTrackerSmartClient.Infrastructure.Interface.Constants.WorkspaceNames

    {

        public const string TripTabWorkspace = “TripTabWorkSpace”;

    }

  • In the ModuleController.cs file I added the following code.  To read more about setting up Views read the documentation link that is commented out in this AddViews() method.  (Unless the Microsoft Team has removed it in current distributions)

        private void AddViews()

        {

            WorkItem.Items.AddNew(Constants.Views.TripDestinations);

            WorkItem.Items.AddNew(Constants.Views.TripManagement);

            WorkItem.Items.AddNew(Constants.Views.TripPurpose);

            WorkItem.Items.AddNew(Constants.Views.TripTypes);

        }

  • Once all of this is complete I now have an application that actually starts, loads the TravelTracker Project and on Run() adds each of the SmartPart Views into the WorkItem Items collection.  With this in place I can now wire up each of the specific event publications and subscriptions that will allow me to have each SmartPart displayed when a particular menu item is selected (or Tab Part).- To start wiring up the Subscription and Publications make a reference in the ModuleController:

using Microsoft.Practices.CompositeUI.EventBroker;

  • After adding that place some methods for the event subscriptions in the ModuleController.cs file and the respective event topic names to the constants file EventTopicNames.cs.

EventTopicNames.cs

    public class EventTopicNames : TravelTrackerSmartClient.Infrastructure.Interface.Constants.EventTopicNames

    {

        public const string TripDestinationsClicked_Event = “TripDestinationsClicked_Event”;

        public const string TripManagementClicked_Event = “TripManagementClicked_Event”;

        public const string TripPurposeClicked_Event = “TripPurposeClicked_Event”;

        public const string TripTypesClicked_Event = “TripTypesClicked_Event”;

    }

ModuleController.cs

        [EventSubscription(Constants.EventTopicNames.TripDestinationsClicked_Event, ThreadOption.UserInterface)

        public void TripDestinationsClicked_Handler(object sender, EventArgs e)

        {}

 

        [EventSubscription(Constants.EventTopicNames.TripManagementClicked_Event, ThreadOption.UserInterface)

        public void TripManagementClicked_Handler(object sender, EventArgs e)

        {}

 

        [EventSubscription(Constants.EventTopicNames.TripPurposeClicked_Event, ThreadOption.UserInterface)

        public void TripPurposeClicked_Handler(object sender, EventArgs e)

        {}

 

        [EventSubscription(Constants.EventTopicNames.TripTypesClicked_Event, ThreadOption.UserInterface)

        public void TripTypesClicked_Handler(object sender, EventArgs e)

        {}

  • At this point I actually, for readability, went back and changed in the ShellForm.cs code and events for the menu selections.  Along with that I added the event publications attributes and more.  The code when finished looks like this:

        [EventSubscription(Constants.EventTopicNames.TripDestinationsClicked_Event, ThreadOption.UserInterface)]

        public void TripDestinationsClicked_Handler(object sender, EventArgs e)

        {

            if (!WorkItem.SmartParts.Contains(Constants.Views.TripDestinations))

            {

                WorkItem.SmartParts.AddNew(Constants.Views.TripDestinations);

            }

 

            WorkItem.RootWorkItem.Workspaces[Constants.WorkspaceNames.TripTabWorkspace].Show(

                WorkItem.SmartParts.Get(Constants.Views.TripDestinations));

        }

Well, that’s that.  I’m all wired up.  The next step (Part 3, it’s coming soon) is to wire up some button pushin data entering GUI Interacing events, buttons, and other such items.  Stay tuned…

Fired, Employed

While in another conversation another statement was brought up that is absolutely true also.  A good employee in the software industry is the one who rides the line between fired and employed.  The reason being is if a software developer isn’t pushing the envelope to keep things progressively moving forward in a company they likely aren’t putting their full potential into their career.  The whole concept of flying under the radar is not a good place to live, it just puts a person in the direct line of the cutting blade during a downturn.

Where one wants to be in software is always pushing forward, always learning the latest or just learning, always learning more about the business and what the business can do, and never ever letting things become mediocre.  Perfection is the goal and will always keep the software industry working diligently to attain.

Developer Thought of the Day

While in conversation with some co-workers a statement was made that made really good sense.  Many, if unaware of this concept should take heed.  The statement went like this, “developers do what they’re told, if they’re told wrong they will end up doing wrong.”  It is a similar statement to what Demming had made about factory workers in relation to quality being introduced at places like Boeing, Ford, GM, and other places.

So the next time a good developer messes something up, think about the premise.  Most likely he was just doing something he was told to do, it was the teller that told them wrong.

CAB & SCSF [SmartParts] Pt. 1

SmartParts.  The coolest (or maybe just the prettiest) part of the View of Model View Presenters (MVP) and Model View Controllers (MVC).  At least in my not so humble opinion.  A SmartPart is generally used to implement what amounts to a Custom User Control in a Windows Application.  Utilizing various controls a SmartPart usually captures a single domain within a business use case.  An example would be a data entry form for entering sales information in a point of sales system or the report criteria screen in the same system.

Below are some of the SmartPart examples I’ve created for my Travel Tracker Application that I’m working on.  I started with the following standard steps to create an Smart Client Software Factory (SCSF) based Composite UI Application Block (CAB) Application.

Setting up the actual Solution

  • Open Visual Studio and start a new SCSF Project.

  • I named my project Travek Tracker Smart Client and… well you can see that info in the screenshot above.- Next I entered the appropriate information for the SCSF Project.  Uncheck both the “Create a seperate module to define the layout for the shell” and the “Show related documentation after running the recipe“.

  • Before going forward hit F5 (Run, not just build) and make sure everything builds and the application starts.  It is important that you do this as one little change that alters the build might compile fine, but then it will break the actual application.  This is very cumbersome to troubleshoot after the fact.- Once everything loads up I setup a seperate application folder and right click to add a “Business Module” within the structure of the new solution shown below.

  • Once you have all of this finished right click on the Views folder and click on Smart Client > Add View and select a name for the new view as below.

  • Once complete you should have a folder structure like the one below.  Now I’ll start digging into the actual Smart Parts that have been created.

  • There are four screens that are going to make up the SmartPart list.  Each screen has some basic control elements that are used in almost every type of application for data entry and manipulation.- Per the data model (shown below) I have the four different views.

  • Before getting ahead of myself I went ahead back and setup some basic properties for the Shell Application Project.- First setup the Shell so that the Split Pane Control is removed and add a Deck Workspace Control to the application in place of the Split Pane Control.  I then set the application so that the Shell application will launch center of screen and at a resolution of 800×600. I really had to do some messing around to get the Split Panel Control deleted.  The easiest way I found was the undock the control, then shrink it by resizing.  I could then easily right click and select delete.

  • After I removed the Split Panel Control I ran the solution again to see what wouldn’t build.  I assumed, rightfully so, that some parts would have code segments somewhere.  Sure enough the _leftWorkspace and _rightWorkspace on lines 44 & 45 of the ShellForm.cs file don’t exist anymore, but the code is there so I deleted it.  I ran it again after that and the app popped up just fine.- One other good thing to get in the habit of is to set the Localizable property to true.  This will put all of the text and other associated user visible text in a resource file in the project.  It’s as simple as adding new language resource files later.- I also removed the menu bar, ran the application, and removed any pertinent lines of code for that also.  There are two lines that need removed in the ShellForm.cs and ShellApplication.cs files.- After that I added the menu options needed for displaying the various Smart Parts.

  • After adding the menu additions I then added a Tab Workspace Control, removed all of the tabs and named the control accordingly.

  • Again I ran the application to assure the solution would build and start.  A’OK.- After that I tidied up the screen, made sure the Tab Workspace Control has all the properties set I wanted, and prepared to wire up some of this contraption to actually display the four Smart Parts I’ve created.