Command Panel: Automatically generating commands

March 09, 2009 Digital Experience

[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.] 

The automatic command generation, is actually a feature of the Control Panel class and it is not to be confused with Command Panel. The process of generating commands automatically has been explained from a practical angle in this article. In this article, however, we are going to examine the mechanics behind this feature - or in other words - how Control Panel class generates commands on a Control Panel.

 


Command Panel and its Commands collection


Command Panel base class contains a following property in its declaration:

public IList<CommandItem> Commands 
The Commands collection can contain any number of CommandItem objects, which become the source for the databinding of the built-in repeater. So the way that Control Panel is able to automatically generate commands based on its Views is very simple: for each View Control Panel creates a new CommandItem and then adds this CommandItem to its built in CommandPanel’s collection of Commands. The actual code that does this looks like following: 
if (this.AutoGenerateViewCommands && this.Views.Count > 0) 
                CommandPanel pnl = new CommandPanel(); 
                pnl.Name = "Views"
                foreach (IViewInfo info in this.Views.Values) 
                { 
                    pnl.AddCommand(info.ViewName 
                    , ControlUtils.SliceRoute(this.Route, this.Name) 
                    , null 
                    , null 
                    , null 
                    , info.Title 
                    , info.Description 
                    , info.ViewCommandCssClass); 
                } 
                list.Add(pnl); 
 

As you can see, if auto generation of View commands is turned on and there are some Views, we create a new instance of CommandPanel class, then for each View we call AddCommand method of the control panel (which is going to add a command to the collection - we could do this manually also) and finally we add the newly created Command Panel to the list of Command Panels (remember that we can have more than one Command Panel).

 


Why is this important?


The reason for this article to be published is to demonstrate that there is no magic behind the automatically generated commands. In the next articles we will be demonstrating various ways of creating Command Panels and managing commands. Knowing that we are, really, only working with a collection to which a repeater gets bound should flatten the learning curve.

The Progress Team